0
當我在AppDelegate中設置通知時,只需要向用戶提供iOS8下的權限,即使我重置了模擬器設置(我知道遠程通知在模擬器中不起作用,但我沒有有一個設備與ios7來測試它,但我很驚訝,它不要求允許遠程通知)。ios7 registerForRemoteNotificationTypes不會提示要求用戶的權限
if iOS8 {
println("ios 8")
let userNotificationTypes: UIUserNotificationType = (UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound)
let settings = UIUserNotificationSettings(forTypes: userNotificationTypes, categories: nil)
application.registerUserNotificationSettings(settings)
application.registerForRemoteNotifications()
} else {
println("ios 7")
let userNotificationTypes: UIRemoteNotificationType = (UIRemoteNotificationType.Alert | UIRemoteNotificationType.Badge | UIRemoteNotificationType.Sound)
application.registerForRemoteNotificationTypes(userNotificationTypes)
}
這也是我如何檢查ios7或8種工作方式:
private let iosVersion = NSString(string: Device.systemVersion).doubleValue
let iOS8 = iosVersion >= 8
let iOS7 = iosVersion >= 7 && iosVersion < 8
我也看了這個http://corinnekrych.blogspot.com.es/2014/07/how-to-support-push-notification-for.html