使用 ASP.NET 服务器添加 iPhone 推送通知 [英] Add iPhone push notification using ASP.NET server

查看:25
本文介绍了使用 ASP.NET 服务器添加 iPhone 推送通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是概览.

我需要向 iPhone 应用程序添加推送通知.服务器端是c#中的ASP.NET.

I need to add push notification to an iPhone app. Server side is ASP.NET in c#.

我想要的是一些指导来完成整个过程.然后,我将发布 iPhone 项目和 ASP.NET Web 应用的通用代码以及分步说明,以便其他人可以学习.

What I would like is some coaching to work through the process. I will then post generic code for an iPhone project and an ASP.NET web app along with step-by-step instructions so that others can learn.

这是我的理解:

  1. 申请 APNS 证书并将其添加到钥匙串中.(不确定如何将其引入 ASP.NET)
  2. 让 iPhone 使用 registerForRemoteNotificationWithTypes 进行注册,将值发送到您的服务器,并存储在数据库中.似乎这个注册代码应该很容易,但我找不到一个好的样本.(将值发送到 ASP.NET 服务器没有问题.)
  3. 您的服务器应用创建一个负载字符串,进行 JSON 编码,使用保存在数据库中的设备令牌为每台(或可以是组)iPhone 发送到 APNS 服务器.

所以为了开发附加功能,这里是部分:

So to develop the addition, here are the pieces:

  • iPhone 注册码

  • The iPhone registration code

将 iPhone 注册码发送到服务器并保存到数据库的代码(这很简单,我已经有了这些部分).

Code that sends iPhone registration code to server and saves to DB (this is easy and I already have these pieces).

c#中的服务器端APNS联系代码.这还包括如何使用在 Apple Developer 网站上生成的证书.

The server side APNS contact code in c#. This also includes how to use the certificate that was generated on the Apple Developer web site.

此外,有效载荷是否可以是一个多项选择题,可以通过将结果发送回服务器来回答?

Also, can the payload be a multiple choice question that can be answered with the result sent back to the server?

在此先感谢您的帮助.我会把它变成其他人的教程.

Thanks in advance for the help. I will turn this in to a tutorial for others.

推荐答案

这让我花了很长时间才弄明白,但我终于从人们留下的小线索中拼凑起来.您需要下载您在开发者门户上注册的APPID 的证书.该证书必须转换为 P12 格式才能在 Windows 上使用.UNIX 中的这些命令终于为我做到了:

This took me forever to figure out but I finally pieced it all together from the minor clues people left. You need to download the certificate for the APPID that you register on the developer portal. That certificate must be converted into a P12 format to be used on Windows. These commands in UNIX finally did it for me:

第 1 步:

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

其中 aps_developer_identity.cer 是您从门户下载的文件

Where aps_developer_identity.cer is the file you download from the portal

第 2 步:

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

其中 APSCertificates.p12 是您从 Mac Keychain 导出的文件.这很关键,您必须将证书从门户导入钥匙串.在我的证书中找到它,打开披露三角形并突出显示证书和私钥,然后右键单击并导出它们.给他们一个密码并将它们保存到一个 p12 文件中.

Where APSCertificates.p12 is a file you export from the Mac Keychain. This is critical, you must import the certificate from the portal into keychain. Find it in My Certificates, open the disclosure triangle and highlight both the certificate and the private key, then right click and export them. Give them a password and save them to a p12 file.

第 3 步:

openssl pkcs12 -export -in aps_developer_identity.pem -out aps_developer_identity.p12 -inkey APSCertificates.pem

系统会多次提示您输入用于导出 Keychain 中的证书和私钥的密码,并再次提示输入新密码以重新加密所有内容,但最终您将获得文件 aps_developer_identity.p12您需要移至 Windows,然后将其导入 MMC 中证书管理器的 Personal 和 Trusted Root 部分.然后在 C# 中,当您使用 MoonAPNS 并调用 PushNotification 类时,您会为其提供该证书的路径.还要确保从设备令牌中删除空格.

You will be prompted a few times for the password you used to export the certificate and private key in Keychain and prompted again for new passwords to re-encrypt it all, but in the end you will have the file aps_developer_identity.p12 which you need to move to windows, then import it into both the Personal and Trusted Root sections of certificate manager in MMC. Then in C# when you use MoonAPNS and call the PushNotification class you give it a path to that certificate. Also make sure to remove spaces from the device token.

这篇关于使用 ASP.NET 服务器添加 iPhone 推送通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆