首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >iOS registerForRemoteNotifications不会生成错误,但不会激发提供设备令牌的委托。

iOS registerForRemoteNotifications不会生成错误,但不会激发提供设备令牌的委托。
EN

Stack Overflow用户
提问于 2016-07-19 14:56:03
回答 1查看 951关注 0票数 3

直到今天早上,所有的设备都工作得很好,我需要设备令牌,当我在didRegisterForRemoteNotificationsWithDeviceToken设备上调试时,设备令牌就会继续前进,didFailToRegisterForRemoteNotificationsWithError方法也不会被触发。我真的很感谢你的帮助。我的代码如下。

代码语言:javascript
运行
复制
        - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
    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)];
    }
    return YES;
    }

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
    NSLog(@"didRegisterForRemoteNotificationsWithDeviceToken: %@", deviceToken);
    [[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
    NSString *deviceID = [[deviceToken description] stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"<>"]];
    deviceID = [deviceID stringByReplacingOccurrencesOfString:@" " withString:@""];

    NSLog(@"Device_Token     -----> %@\n",deviceID);
    [[NSUserDefaults standardUserDefaults] setObject:deviceID forKey:@"KiviDeviceToken"];
    [[NSUserDefaults standardUserDefaults] synchronize];
}

-(void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
{
    NSLog(@"Error: %@", error.description);

    if (error.code == 3010) {
        NSLog(@"Push notifications are not supported in the iOS Simulator.");
    } else {
        NSLog(@"application:didFailToRegisterForRemoteNotificationsWithError: %@", error);
    }
}

- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
{
    NSLog(@"NotificationSettings: %@", notificationSettings);
    //register to receive notifications
    [application registerForRemoteNotifications];
}

我已经检查了iOS设置应用程序通知是否启用,该方法不会被调用。

如果既没有调用委托回调application:didRegisterForRemoteNotificationsWithDeviceToken:,也没有调用application:didFailToRegisterForRemoteNotificationsWithError:,那么我需要为“故障排除推送通知”提供一些帮助,因为还没有建立连接,所以NotificationSettings没有被调用。

EN

回答 1

Stack Overflow用户

发布于 2016-07-19 15:00:01

苹果上一直有问题,以APNS结尾。出于某种原因,生产中的应用程序可以正常工作,但是人们正在开发的应用程序不会推动任何通知。

Click here for more info

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38462025

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档