我有一个在AppStore上发布的,在iOS11之前运行良好的应用程序。如果用户在使用iOS11之前使用我的应用程序,并升级到iOS11,我的应用程序仍然可以正常工作。但是,如果它们最初在iOS11上,然后重新安装我的应用程序,UILocalNotifiation将无法工作。每日警报不会触发。我在我的实现中使用了UILocalNotification,我知道它在iOS10中已经被弃用了。我检查了通知中心,在首选项窗格中看不到我的应用程序。有没有解决这个问题的线索,或者我需要使用其他框架重写所有相关代码?
-(void)scheduleNotification {
LOGDEBUG(NSLog(@"schedule notification"));
if (alertDate==nil) {
alertDate=self.as.alertTime;
LOGDEBUG(NSLog(@"alert Date insider notification: %@", alertDate));
}
UILocalNotification *notification = [[UILocalNotification alloc] init];
notification.fireDate = alertDate;
notification.timeZone = [NSTimeZone defaultTimeZone];
notification.alertBody = "AlertBody here...";
notification.alertAction = "AlertAction...";
notification.soundName = UILocalNotificationDefaultSoundName;
notification.applicationIconBadgeNumber += 1;
notification.repeatInterval = NSDayCalendarUnit;
LOGDEBUG(NSLog(@"To be alert at: %@", alertDate));
[[UIApplication sharedApplication] scheduleLocalNotification:notification];
}我的AppDelegate中也有以下代码:
UILocalNotification *notification = [launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];
LOGDEBUG(NSLog(@"%@", notification));
if (notification) {
UIAlertView *view = [[UIAlertView alloc] initWithTitle:APP_NAME message:notification.alertBody delegate:self cancelButtonTitle:notification.alertAction otherButtonTitles: nil];
[view show];
}
application.applicationIconBadgeNumber = 0;并且已经实现了这些方法:
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification 发布于 2018-01-12 18:41:38
至于Apple developer documentation,UILocalNotification在iOS 10中已被弃用。您可能希望将UserNotications.framework与import UserNotifications一起使用。
https://stackoverflow.com/questions/48224366
复制相似问题