Swift 中的本地通知在 iOS 7 崩溃
Local Notifications in Swift Crashing on iOS 7
我正在尝试将本地通知添加到我的游戏中。该代码适用于 iOS 8,但是当我尝试在 iOS 7 上对其进行测试时,它就崩溃了。
这是注册通知的代码(在 App Delegate 中)
let notificationType = UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound
let settings = UIUserNotificationSettings(forTypes: notificationType, categories: nil)
application.registerUserNotificationSettings(settings)
这是我设置通知的代码
UIApplication.sharedApplication().cancelAllLocalNotifications()
notification.fireDate = NSDate(timeIntervalSinceNow: 3600)
notification.alertBody = "Come back and play"
notification.alertAction = "to play"
notification.applicationIconBadgeNumber = 1
UIApplication.sharedApplication().scheduleLocalNotification(notification)
注册通知时崩溃。
In iOS 7 registerUserNotificationSettings 是无法识别的选择器,会崩溃。您需要查看它是否响应该选择器,以及它是否不调用 registerForRemoteNotificationTypes: 相反。
我正在尝试将本地通知添加到我的游戏中。该代码适用于 iOS 8,但是当我尝试在 iOS 7 上对其进行测试时,它就崩溃了。
这是注册通知的代码(在 App Delegate 中)
let notificationType = UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound
let settings = UIUserNotificationSettings(forTypes: notificationType, categories: nil)
application.registerUserNotificationSettings(settings)
这是我设置通知的代码
UIApplication.sharedApplication().cancelAllLocalNotifications()
notification.fireDate = NSDate(timeIntervalSinceNow: 3600)
notification.alertBody = "Come back and play"
notification.alertAction = "to play"
notification.applicationIconBadgeNumber = 1
UIApplication.sharedApplication().scheduleLocalNotification(notification)
注册通知时崩溃。
In iOS 7 registerUserNotificationSettings 是无法识别的选择器,会崩溃。您需要查看它是否响应该选择器,以及它是否不调用 registerForRemoteNotificationTypes: 相反。