首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >UILocalNotification在iOS11中不起作用

UILocalNotification在iOS11中不起作用
EN

Stack Overflow用户
提问于 2018-01-12 18:32:36
回答 1查看 709关注 0票数 0

我有一个在AppStore上发布的,在iOS11之前运行良好的应用程序。如果用户在使用iOS11之前使用我的应用程序,并升级到iOS11,我的应用程序仍然可以正常工作。但是,如果它们最初在iOS11上,然后重新安装我的应用程序,UILocalNotifiation将无法工作。每日警报不会触发。我在我的实现中使用了UILocalNotification,我知道它在iOS10中已经被弃用了。我检查了通知中心,在首选项窗格中看不到我的应用程序。有没有解决这个问题的线索,或者我需要使用其他框架重写所有相关代码?

代码语言:javascript
复制
-(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中也有以下代码:

代码语言:javascript
复制
    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;

并且已经实现了这些方法:

代码语言:javascript
复制
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification 
EN

回答 1

Stack Overflow用户

发布于 2018-01-12 18:41:38

至于Apple developer documentationUILocalNotification在iOS 10中已被弃用。您可能希望将UserNotications.frameworkimport UserNotifications一起使用。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48224366

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档