xcode 当用户加载应用程序时推送通知不请求许可

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10846451/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 00:27:41  来源:igfitidea点击:

Push notifications not asking permission when user loads app

objective-ciosxcode

提问by Alex G

Hi I have just released my app update with push notifications added into it. I was worried that it would not work properly so I did a bunch of testing. First with just a development certificate and then a production certificate using adhoc. Both ended up working and I was pleased when the adhoc worked.

嗨,我刚刚发布了我的应用程序更新,其中添加了推送通知。我担心它不能正常工作,所以我做了一堆测试。首先只有开发证书,然后是使用 adhoc 的生产证书。两者最终都工作了,当临时工作时我很高兴。

Anyways the update has been live for about 8 hours now and for some reason push isn't working. I checked with my friend and have realized that the user is not being asked whether he wants to accept push notifications from my app. Which means when the token gets sent to my server, its appearing as (null). I have no idea why this is happening. When he goes into device settings --> notifications ---> my app does not appear on any of the lists (receiving push notifications or not receiving).

无论如何,更新现在已经上线了大约 8 个小时,但由于某种原因推送不起作用。我与我的朋友核实过,并意识到没有询问用户是否愿意接受来自我的应用程序的推送通知。这意味着当令牌发送到我的服务器时,它显示为(空)。我不知道为什么会这样。当他进入设备设置 --> 通知 ---> 我的应用程序没有出现在任何列表中(接收推送通知或未接收)。

This is the code in my delegate that should trigger the request:

这是我的委托中应该触发请求的代码:

[[UIApplication sharedApplication] registerForRemoteNotificationTypes:
 (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];

If anyone knows why this is happening, input would be much appreciated. Thanks!

如果有人知道为什么会发生这种情况,将不胜感激。谢谢!

回答by respectTheCode

We thought we were having this same issue but found out that the app was actually working correctly. The user is only prompted once even if they uninstall and reinstall the app.

我们以为我们遇到了同样的问题,但发现该应用程序实际上运行正常。即使用户卸载并重新安装应用程序,也只会提示用户一次。

We were testing it by uninstalling the app and then reinstalling. iOS would remember how we had responded previously on that device and would not prompt again leading us to think there was a problem.

我们通过卸载应用程序然后重新安装来测试它。iOS 会记住我们之前在该设备上的响应方式,并且不会再次提示导致我们认为存在问题。

We found the best way to test is with the simulator and doing a "Reset Content and Settings".

我们发现最好的测试方法是使用模拟器并执行“重置内容和设置”。

回答by Heiberg

After configuring your app for push notifications and generating your SSL certificates you must also generate new provisioning profiles.

为推送通知配置应用程序并生成 SSL 证书后,您还必须生成新的配置文件。

The developer portal displays this message on the App ID configuration page:

开发者门户在 App ID 配置页面上显示此消息:

After you have generated your Client SSL certificate, create a new provisioning profile containing the App ID you wish to use for notifications.

生成客户端 SSL 证书后,创建一个新的配置文件,其中包含您希望用于通知的 App ID。

If you did not update your App Store provisioning profile after setting up push the OS will not provide you with a push token.

如果您在设置推送后没有更新您的 App Store 配置文件,操作系统将不会为您提供推送令牌。

If this is your problem you just need to generate a new App Store distribution profile and submit a recompiled version signed with that profile.

如果这是您的问题,您只需要生成一个新的 App Store 分发配置文件并提交使用该配置文件签名的重新编译版本。