通知中心缺少 iOS 应用程序
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14756820/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
iOS application missing from notification center
提问by e2l3n
Problem:
The app doesn't appear on notification center and it is unable to receive push notifications right after installation completes and the app registers for push notifications via registerForRemoteNotificationTypes:
.
问题:应用程序没有出现在通知中心,安装完成后无法立即接收推送通知,应用程序通过 注册推送通知registerForRemoteNotificationTypes:
。
Details:
细节:
- The app usually appears in notification center after the device is restarted and after that everything works just fine.
- Sometimes the app shows up in notification center right after intallation and registration for APNs(I still can't confirm this but I think I stumbled upon such situations).
- The app calls the method
registerForRemoteNotificationTypes
each time a user logins and each time a user logouts respectively with bit masks (UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound
) andUIRemoteNotificationTypeNone
. enabledRemoteNotificationTypes
returns correct values.- Initially I used the method
unregisterForRemoteNotifications
on logout but I changed it toregisterForRemoteNotificationTypes:UIRemoteNotificationTypeNone
due to suspicians that this could be causing the problem . - This problem occurs in both development and adhoc builds and irrespectively of whether the app is installed via xcode or itunes.
- 该应用程序通常在设备重启后出现在通知中心,之后一切正常。
- 有时应用程序会在安装和注册 APNs 后立即显示在通知中心(我仍然无法确认这一点,但我想我偶然发现了这种情况)。
- 应用程序在
registerForRemoteNotificationTypes
每次用户登录和每次用户注销时分别使用位掩码 (UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound
) 和UIRemoteNotificationTypeNone
. enabledRemoteNotificationTypes
返回正确的值。- 最初我
unregisterForRemoteNotifications
在注销时使用该方法,但registerForRemoteNotificationTypes:UIRemoteNotificationTypeNone
由于怀疑这可能导致问题,我将其更改为。 - 无论应用程序是通过 xcode 还是 itunes 安装,都会在开发和临时构建中出现此问题。
Any thoughts and advices will be greatly appreciated. Thank you!
任何想法和建议将不胜感激。谢谢!
回答by just.jimmy
This was happening to some of my devices. (Not showing up in notification center and not receiving pushes.)
这发生在我的一些设备上。(没有出现在通知中心,也没有收到推送。)
Managed to fix it by doing:
设法通过执行以下操作来修复它:
- Delete the app
- Delete all the relevant profiles from the device. Settings app > General > Profiles, then tap into each of the Provisioning Profiles related to your app, then tap Remove. On iOS 8/9, where the setting no longer exists, use XCode > Windows > Devices > select device > Show provisioning profiles... > then remove the profile(s)
- Turn your phone off, then on again.
- Give 5 mins
- Reinstall your app, the Provisioning Profile should get installed automatically.
- Launch app and let it register and stuff.
- Test push notifications again
- 删除应用
- 从设备中删除所有相关配置文件。设置应用程序 > 通用 > 配置文件,然后点击与您的应用程序相关的每个配置文件,然后点击删除。在 iOS 8/9 上,设置不再存在,使用 XCode > Windows > 设备 > 选择设备 > 显示配置文件... > 然后删除配置文件
- 关闭手机,然后再打开。
- 给 5 分钟
- 重新安装你的应用,Provisioning Profile 应该会自动安装。
- 启动应用程序,让它注册和东西。
- 再次测试推送通知
For us, it didn't work immediately, so give it a few minutes.
对我们来说,它没有立即起作用,所以给它几分钟。
回答by irodrigo17
Maybe there is a problem with registering and unregistering the app at login/logout respectively, from Apple's documentation:
从Apple 的文档中,可能分别在登录/注销时注册和取消注册应用程序存在问题:
An application should register every time it launches and give its provider the current token.
应用程序应在每次启动时进行注册,并为其提供者提供当前令牌。
And not sure about unregistering, they don't mention unregistering in their programming guide, maybe the app should never unregister and the server should handle that, by sending or not sending push notifications depending if the user is logged in or not. This is how I've done it in the past, and never experienced this issue, so maybe this approach works for you too.
并且不确定取消注册,他们在他们的编程指南中没有提到取消注册,也许应用程序永远不应该取消注册并且服务器应该通过发送或不发送推送通知来处理这个问题,具体取决于用户是否登录。我过去就是这样做的,从来没有遇到过这个问题,所以也许这种方法也适用于你。
回答by Jennifer
Well, I also have this problem, I found that as the application used the unregisterForRemoteNotifications before uninstall at the previous install.
嗯,我也有这个问题,我发现应用程序在卸载之前使用了 unregisterForRemoteNotifications。
And, in addition, if the application install again and login to register for the remote notifications, this problem will happen.
此外,如果应用程序再次安装并登录以注册远程通知,则会出现此问题。
It happened also at the first install(installed after reset your iOS device). if you use the unregisterForRemoteNotifications before login, then register at the login operation, this problem will happen.
它也在第一次安装时发生(在重置您的 iOS 设备后安装)。如果在登录前使用unregisterForRemoteNotifications,然后在登录操作时注册,就会出现这个问题。
As this problem happened, you need to restart the iOS device.
发生此问题时,您需要重新启动 iOS 设备。
For the unregisterForRemoteNotifications, we couldn't stop this problem, but we can reduce the probability of the occurrence of the problem, the method is:
对于unregisterForRemoteNotifications,我们无法阻止这个问题,但是我们可以降低问题发生的概率,方法是:
If the device token didn't delete from provider at the previous install, then use unregisterForRemoteNotifications at the current install before login; Otherwise, you should never use unregisterForRemoteNotifications.
如果设备令牌在上次安装时没有从提供者中删除,则在登录前在当前安装中使用 unregisterForRemoteNotifications;否则,您永远不应使用 unregisterForRemoteNotifications。