在ios 9.3.1中没有调用didRegisterForRemoteNotificationsWithDeviceToken

时间:2016-07-19 11:54:50

标签: ios objective-c remote-notifications ios9.3.1

我正在我的一个应用程序中实现远程通知,并且我正在使用该方法获取设备令牌。

  - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
    NSLog(@"Did Register for Remote Notifications with Device Token (%@)", deviceToken);
    NSString * token = [NSString stringWithFormat:@"%@", deviceToken];
    //Format token as you need:
    token = [token stringByReplacingOccurrencesOfString:@" " withString:@""];
    token = [token stringByReplacingOccurrencesOfString:@">" withString:@""];
    token = [token stringByReplacingOccurrencesOfString:@"<" withString:@""];

   // [OTWebServiceHelper sharedInstance].deviceTocken    = token;
    NSLog(@"App Token for Device%@",token);
    [[NSUserDefaults standardUserDefaults] setObject:token forKey:@"MyAppDeviceToken"];
    [[NSUserDefaults standardUserDefaults] synchronize];

}

当我检查8.0设备时它工作正常,但在ios 9.3.1中它没有被调用。

我提到了这个链接但没有用。

didRegisterForRemoteNotificationsWithDeviceToken is not called up in ios 9

请帮帮我。

注册我正在使用代码:

  -(void)registerForPUSHNotifications {

    NSString *iOSversion = [[UIDevice currentDevice] systemVersion];
    NSString *prefix = [[iOSversion componentsSeparatedByString:@"."] firstObject];
    float versionVal = [prefix floatValue];


    if (versionVal >= 8)
    {
        //for iOS8
        UIUserNotificationSettings *settings =
        [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert |
         UIUserNotificationTypeBadge |
         UIUserNotificationTypeSound categories:nil];
        [[UIApplication sharedApplication] registerUserNotificationSettings:settings];
        [[UIApplication sharedApplication] registerForRemoteNotifications];
    }
    else
    {

        [[UIApplication sharedApplication] registerForRemoteNotificationTypes: (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];

    }
}

0 个答案:

没有答案