didRegisterForRemoteNotificationsWithDeviceToken 从未在特定设备上调用 [英] didRegisterForRemoteNotificationsWithDeviceToken never called on specific device

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

问题描述

首先,我使用的是 iPhone 6 Plus/iOS 8.1,我在这里尝试了一切:为什么不调用 didRegisterForRemoteNotificationsWithDeviceToken

First of all, I am on iPhone 6 Plus/iOS 8.1 and I've tried everything here: why didRegisterForRemoteNotificationsWithDeviceToken is not called

还是没用.总结一下:

  • 我检查了我的包标识符与配置文件/开发门户中的标识符相匹配
  • 我创建了一个新的开发推送 APNS 证书
  • 我创建了一个新的开发证书
  • 我为该开发证书创建了一个新的配置文件
  • 我已经下载了证书和配置文件,显然,双击它们进行安装
  • 我已在 Developer Portal 上验证一切正常:所有证书和配置文件均有效、已启用推送并使用我的新 APNS 证书进行配置
  • 我已将我的新 APNS 证书上传到 Parse(这与这一步无关,但无论如何),因为我将 Parse 用于我的后端
  • 我已确保在 Xcode 中使用正确的证书/配置文件对进行协同设计
  • 我已经检查了通知设置,以防我的应用程序无法接收推送,但它不存在
  • 我尝试将日期手动设置为明天并尝试重新安装应用
  • 我已从我的设备中删除了该应用
  • 我已从我的设备中删除了所有相关的配置文件
  • 我已经多次重启我的设备

application:didFinishLaunchingWithOptions: 我调用:

if([application respondsToSelector:@selector(registerUserNotificationSettings:)]){
        //iOS 8+
        [application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
    }else{
        //pre-iOS 8
        [[UIApplication sharedApplication] registerForRemoteNotificationTypes:
         (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
    }

application:didRegisterUserNotificationSettings: 我调用:

[application registerForRemoteNotifications];

我用断点检查过它,它确实被调用了.我还实现了两种方法:

I've checked it with a breakpoint, it DOES get called. I've also implemented two methods:

application:didRegisterForRemoteNotificationsWithDeviceToken:

application:didFailToRegisterForRemoteNotificationsWithError:

然而,它们都没有被调用.不是错误,什么都没有.控制台也没有错误.(我今天早些时候遇到了一个关于权利的问题,但创建新的证书/配置文件解决了这个问题)

However, neither of them is called. Not an error, nothing. No error at the console either. (I've had an issue about entitlements earlier today, but creating new certificate/provisioning profile solved that)

可能是什么问题?

更新:这里有一些东西.在 application:didRegisterUserNotificationSettings: 中,我检查了通知设置,这是我得到的:

UPDATE: Here is something. In application:didRegisterUserNotificationSettings: I've checked the notification settings and here is what I've got:

(lldb) po notificationSettings
<UIUserNotificationSettings: 0x170031cc0; types: (none);>

更新 2: 我再次检查了通知,发现现在我的应用已添加到设置"中的通知中,它已启用,并已授予权限.但仍然没有调用处理程序.类型是无.我 99% 确定这与问题有关.

UPDATE 2: I've checked notifications again, and found out that now my app is added to the notifications in Settings, it's enabled, given permissions. But still, the handler is not called. Types are none. I'm 99% sure it's related to the problem.

更新 3: 我已经在另一台设备(iPod touch、iOS 8.1)上进行了测试,没有遇到任何问题.它立即使用其令牌调用 application:didRegisterForRemoteNotificationsWithDeviceToken: 方法.该问题特定于我的 iPhone.

UPDATE 3: I've tested on another device (iPod touch, iOS 8.1), and I've got no problems there. It immediately called the application:didRegisterForRemoteNotificationsWithDeviceToken: method with its token. The problem is specific to my iPhone.

推荐答案

我遇到了类似的问题,代码已经实现并且运行良好.突然,经过一些调整后,它不再起作用了.

I got a similar problem, the code was already implemented and working fine. Suddenly, after some adjustments, it just don't work it anymore.

在设备上运行的场景是:

The scenario running on device was:

  • didFinishLaunchingWithOptions 上调用 registerForRemoteNotifications.
  • didRegisterForRemoteNotificationsWithDeviceToken 不会调用
  • 也不会调用didFailToRegisterForRemoteNotificationsWithError.
  • Call registerForRemoteNotifications on didFinishLaunchingWithOptions.
  • The didRegisterForRemoteNotificationsWithDeviceToken won't call
  • nor didFailToRegisterForRemoteNotificationsWithError won't call.

我尝试了所有方法,几乎​​重置了所有推送配置和证书以及配置文件等.使用最新版本的所有设备都可以工作,但是当我安装新版本时,就不再工作了.

I tried everything, almost reset all push configurations and certificates and provisioning profiles, etc.. All devices with the last version was working, but when I install the new version, just don't work anymore.

为了解决这个问题,我只是这样做了:

To solve this, I just did this:

  1. 去了目标能力;
  2. 关闭推送通知 关闭;
  3. 构建 &在设备上运行应用程序并等待;
  4. 停止运行应用程序;
  5. 再次打开推送通知打开.
  6. 构建 &在设备上运行应用程序;
  7. 就像魔法一样,它再次发挥作用
  1. Went to the target capabilities;
  2. Turn the Push Notification Off;
  3. Build & Run the app on device and wait;
  4. Stop running the app;
  5. Turn the Push Notification On again.
  6. Build & Run the app on device;
  7. And like magic, it worked again

在与 Xcode 斗争 6 小时后,这是我的解决方案,没有任何解释.

After 6h fighting with Xcode, that was my solution, without any explanation.

我希望这对某人有所帮助.

I hope this help someone.

这篇关于didRegisterForRemoteNotificationsWithDeviceToken 从未在特定设备上调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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