swift 中的对讲推送通知
Intercom push notifications in swift
我正在尝试为对讲机推送通知注册一个应用程序。他们在这里有说明:https://docs.intercom.io/Install-on-your-mobile-product/enabling-push-notifications-with-intercom-for-ios
他们在 obj c 中提供了此代码,但我的应用程序在 swift 中,这对我来说像是胡言乱语:
- (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)];
}
}
有人可以在 swift 中解释如何执行此过程吗?
以下代码通过使用添加到 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))
}
我正在尝试为对讲机推送通知注册一个应用程序。他们在这里有说明:https://docs.intercom.io/Install-on-your-mobile-product/enabling-push-notifications-with-intercom-for-ios
他们在 obj c 中提供了此代码,但我的应用程序在 swift 中,这对我来说像是胡言乱语:
- (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)];
}
}
有人可以在 swift 中解释如何执行此过程吗?
以下代码通过使用添加到 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))
}