ios - 使用 Moon-APNS 或 APNS-Sharp 的 Apple 推送通知

标签 ios apple-push-notifications apns-sharp

我很难弄清楚如何将消息从我的服务器发送到 APNS。我使用过 Moon-APNS 和 APNS-Sharp,但遇到了同样的错误,即“参数不正确”。我使用 KeyChain 生成了 p12 文件。我将该文件拖到我的 Win 7 虚拟环境中并将其放入 bin\debug 文件夹中。这是 Moon-APNS 的代码:

 static void Main(string[] args)
        {
            var deviceToken = "21212d6fefebde4d317cab41afff65631b5a4d47e5d85da305ec610b4013e616";

            var payload = new NotificationPayload(deviceToken, "hello world");
            var notificationList = new List<NotificationPayload>() { payload };

            var push = new PushNotification(true, "PushNotificationTest.p12", "pushchat");
            var result = push.SendToApple(notificationList);

            Console.WriteLine("Hello World");  
        }

有人有想法吗?

最佳答案

我认为这会对您有所帮助:

OSX 钥匙串(keychain)

在 iPhone 开发者计划门户中创建适当的推送通知证书后,您应该下载了一个名为 apn_developer_identity.cer 之类的文件。如果您还没有这样做,您应该打开/导入此文件到钥匙串(keychain)中,进入您的登录部分。

最后,如果您过滤钥匙串(keychain)以显示登录容器的证书,您应该会看到列出的证书。展开证书,下面/附加一个 key 。

右键单击或按住 Ctrl 键并单击相应的证书,然后选择“导出”。钥匙串(keychain)会要求您选择要导出的密码。选择一个并记住它。您最终应该得到一个 .p12 文件。您将需要此文件和您选择的密码才能使用此处的通知和反馈库。 OpenSSL

以下是如何使用open ssl创建PKCS12格式文件,您将需要您的开发者私钥(可以从钥匙串(keychain)导出)和CertificateSigningRequest??.certSigningRequest

1. Convert apn_developer_identity.cer (der format) to pem:

openssl x509 -in apn_developer_identity.cer -inform DER -out apn_developer_identity.pem -outform PEM}

2. Next, Convert p12 private key to pem (requires the input of a minimum 4 char password):

openssl pkcs12 -nocerts -out private_dev_key.pem -in private_dev_key.p12

3. (Optional): If you want to remove password from the private key:

openssl rsa -out private_key_noenc.pem -in private_key.pem

4. Take the certificate and the key (with or without password) and create a PKCS#12 format file:

openssl pkcs12 -export -in apn_developer_identity.pem -inkey private_key_noenc.pem -certfile CertificateSigningRequest??.certSigningRequest -name "apn_developer_identity" -out apn_developer_identity.p12

我发现 Moon-APNS 在我的应用程序上更易于使用和配置。

关于ios - 使用 Moon-APNS 或 APNS-Sharp 的 Apple 推送通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7080318/

相关文章:

ios - 在 swift 3 的不同部分的 TableView 中执行互斥选择的最佳方法

Ios Google Map Cluster 项目点击事件不起作用

objective-c - 从 CVImageBufferRef 获取内存所有权

iphone - APNS 只能通过命令行工作

apns Sharp 中的 iPhone 证书错误 对 SSPI 的调用失败

c# - 带有 APNS sharp 的苹果推送通知

ios - 请求 APNs VoIP 通知 (Flutter iOS)

iOS:当应用程序处于前台时,如何让用户忽略远程通知?

ios - 自定义声音远程推送通知 iOS 不工作