didRegisterForRemoteNotificationsWithDeviceToken没有在ios8中调用,但是didRegister ...设置是 [英] didRegisterForRemoteNotificationsWithDeviceToken not called in ios8, but didRegister...Settings is

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

问题描述

我按照这个帖子,但方法 didRegisterForRemoteNotificationsWithDeviceToken 仍然没有被调用:

I followed this thread, but the method didRegisterForRemoteNotificationsWithDeviceToken is still not called :

文档说:


在调用
UIApplication对象的registerForRemoteNotifications方法后,应用程序在设备
注册成功完成时调用此方法

After you call the registerForRemoteNotifications method of the UIApplication object, the app calls this method when device registration completes successfully

didRegisterUser 显示良好,但没有注册notif

以下是AppDelegate中的代码(应用版本为8.1):

Here is my code in the AppDelegate (the app version is 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中的远程通知。

I also have background mode -> remote notification in the info.plist.

推荐答案

您的代码似乎是正确的。作为一个小改进,您可以像这样编写didRegisterUserNotificationSettings方法:

Your code seems to be correct. As a minor improvement you could write your didRegisterUserNotificationSettings method like so:

- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings {
    if (notificationSettings.types != UIUserNotificationTypeNone) {
        NSLog(@"didRegisterUser");
        [application registerForRemoteNotifications];
    }
}

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

There may be a configuration problem that causes a failed APN registration.


  1. 确保您的供应资料包含aps-environment条目

  1. Assure that your Provisioning Profile contains the aps-environment entry

确保您的配置文件中设置了唯一的应用标识符(不带任何*的字符串)。您还应该在Info.plist中将此确切标识符用作Bundle identifier

Assure that you have a unique App Identifier (a string without any "*") set in your Provisioning Profile. You should also use this exact identifier as "Bundle identifier" in your Info.plist

也许您在初始安装后拒绝了推送功能 - 在此如果您再也没有看到应用程序内推送警报,则必须再次启用设置应用程序中的推送。

Maybe you have declined the Push-Feature after the initial installation - in this case you will never see the in-app-push-alert again and have to enable Push in the settings app again.

尝试其他设备。

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

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