2014-10-27 96 views
0

我有一個快速的應用程序,我正在橋接Objective C Parse框架。解析iOS中的應用程序崩潰<8 in swift

它不會在模擬器中崩潰,但推送通知在模擬器中不起作用。

下面是代碼:

Parse.setApplicationId("id", clientKey: "id") 
    let notificationTypes:UIUserNotificationType = UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound 
    let notificationSettings:UIUserNotificationSettings = UIUserNotificationSettings(forTypes: notificationTypes, categories: nil) 
    UIApplication.sharedApplication().registerUserNotificationSettings(notificationSettings) 
    UIApplication.sharedApplication().registerForRemoteNotifications() 
    return true 

它崩潰以下行沒有錯誤消息:

UIApplication.sharedApplication().registerUserNotificationSettings(notificationSettings) 

我怎樣才能解決這個問題?

UPDATE

我只是測試它在我的iPad(iOS 8的),現在實在是太崩潰呢?

+0

您嘗試更新您的Xcode?到6.1蘋果在Swift上做了一些API更新... – eddwinpaz 2014-10-27 19:21:05

回答

0

如果它在iOS <中崩潰8它的原因是-registerUserNotificationsSettings()僅適用於iOS8。

嘗試類似的東西:

let notificationTypes:UIUserNotificationType = UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound 
let notificationSettings:UIUserNotificationSettings = UIUserNotificationSettings(forTypes: notificationTypes, categories: nil) 


if(UIApplication.sharedApplication().respondsToSelector(@selector(registerUserNotificationSettings:))){ 
    UIApplication.sharedApplication().registerUserNotificationSettings(notificationSettings) 
    UIApplication.sharedApplication().registerForRemoteNotifications() 
}else{ 
    UIApplication.sharedApplication().registerForRemoteNotificationsTypes(notificationTypes) 
} 
+0

它說無法解析的標識符'registerUserNotificationSettings' – Haring10 2014-10-28 05:36:25

+0

當我取出'@selector(registerUserNotificationSettings:)'並放入'registerUserNotificationSettings'時,它說''UIApplication沒有名爲'registerUserNotificationSettings''的成員 – Haring10 2014-10-28 05:40:22