【发布时间】:2017-05-09 05:59:07
【问题描述】:
我没有在 iPhone 5 (10.2.1) 和 SE(10.3.1) 以及其他 5 款相关设备中获得设备令牌,但在所有 iPhone 6(包括 plus、SE)和 7 以及 7+ 中也成功获得了令牌.
这是我的注册码
func registerForPushNotification(let application: UIApplication) {
let notificationTypes: UIUserNotificationType = [UIUserNotificationType.Alert, UIUserNotificationType.Badge, UIUserNotificationType.Sound]
let pushNotificationSettings = UIUserNotificationSettings(forTypes: notificationTypes, categories: nil)
application.registerUserNotificationSettings(pushNotificationSettings)
application.applicationIconBadgeNumber = 0
if pushNotificationSettings.types != .None {
application.registerForRemoteNotifications()
}
}
这是我收集令牌的代码
func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {
let characterSet: NSCharacterSet = NSCharacterSet( charactersInString: "<>" )
let deviceTokenString: String = ( deviceToken.description as NSString )
.stringByTrimmingCharactersInSet( characterSet )
.stringByReplacingOccurrencesOfString( " ", withString: "" ) as String
print( deviceTokenString )
}
有什么帮助吗?
【问题讨论】:
-
从设备中删除应用并重新安装。
-
查看stackoverflow.com/a/37967012/3901620中的requestAuthorization
-
他们的操作系统版本不同吗?
-
@BalajiGalave 在 6 中,我的操作系统是 10.1.1,它运行成功,但在 5 中,操作系统是 10.2.1,它返回空
-
你实现
didRegisterUserNotificationSettings了吗?
标签: ios iphone swift push-notification swift2