在ios 9中没有调用didRegisterForRemoteNotificationsWithDeviceToken [英] didRegisterForRemoteNotificationsWithDeviceToken is not called up in ios 9

查看:136
本文介绍了在ios 9中没有调用didRegisterForRemoteNotificationsWithDeviceToken的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须在我的项目中实施 APNS ,我在开发人员门户网站中创建了 APNS SSL ,并使用此我创建了新配置这个档案。
使用SSL证书我创建 P12 文件,然后将其合并到 PEM 文件。
我得到了应用程序想要发送通知的弹出窗口.....
i接受但仍然没有得到设备令牌!!

I have to implement APNS in my project, I have created APNS SSL in developer portal, and using this i have created new provision profile for this. Using SSL certificate I created P12 file then merging it to PEM file. I get popup that App would like to send you notification..... i accept that but still i didn't get the device token !!

didfinishLaunching 我使用此部分

float ver = [[[UIDevice currentDevice] systemVersion] floatValue];

   if(ver >= 8 && ver<9)
    {
        if ([[UIApplication sharedApplication] respondsToSelector:@selector(registerUserNotificationSettings:)])
        {
           [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];

            [[UIApplication sharedApplication] registerForRemoteNotifications];

            //[[UIApplication sharedApplication] registerUserNotificationSettings:settings];

        }
    }else if (ver >=9){

        [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];

        [[UIApplication sharedApplication] registerForRemoteNotifications];

    }
    else{
        //iOS6 and iOS7 specific code
        [[UIApplication sharedApplication] registerForRemoteNotificationTypes:UIRemoteNotificationTypeBadge|UIRemoteNotificationTypeAlert];
    }


I have used delegate method of push notification 


- (void)application:(UIApplication*)application didFailToRegisterForRemoteNotificationsWithError:(NSError*)error
{
    NSLog(@"Failed to get token, error: %@", error);
}


- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {

    for (id key in userInfo) {
        NSLog(@"key: %@, value: %@", key, [userInfo objectForKey:key]);
    }    

}


推荐答案

试试这个。

if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0){

    UIUserNotificationType types = UIUserNotificationTypeBadge |
    UIUserNotificationTypeSound | UIUserNotificationTypeAlert;

    UIUserNotificationSettings *mySettings =
    [UIUserNotificationSettings settingsForTypes:types categories:nil];

    [application registerUserNotificationSettings:mySettings];
    [application registerForRemoteNotifications];


}else{
    [application registerForRemoteNotificationTypes:
     (UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert)];
}

这篇关于在ios 9中没有调用didRegisterForRemoteNotificationsWithDeviceToken的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆