xcode 应用从应用商店返回设备令牌的空值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10996121/
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
App returns null value for device token from app store
提问by Alex G
I have released my app update with push notifications however when I check my server, I notice that the token that was sent to the database is "null". I did lots of testing using a development certificate AND a production certificates for ad hoc. Both worked succesfully but the version on the app store does not and I have no idea why. I posted about this issue about 2 weeks ago and someone told me I should not use the provisioning profile I used for ad hoc so I created a new provisioning profile with the same id. Update got releases yesterday and I still have the same problem. I need to find a permanent solution since my users are getting annoyed with all these updates but I don't know how to test until it gets approved on the app store.
我已经通过推送通知发布了我的应用程序更新,但是当我检查我的服务器时,我注意到发送到数据库的令牌为“空”。我使用开发证书和临时生产证书进行了大量测试。两者都成功运行,但应用商店上的版本没有,我不知道为什么。我在大约 2 周前发布了关于这个问题的帖子,有人告诉我我不应该使用我用于临时的配置文件,所以我创建了一个具有相同 ID 的新配置文件。昨天更新发布了,我仍然有同样的问题。我需要找到一个永久的解决方案,因为我的用户对所有这些更新感到恼火,但在应用商店获得批准之前我不知道如何进行测试。
If anyone can please offer thoughts or assistance I would really appreciate it. Thanks in advance.
如果有人可以提供想法或帮助,我将不胜感激。提前致谢。
P.S. if it helps, I deleted my app from my device and installed it again from the app store... It did not ask me if I wanted to receive push notifications but push is enabled for the app from the phone settings...
PS如果有帮助,我从我的设备中删除了我的应用程序并从应用程序商店重新安装了它......它没有问我是否想接收推送通知但是从手机设置中为应用程序启用了推送......
回答by Angel G. Olloqui
There are 3 steps in an APNs communication:
APNs 通信有 3 个步骤:
- Your app registers to receive APNs in your appDelegate within your iOS. This will give you a deviceToken that you should use to send notifications.
- Your app sends the deviceToken to your management server
- Your management server connects with Apple APNs server to send the Push Notification
- 您的应用在 iOS 中的 appDelegate 中注册以接收 APN。这将为您提供一个 deviceToken,您应该使用它来发送通知。
- 您的应用程序将 deviceToken 发送到您的管理服务器
- 您的管理服务器与 Apple APNs 服务器连接以发送推送通知
In your case, I understand that your problem is in step 1 because you said that you are having a null device id and the app is not asking you about the APNs permission. Therefore, changing your server certificate or switching from gateway.sandbox.push.apple.com to gateway.push.apple.com is not going to help because the error happens before.
在您的情况下,我了解您的问题在第 1 步,因为您说您的设备 ID 为空,并且应用程序没有询问您有关 APNs 权限的问题。因此,更改服务器证书或从 gateway.sandbox.push.apple.com 切换到 gateway.push.apple.com 都无济于事,因为错误发生在之前。
This is clearly a problem with your certificates. You should check that you have done all the required steps in your Apple iOS Provisioning Portal:
这显然是您的证书的问题。您应该检查您是否已在Apple iOS Provisioning Portal 中完成所有必需的步骤:
- Create an AppIdwith the bundle identifier of your app. Avoid wildcars such as *.
- Configure your InAppPurchase options for your app (this is not the problem because is used for step 3 in the communication)
- Create a provisioning profile for Distribution which uses the AppIdused in 1. (I suspect that this could be your problem), and download it
- Open XCode project settings and check that your archiving operation uses the correct profiledonwloaded in 3. Be sure that you pick the correct one when Organizer asks for one. (if the previous step was OK, then this is definetely your problem, so double or triple check it).
- 使用您的应用程序的包标识符创建一个AppId。避免使用诸如 * 之类的通配符。
- 为您的应用程序配置 InAppPurchase 选项(这不是问题,因为用于通信中的第 3 步)
- 使用 1 中使用的 AppId 为 Distribution创建配置文件(我怀疑这可能是您的问题),然后下载它
- 打开 XCode 项目设置并检查您的归档操作是否使用了 3 中下载的正确配置文件。请确保在 Organizer 要求时选择正确的配置文件。(如果上一步没问题,那么这肯定是您的问题,因此请仔细检查它)。
If your want to be sure that your binary was generated with the correct profile before submitting it again to AppStore, do the following:
如果您想在再次将其提交到 AppStore 之前确保您的二进制文件是使用正确的配置文件生成的,请执行以下操作:
- Open the binary with Finder (first, open the archive at Library/Developer/XCode/Archives/..., right click on it and "Show package contents", navigate to /Products/Applications/youApp, show package contents again),
- Look for the file embedded.mobileprovision and open it with a text editor
- Among the binary content, you should be able to localize a couple of fields called "application-identifier" and "aps-environment". Check they have the correct values.
- 使用 Finder 打开二进制文件(首先,在 Library/Developer/XCode/Archives/... 打开存档,右键单击它并“显示包内容”,导航到 /Products/Applications/youApp,再次显示包内容),
- 查找文件embedded.mobileprovision 并使用文本编辑器打开它
- 在二进制内容中,您应该能够本地化名为“application-identifier”和“aps-environment”的几个字段。检查它们是否具有正确的值。
I bet that if you check your previously archived apps you will see an incorrect profile. This is the only cause for your app not to return a deviceToken.(unless it receives it but it is not correctly sent to your server, a problem in step 2 of the communication above).
我敢打赌,如果您检查以前存档的应用程序,您会看到不正确的配置文件。这是您的应用程序不返回 deviceToken 的唯一原因。(除非它收到它但没有正确发送到您的服务器,这是上述通信步骤 2 中的问题)。
回答by xapslock
Do you use gateway.push.apple.comand not gateway.sandbox.push.apple.com?
你使用gateway.push.apple.com而不是gateway.sandbox.push.apple.com吗?
回答by ?ystein
If you have created a new provisioning profile for your application, I think you need to generate new certificates on your server as well.
如果您为您的应用程序创建了一个新的配置文件,我认为您还需要在您的服务器上生成新证书。
回答by Alphonse R. Dsouza
If you can check your app logs in 'console app'(organizer>device>console ) by connecting device installed with your app containing device token null issue.
如果您可以通过连接安装了包含设备令牌空问题的应用程序的设备,在“控制台应用程序”(组织者>设备>控制台)中检查您的应用程序日志。
Based on this
no valid 'aps-environment' entitlement string found for applicationThe problem is due to current Provisioning Profile does not contain APNS information, as the Provisioning Profile is created BEFORE creating the APNS certificate.
Solution:create a new Provisioning Profile & select the Provisioning Profile in Xcode will clear the error.
You can execute terminal command to check 'production provisional profile' supports apns environment or not and it should look similar to the following:
基于此
没有为应用程序找到有效的“aps-environment”权利字符串问题是由于当前的配置文件不包含 APNS 信息,因为配置文件是在创建 APNS 证书之前创建的。
解决方案:创建一个新的 Provisioning Profile 并在 Xcode 中选择 Provisioning Profile 将清除错误。
您可以执行终端命令来检查“生产临时配置文件”是否支持 apns 环境,它应该类似于以下内容:
security cms -D -iPath_Of_Your_AppStoreDistribution.mobileprovision
安全 cms -D -iPath_Of_Your_AppStoreDistribution.mobileprovision
<key>Entitlements</key>
<dict>
<key>application-identifier</key>
<string>H22LLUHM4D.com.company.appName</string>
<key>aps-environment</key>
<string>production</string>
<key>get-task-allow</key>
<false/>
</dict>