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

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

问题描述

我实现了一个每 3 分钟运行一次的 Windows 服务,并轮询数据库以获取准备发送的通知.我将它们收集到一个列表中,确定它是 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 代码中的委托,以便我可以将响应记录到我们的数据库中.为了澄清......我需要知道错误响应来自哪个条目尝试(设备ID).我无法通过通知代表生成的消息来判断,因为数据未链接到任何特定的 deviceid 传递尝试.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 服务器生成 APNs 证书.如果您已经从 Mac OS X 工作站生成了证书,则可以跳过此步骤部分并将您的证书上传到推送通知服务器.

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.

在Cryptographic service provider中选择Microsoft RSA SChannel Cryptographic Provider字段和位长度字段中的 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 证书文件复制到您创建证书请求文件.

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)

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

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 中看不到证书,如上所示,或者没有从该 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 for ios 和 android 处理多个通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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