使用PushSharp为iOS和Android处理多个通知 [英] Processing multiple Notifications with PushSharp for ios and android

查看:71
本文介绍了使用PushSharp为iOS和Android处理多个通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我实现了一个Windows服务,该服务每3分钟运行一次,并轮询数据库以获取准备发送的通知.我将它们收集到一个列表中,确定它是ios通知还是android通知,然后调用PushBroker(PushSharp解决方案作为解决方案项目中的已编译解决方案包括在内),然后对列表中的项目进行迭代处理,如下所示:

I have implemented a windows service that runs every 3 minutes and polls a database for notifications that are ready to be sent. I collects them into a list determines whether it is an ios or an android notification and then call the PushBroker (PushSharp solution is included as a compiled solution in my solution project) I then iterate the items in the list to process as follows:

    static void ProcessIOS(List<Client> IOS)
   {
       PushBroker push = new PushBroker();
       push.OnNotificationSent += NotificationSent;
       push.OnChannelException += ChannelException;
       push.OnServiceException += ServiceException;
       push.OnNotificationFailed += NotificationFailed;
       push.OnDeviceSubscriptionExpired += DeviceSubscriptionExpired;
       push.OnDeviceSubscriptionChanged += DeviceSubscriptionChanged;
       push.OnChannelCreated += ChannelCreated;
       push.OnChannelDestroyed += ChannelDestroyed;
       foreach (var entry in IOS)
           {
               string dev = entry.Device_Id.ToString();
               string load = entry.Push_Payload.ToString();
               int count = entry.Unread_Count;
              var appleCert = File.ReadAllBytes(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "../../../productionfile.p12"));
               push.RegisterAppleService(new ApplePushChannelSettings(true, appleCert, "password")); //Extension method
                     push.QueueNotification(new AppleNotification()
                                          .ForDeviceToken(dev)
                                          .WithAlert(load)
                                          .WithBadge(count));
                  }

   }

消息已成功发送,但是,我遇到的问题是 1.尝试在成功发送或失败消息,失败原因等时检索响应.这些都是pushsharp代码中的委托,以便我可以将响应记录到我们的数据库中.为了澄清...我需要知道错误响应来自哪个条目try(deviceID).由于数据未链接到任何特定的deviceid传递尝试,因此我无法从Notificationsent委托生成的消息中分辨出来. 2.我还希望能够在不进行任何修改的情况下按原样保留pushsharp代码,并在我的代码中调用方法,以减少将来对pushsharp代码进行任何更新时的合并问题. 有什么建议? 如果有人可以给我有关如何使用响应事件和委托来为每个通知发送尝试检索信息的示例,我将不胜感激. 谢谢.

The messages are sent successfully, however, the issue I am having is 1. trying to retrieve the responses when message was sent successfully, or failed, reason for failure etc... these are delegates within the pushsharp code so that I can log the responses to our database. For clarification... I need to know what entry attempt(deviceID) the error responses are from. I am unable to tell by the generated messages from the notificationsent delegates since the data is not linked to any particular deviceid delivery attempt. 2. I also want to be able to keep the pushsharp code as is without modifications and call methods from my code to reduce merging issues when any updates are made to pushsharp code in future. Any Suggestions? If anyone can give me any examples on how to use the response events and delegates to retrieve information for each notification send attempt, I would appreciate it. thank you.

推荐答案

我没有得到任何答复,但是通过进一步的研究,我能够解决因失败而导致的问题,并且能够成功发送通知而没有任何错误.解决的办法是重新生成我的证书.由于我将Windows服务器用作推送通知服务器,因此以下步骤将指导您从Windows Server生成APNs证书. 如果您已经从Mac OS X工作站生成了证书,则可以跳过此步骤 部分,然后将您的证书上传到Push Notification Server.

I did not get any replies but with further research I was able to resolve my issue with the failed sucesses and was able to successfully send out notifications with no errors. The solution was to regenerated my certificates. Since I am using a windows server for my push notification server The following steps will guide you to generate an APNs certificate from a Windows Server. If you have already generated your certificate from a Mac OS X workstation, you can skip this section and upload your certificate to the Push Notification Server.

第1步-生成证书签名请求(CSR) 1.转到开始>管理工具> Internet信息服务(IIS)管理器,然后选择 服务器名称. 2.双击服务器证书.

Step 1—Generating a Certificate Signing Request (CSR) 1. Go to Start > Administrative Tools > Internet Information Services (IIS) Manager, and select the server name. 2. Double-click Server Certificates.

注意:本文档中IIS服务器的版本是7.0.

Note: The version of IIS server is 7.0 in this document.

  1. 在右侧的操作"窗格中,单击创建证书申请".申请证书 向导出现.

  1. From the Actions pane on the right, click Create Certificate Request. The Request Certificate wizard appears.

在专有名称属性"窗口中,键入以下内容: •通用名称-与您的Apple Developer帐户关联的名称 •组织-您的组织/公司的合法注册名称 •组织单位-组织中您部门的名称 •城市/位置-您的组织所在的城市 •州/省-您的组织所在的州或省 •国家/地区-您的组织所在的国家或地区

In the Distinguished Name Properties window, type the following: • Common Name—the name associated with your Apple Developer account • Organization—the legally registered name of your organization/company • Organizational unit—the name of your department within the organization • City/locality—the city in which your organization is located • State/province—the state or province in which your organization is located • Country/region—the country or region in which your organization is located

单击下一步".出现密码服务提供者属性"窗口.

Click Next. Cryptographic Service Provider Properties window appears.

在加密服务提供者中选择Microsoft RSA SChannel加密提供者 字段,然后在位长度"字段中输入2048,然后单击下一步".

Select Microsoft RSA SChannel Cryptographic Provider in the Cryptographic service provider field and 2048 in the Bit length field, and then click Next.

选择要保存证书请求文件的位置.请务必记住 文件名和保存文件的位置.

Select a location where you want to save the certificate request file. Make sure to remember the filename and the location where you save the file.

单击完成".您现在已经创建了一个CSR请求,并准备将其上传到您的Apple. 开发门户. 第2步-将CSR上传到您的Apple开发门户并生成 APNs证书 第3步-下载并安装您的APNs证书

Click Finish. You have now created a CSR request and are ready to upload it to your Apple development portal. Step 2— Uploading CSR to your Apple development portal and generate the APNs certificate Step 3— Downloading and Installing your APNs certificate

单击下载"将.cer文件保存到您的计算机.

Click Download to save the .cer file to your computer.

将.cer证书文件复制到创建Windows Server的同一台Windows Server计算机上 证书申请文件.

Copy the .cer certificate file to the same Windows Server computer where you created the certificate request file.

从右侧的操作"窗格中,单击完成证书申请".完整的 出现证书申请向导.

From the Actions pane on the right, click Complete Certificate Request. The Complete Certificate Request wizard appears.

选择从Apple Developer Portal下载的.cer证书文件,然后键入 友好名称字段中应用程序的名称(例如com.xxxx.xxxxx).

Select the .cer certificate file that you downloaded from the Apple Developer Portal, and type the name of your application (e.g. com.xxxx.xxxxx) in the Friendly name field.

提示:友好名称不是证书本身的一部分,而是由服务器使用 管理员可以轻松区分证书. 6.选择确定.证书将安装在服务器上. 7.验证您的Apple Production Push Services证书是否出现在服务器证书上 列表.

Tip: The friendly name is not a part of the certificate itself, but is used by the server administrator to easily distinguish the certificate. 6. Select OK. The certificate will be installed on the server. 7. Verify that your Apple Production Push Services certificate appears on the Server Certificates list.

A.如果可以看到证书,请按照以下步骤导出证书并将其上传到 推送通知服务器. 8.右键单击服务器证书"列表中的证书,然后单击导出".

A. If you can see the certificate, follow the next steps to export the certificate and upload it to the Push Notification Server. 8. Right-click on the certificate in the Server Certificates list, and then click Export.

  1. 选择要保存文件的位置,选择导出密码,然后 单击确定. (导出为.pfx)
  1. Select the location where you want to save the file, choose a password for exporting, and then click OK. (Export as a .pfx)

提示:如果您只能选择另存为.cer文件而不是.pfx文件,那么您就没有 正确导出证书.确保选择了正确的文件导出.如果仍然没有导出为.pfx的选项,请转到下面的步骤B. 注意:确保记住密码,或将其保存在安全的地方.密码将 将证书上载到Push Notification Server时必需. 完成所有这些步骤之后,您应该具有以下各项: •APNs证书(.pfx格式,而不是.cer格式) •导出证书时设置的密码 现在,如果您还不在该服务器上,则可以将其证书上载到Push Notification Server.

Tip: If you only have the option to save as a .cer file rather than a .pfx, then you are not correctly exporting the certificate. Make sure you selected the correct file to export. If you still do not have the option to export as a .pfx go to step B. below. Note: Make sure to remember the password, or keep it in the secure place. The password will be required when uploading the certificate to the Push Notification Server. After completing all these steps, you should have the following items: • APNs certificate (.pfx format, not .cer format) • The password that you set when exporting the certificate You are now ready to upload your certificate to Push Notification Server if you are not on that server already.

B.如果您无法在服务器证书用户界面中看到该证书(如上所示),或者没有选择从该UI导出为.pfx的选项,请按照以下步骤导出证书并将其上传到推送通知服务器. 8.转到Microsoft管理控制台 9.在开始"菜单上,单击运行",键入MMC,然后单击确定". Microsoft管理控制台将打开,并带有一个空的控制台(或管理工具),如下图1所示.在添加一些管理单元之前,空控制台没有管理功能. Microsoft管理控制台窗口顶部的菜单栏上的MMC菜单命令适用于整个控制台.

B. If you DON’T can see the certificate in the Server Certificate UI as shown above or DO NOT have the option to export as a .pfx from that UI, follow the next steps to export the certificate and upload it to the Push Notification Server. 8 . Go to Microsoft Managenment console 9. On the Start Menu, click Run, type MMC, and then click OK. Microsoft Management Console opens with an empty console (or administrative tool) as shown in Figure 1 below. The empty console has no management functionality until you add some snap-ins. The MMC menu commands on the menu bar at the top of the Microsoft Management Console window apply to the entire console.

  1. 单击文件"->打开",然后选择Console1.msc并打开

  1. Click File->Open and select Console1.msc and Open

右键单击要导出的证书,选择所有任务"->导出"

Right click on the certificate you want to export select All Tasks-> Export

在证书导出向导上单击下一步"

Click Next on the Certificate Export Wizard

  1. 选择要保存文件的位置,选择导出密码,然后单击确定". (导出为.pfx)

  • 转到导出的.pfx文件,并将扩展名重命名为.p12.

  • Go to the exported .pfx file and rename extension to .p12.

    这篇关于使用PushSharp为iOS和Android处理多个通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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