我有一个应用程序,在iOS11之前运行良好,并在AppStore上发布。如果用户在 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];
}
我的应用程序代表中也有这些代码:
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
至于Apple开发人员文档,UILocalNotification
在iOS 10中已弃用。您可能希望将UserNotications.framework
与 import UserNotifications
一起使用。