【问题标题】:Device token not generating iOS设备令牌未生成 iOS
【发布时间】:2016-04-27 12:24:43
【问题描述】:

我在使用真实设备生成设备令牌时遇到问题。 我正在调试设备,但未生成设备令牌。 有时有效,有时无效。

请让我知道可能是什么问题。 谢谢

【问题讨论】:

  • 有时有效,有时无效:在同一台设备上?各种设备?各种iOS版本?是否调用了错误回调?
  • 我认为两次询问同一件事不是一个好习惯。在您的两个问题中,您都没有提供任何详细信息、代码、iOS 版本等,您没有表现出任何研究工作。我强烈建议您删除您的一个问题,并在您保留的问题中包含尽可能多的有关该问题的详细信息。干杯!

标签: ios objective-c iphone push-notification apple-push-notifications


【解决方案1】:

您是否在didFinishLaunchingWithOptionsAppDelegate.m 下方输入了?

if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)
{
    NSLog(@"ios8 app");
    [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
    [[UIApplication sharedApplication] registerForRemoteNotifications];
}
else
{
    NSLog(@"lower ios8 app");
    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)];
}

【讨论】:

    【解决方案2】:

    到目前为止,我也无法获取设备令牌。

    我的项目在大约 10 小时前被“擦除”和“安装”时停止生成设备令牌。 同样在韩国 iOS 开发者论坛中,有些人报告了过去 10 小时内没有生成 APNS 令牌的问题。

    某些沙盒 APNS 服务器可能有问题。

    • 上次检查时间 2016-04-27 22:43 PM +0900 GMT:没有设备令牌,推送通知未到达。

    【讨论】:

    • 这真的发生了吗@CheeseLemon?
    • 是的,现在每个人都在报告,现在它又开始工作了。
    【解决方案3】:

    添加这个方法,

     func application(application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: NSError) 
        {
          print("application:didFailToRegisterForRemoteNotificationsWithError: %@", error)
        }
    

    你会得到答案,为什么没有生成令牌。

    【讨论】:

    • 编辑目标 c:-(void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error{ }
    【解决方案4】:

    @GopalDevra 你能说得更清楚点吗?无论如何,我有这个 Parse 的代码,也许不是你的情况,但你可以理解。

    您可以在 AppDelegate.m 中使用 didRegisterForRemoteNotificationsWithDeviceToken,例如:

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

    已编辑

    你有没有把它放在 didFinishLaunchingWithOptions 中?

    // - Push notifications
    // -- Register for Push Notitications
    UIUserNotificationType userNotificationTypes = (UIUserNotificationTypeAlert |
                                                    UIUserNotificationTypeBadge |
                                                    UIUserNotificationTypeSound);
    UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:userNotificationTypes
                                                                             categories:nil];
    
    [application registerUserNotificationSettings:settings];
    [application registerForRemoteNotifications];
    
    //-- Set Notification
    if ([application respondsToSelector:@selector(isRegisteredForRemoteNotifications)])
    {
        // iOS 8 Notifications
        [application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
    
        [application registerForRemoteNotifications];
    }
    else
    {
        // iOS < 8 Notifications
        [application registerForRemoteNotificationTypes:
         (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound)];        
    }
    
    //--- your custom code
    

    【讨论】:

    • 非常感谢我已经尝试了这些代码行。但不工作
    • @J.Lopes 今天你能自己从沙盒 APN 获取设备令牌吗?
    • @ChrisW.Rea 我今天获得的最后一个设备令牌位于:2016-04-27T03:57:06.942Z 所以我不知道它是否在那之后停止了。我去看看。
    • Apple 开发者论坛中正在进行讨论,表明其他人目前也无法从沙盒 APN 获取设备令牌。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-11-28
    • 1970-01-01
    • 1970-01-01
    • 2016-11-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多