ios 将 Apple 推送通知 (APN) 用于 Passbook 时令牌无效

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

Invalid token when using Apple Push Notifications (APN) for Passbook

iospush-notificationapple-push-notificationspassbook

提问by Mike

I am trying to create a server-side implementation for passbook APN, but the server does not like the push token that the device is giving me. If I send the token to Apple's sandbox server, it sends me an "invalid token" response. If I send the token to Apple's production server, it returns the token in the feedback service as one that I should remove from my list. At least I know that the APN certificates and connection to the server work fine.

我正在尝试为存折 APN 创建服务器端实现,但服务器不喜欢设备给我的推送令牌。如果我将令牌发送到 Apple 的沙箱服务器,它会向我发送“无效令牌”响应。如果我将令牌发送到 Apple 的生产服务器,它会在反馈服务中返回令牌作为我应该从列表中删除的令牌。至少我知道 APN 证书和到服务器的连接工作正常。

My iPhone 4s has been enabled for development. The APP ID is enabled for both development and production and the device is enabled in the provisioning profiles. I have verified that the 32 byte binary token data is correct with respect to the string token that is sent from the device.

我的 iPhone 4s 已启用开发。APP ID 为开发和生产启用,设备在配置文件中启用。我已经验证了 32 字节二进制令牌数据对于从设备发送的字符串令牌是正确的。

One question that I have is, how does passbook in the device determine which token to use (development vs production)? I would prefer to be using the sandbox environment right now, but I'm not sure how to "select" it.

我的一个问题是,设备中的存折如何确定使用哪个令牌(开发与生产)?我现在更喜欢使用沙箱环境,但我不确定如何“选择”它。

I have seen similar topics for this but none seem to have the answer for this issue. It is really frustrating as I feel that I'm so close to making this work! Thanks in advance for any advice!

我已经看到了类似的主题,但似乎没有人有这个问题的答案。这真的很令人沮丧,因为我觉得我离完成这项工作很近了!提前感谢您的任何建议!

回答by Eran

If you are using a pruduction certificate to connect to the APN production server, you must use a production token.

如果您使用生产证书连接到 APN 生产服务器,则必须使用生产令牌。

The fact that you get "invalid token" when sending the notification to the sandbox server means you are using a production token, which works only with the production server.

在向沙箱服务器发送通知时获得“无效令牌”这一事实意味着您正在使用生产令牌,该令牌仅适用于生产服务器。

The fact that sending the token to the production server returns the token in the feedback service means that the application that matches the certificate (which your server is using to send the notification) is either uninstalled from the device or has push notifications disabled. Perhaps you are using a wrong certificate (perhaps a certificate that belong to a different App that was uninstalled from the device).

将令牌发送到生产服务器会在反馈服务中返回令牌这一事实意味着与证书(您的服务器用于发送通知)匹配的应用程序已从设备上卸载或禁用了推送通知。也许您使用了错误的证书(也许属于从设备卸载的不同应用程序的证书)。

回答by PassKit

For Passbook pushes, you need to be connecting to the production serverwith the Pass Type IDcertificate, not the App certificate.

对于 Passbook 推送,您需要使用Pass Type ID证书而不是 App 证书连接到生产服务器

All Passbook pushes go through the production server, there is no way to use the sandbox.

所有 Passbook 推送都通过生产服务器,无法使用沙箱。

Also, the push payload should be empty for a Passbook push. Anything you do send will be ignored.

此外,对于 Passbook 推送,推送有效负载应该为空。您发送的任何内容都将被忽略。

回答by pradeep sg

Found the root cause for this issue, it is because of bad private key. To resolve this issue just generate a .p12 certificate with .pem . For creating the p12 file with .pem file please follow the below method

找到了这个问题的根本原因,是因为私钥不好。要解决此问题,只需生成带有 .pem 的 .p12 证书。要使用 .pem 文件创建 p12 文件,请按照以下方法操作

Steps

脚步

回答by Yves Rochon

Rewriting the above statements in text format so you can copy/paste them. That did the trick for me, PushSharp 4.0.10 was returning an error about an invalid certificate, but executing these commands on the original public and private keys solve the problem:

以文本格式重写上述语句,以便您可以复制/粘贴它们。这对我有用,PushSharp 4.0.10 返回关于无效证书的错误,但是在原始公钥和私钥上执行这些命令解决了问题:

openssl x509 -in aps.cer -inform DER -out aps.pem -outform PEM
openssl pkcs12 -nocerts -in mykey.p12 -out mykey.pem
openssl pkcs12 -export -inkey mykey.pem -in aps.pem -out iphone.p12

回答by xcodedeveloper

I stuck in a hour and I find a way to fix it: In xcode 11: project setting -> singing & Capabilities -> (+) -> background -> tick Remote notifications.

我坚持了一个小时,我找到了解决它的方法:在 xcode 11 中:项目设置 -> 唱歌和功能 -> (+) -> 背景 -> 勾选远程通知。