在APNS中,除了iPhone 4之外,无法在任何设备中获取设备令牌

时间:2016-07-19 10:24:33

标签: ios objective-c iphone apple-push-notifications

在APNS中,除iPhone 4didRegisterForRemoteNotificationsWithDeviceToken未执行外,它无法在任何设备中获取设备令牌 - 推送通知。

2 个答案:

答案 0 :(得分:1)

试试这个......

if (SYSTEM_VERSION_LESS_THAN(@"8.0")) {
    [application registerForRemoteNotificationTypes:  (UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)];
} else {
    UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:(UIRemoteNotificationTypeBadge|UIRemoteNotificationTypeSound|UIRemoteNotificationTypeAlert) categories:nil];
    [[UIApplication sharedApplication] registerUserNotificationSettings:settings];
}

答案 1 :(得分:0)

在App委托中尝试使用DidFinishLaunchingWithOption: iphone 4仅在iOS7上运行。

 if ([application respondsToSelector:@selector(registerUserNotificationSettings:)])
    {
        UIUserNotificationType userNotificationTypes = (UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound);
        UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:userNotificationTypes categories:nil];
        [application registerUserNotificationSettings:settings];  
    }
    else
    {
        // Register for Push Notifications, if running iOS version < 8
        [application registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound)];

    }