iOS   发布时间:2022-03-31  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了didRegisterForRemoteNotificationsWithDeviceToken未在ios8中调用,但是已经注册了…大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我跟着 this thread,但方法didRegisterForRemoteNotificationsWithDeviCEToken仍然没有被调用

文件说:

didRegisterUser看起来很好,但没有注册通知.

这是AppDelegate中的代码(应用程序版本是8.1):

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    //register notif
    UIUserNotificationType userNotificationTypes = (UIUserNotificationTypeAlert |
                                                    UIUserNotificationTypeBadge |
                                                    UIUserNotificationTypeSound);
    UIUserNotificationSetTings *setTings = [UIUserNotificationSetTings setTingsForTypes:userNotificationTypes categories:nil];
    [application registerUserNotificationSetTings:setTings];


    return YES;
}

- (void)application:(UIApplication *)application didRegisterUserNotificationSetTings:(UIUserNotificationSetTings *)notificationSetTings
{
    //register to receive notifications
    [application registerForRemoteNotifications];
    NSLog(@"didRegisterUser");
}

-(void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
    NSLog(@"error here : %@",error);//not called
}

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviCEToken:(NSData *)deviCEToken {
    /*
    // Store the deviCEToken in the current installation and save it to Parse.
    PFInstallation *currenTinstallation = [PFInstallation currenTinstallation];
    [currenTinstallation setDeviCETokenFromData:deviCEToken];
    currenTinstallation.chAnnels = @[ @"global" ];
    [currenTinstallation saveInBACkground];
     */
    NSLog(@"did register notif");//not called
}

我也有背景模式 – > info.plist中的远程通知.

解决方法

你的代码似乎是正确的.作为一个小的改进,您可以编写您的didRegisterUserNotificationSetTings方法,如下所示:
- (void)application:(UIApplication *)application didRegisterUserNotificationSetTings:(UIUserNotificationSetTings *)notificationSetTings {
    if (notificationSetTings.types != UIUserNotificationTypeNonE) {
        NSLog(@"didRegisterUser");
        [application registerForRemoteNotifications];
    }
}

可能存在导致APN注册失败的配置问题.

>确保您的配置配置文件包含aps环境条目>确保您的配置配置文件中设置了唯一的应用标识符(不包含任何“*”的字符串).您还应该在Info.plist中将此确切标识符用作“捆绑标识符”>也许您在初次安装后拒绝了推送功能在这种情况下,您将永远不会再看到应用内推送警报,并且必须再次启用“设置”应用.>尝试另一个设备.

大佬总结

以上是大佬教程为你收集整理的didRegisterForRemoteNotificationsWithDeviceToken未在ios8中调用,但是已经注册了…全部内容,希望文章能够帮你解决didRegisterForRemoteNotificationsWithDeviceToken未在ios8中调用,但是已经注册了…所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。