本地通知无法工作,因为更新到IOS 8和Xcode 6

自从更新到IOS 8和Xcode 6之后,有没有其他人遇到本地通知问题? 我有我的应用程序运行良好, notification.firdate设置从dateselect器和工作正常, notification.alertBody显示正常。 现在我已经更新它不起作用。 我已经添加了中断点,并且已经存储了一个值。 谁能帮帮我吗?

您需要更新您的代码才能在iOS8中接收通知。 更多信息在这里 。

Objective-C代码:

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { if ([UIApplication instancesRespondToSelector:@selector(registerUserNotificationSettings:)]){ [application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSound categories:nil]]; } // Override point for customization after application launch. return YES; } 

SWIFT代码:

 func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: NSDictionary?) -> Bool { //registering for sending user various kinds of notifications application.registerUserNotificationSettings(UIUserNotificationSettings(forTypes: UIUserNotificationType.Sound|UIUserNotificationType.Alert |UIUserNotificationType.Badge, categories: nil) // Override point for customization after application launch. return true } 

为了接收本地NSNotification,请按照以下步骤操作:

  1. 将代码添加到didFinishLaunchingWithOptions方法中的appDelegate.h

     if ([UIApplication instancesRespondToSelector:@selector(registerUserNotificationSettings:)]){ [application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSound categories:nil]]; }