简体   繁体   English

iOS 7的Swift Crashing中的本地通知

[英]Local Notifications in Swift Crashing on iOS 7

I am trying to add local notifications to my game. 我正在尝试将本地通知添加到我的游戏中。 The code works with iOS 8 but when I try to test it on iOS 7 it just crashes. 该代码适用于iOS 8,但是当我尝试在iOS 7上对其进行测试时,它只会崩溃。

This is the code to register the notifications(its in the App Delegate) 这是注册通知的代码(位于应用程序委托中)

let notificationType = UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound
let settings = UIUserNotificationSettings(forTypes: notificationType, categories: nil)
application.registerUserNotificationSettings(settings)

And this is my code to set the notification 这是我设置通知的代码

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)

It crashes when its registering the notifications. 注册通知时崩溃。

In iOS 7 registerUserNotificationSettings is an unrecognized selector and will crash. 在iOS 7中,registerUserNotificationSettings是无法识别的选择器,将崩溃。 You need to see if it responds to that selector and if it doesn't call registerForRemoteNotificationTypes: instead. 您需要查看它是否响应该选择器,以及是否不调用registerForRemoteNotificationTypes:。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM