2015-03-13 23 views
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

回答

0

推送通知是不支持iOS模擬器。這似乎是從iOS 8開始才顯示此警報(這並不意味着通知可以與模擬器一起使用)。 See this SO question

所以你必須找到一個運行iOS 7的設備,但你的代碼看起來不錯。

相關問題