0

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

  - (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 中它没有被调用。

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

在 ios 9 中未调用 didRegisterForRemoteNotificationsWithDeviceToken

请帮我。

对于注册,我正在使用代码:

  -(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)];

    }
}
4

0 回答 0