2015-10-28 54 views
0

我正在嘗試註冊對講推送通知的應用程序。他們說明這裏:https://docs.intercom.io/Install-on-your-mobile-product/enabling-push-notifications-with-intercom-for-ios迅速對講推送通知

他們給在OBJ C此代碼,但我的應用程序是迅速,這看起來像亂碼對我說:

- (void)applicationDidBecomeActive:(UIApplication *)application {  
    if ([application respondsToSelector:@selector(registerUserNotificationSettings:)]){ // iOS 8 (User notifications) 
     [application registerUserNotificationSettings: 
     [UIUserNotificationSettings settingsForTypes: 
      (UIUserNotificationTypeBadge | 
      UIUserNotificationTypeSound | 
      UIUserNotificationTypeAlert) 
              categories:nil]]; 
     [application registerForRemoteNotifications]; 
    } else { // iOS 7 (Remote notifications) 
     [application registerForRemoteNotificationTypes: 
     (UIRemoteNotificationType) 
     (UIRemoteNotificationTypeBadge | 
      UIRemoteNotificationTypeSound | 
      UIRemoteNotificationTypeAlert)]; 
    } 
} 

有人能解釋如何在迅速做了這一過程?

+0

只要搜索谷歌「迅速registerForRemoteNotifications」的例子還有很多新的可用性功能適用於Xcode的7.1。 – Darko

回答

1

下面的代碼通過使用添加到斯威夫特2

if #available(iOS 8, *) { 
    application.registerUserNotificationSettings(
      UIUserNotificationSettings(forTypes: UIUserNotificationType(rawValue: UIUserNotificationType.Badge.rawValue | 
       UIUserNotificationType.Sound.rawValue | 
       UIUserNotificationType.Alert.rawValue), 
      categories: nil)) 
} else { 
    application.registerForRemoteNotificationTypes(
     UIRemoteNotificationType(rawValue: UIRemoteNotificationType.Badge.rawValue | 
     UIRemoteNotificationType.Alert.rawValue | 
     UIRemoteNotificationType.Sound.rawValue)) 
} 
+0

這沒有編譯。有錯誤 – Deekor

+0

更新了代碼,如果您想使用特定於平臺的代碼,則需要在Xcode 7中使用可用性功能 – manman