2013-03-14 42 views
0

我有一个应用程序,我正在与允许用户设置和删除UILocalNotifications。在开发过程中,我添加并删除了用于测试的UILocalNotifications,它似乎正在工作。孤儿UILocalNotification - 已确认

但是我看到奇怪的行为,从设备删除我的应用程序并再次运行它没有设置任何通知后,我会得到一个UILocalNotification。此新通知未在此新安装中设置(通过在通知设置方法中添加断点进行检查)。

是否有可能从先前的安装中得到孤立的UILocalNotification(是的,它似乎不太可能)。

我试着通过通知alertBody设置具体到每一个新的安装,但这个唯一的字符串不会被显示在警告一些在调试这一点。例如:

notif.alertBody = [NSString stringWithFormat:@"Alert for: %@", alertName]; 

有没有人见过这种行为?

更新:刚刚确认孤立UILocalNotifications:从设备中删除应用程序,并在我的rootViewController上运行下面的代码viewDidAppear。我得到的控制台输出如下:

2013-03-14 14:20:07.439 TestApp[16606:907] found alert: uigffhy 
2013-03-14 14:20:07.444 TestApp[16606:907] found alert: uigffhy 

此用户是从一些以前的安装。啊。

NSArray *notificationArray = [[UIApplication sharedApplication] scheduledLocalNotifications]; 

for (UILocalNotification *notif in notificationArray) { 
    NSDictionary * info = notif.userInfo; 
    NSString * name = [info objectForKey:@"sequenceName"]; 
    NSLog(@"found alert: %@", name); 

} 

回答

1

只是检测,如果它是一个新的安装(使用NSUserDefaults),并做applicationDidFinishLaunching:

[[UIApplication sharedApplication] cancelAllLocalNotifications]; 
+0

感谢您的答复如下。让我想知道:这不是一个错误,因为所有的应用程序数据应该删除时,应用程序被删除。 – 2013-03-14 19:38:21

+0

从这个帖子:HTTP://stackoverflow.com/questions/4923028/uilocalnotification-fires-after-reinstalling-the-app 据苹果公司称,这是不是一个错误(我提交了错误报告)。该系统保留了24小时卸载的应用的UILocalNotifications以防万一用户意外删除的应用程序,并恢复所述UILocalNotifications如果应用程序是规定时间内重新安装。 – 2013-03-14 19:53:41

+0

酷 - 感谢您的跟踪! – 2013-03-14 20:48:31