简体   繁体   English

快速对讲推送通知

[英]Intercom push notifications in swift

I am trying to register an app for intercoms push notifications. 我正在尝试为对讲机推送通知注册一个应用程序。 They have instructions here: https://docs.intercom.io/Install-on-your-mobile-product/enabling-push-notifications-with-intercom-for-ios 他们在这里有说明: https : //docs.intercom.io/Install-on-your-mobile-product/enabling-push-notifications-with-intercom-for-ios

They give this code in obj c, but my app is in swift and this looks like gibberish to me: 他们在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)];
    }
}

Could someone explain how to do this process in swift? 有人可以解释一下如何快速完成此过程吗?

Following code works on Xcode 7.1 by using the new availability feature added to Swift 2 以下代码通过使用Swift 2中新增的可用性功能在Xcode 7.1上运行

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))
}

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

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