IOS通过PushSharp开源框架发送推送
1,首先生成推送证书:
openssl x509 -in aps_developer_identity.cer -inform DER -out aps_developer_identity.pem -outform PEM
openssl pkcs12 -nocerts -out PushChat_Noenc.pem -in PushChatKey.p12
(cat aps_developer_identity.pem PushChat_Noenc.pem > ck.pem)
openssl pkcs12 -export -in aps_developer_identity.pem -inkey PushChat_Noenc.pem -certfile PushChat.certSigningRequest -name "aps_developer_identity" -out aps_developer_identity.p12 (C#必须)
2.下载框架http://pan.baidu.com/s/1pJoD8IR或者https://github.com/Redth/PushSharp
3.调用方法
#region
/// <summary>
/// 发送消息
/// </summary>
/// <param name="deviceToken">设备令牌</param>
/// <param name="message">消息内容</param>
private void SendMessage(List<string> deviceToken, string message)
{
//创建推送对象
var pusher = new PushBroker();
pusher.OnNotificationSent += pusher_OnNotificationSent;//发送成功事件
pusher.OnNotificationFailed += pusher_OnNotificationFailed;//发送失败事件
pusher.OnChannelCreated += pusher_OnChannelCreated;
pusher.OnChannelDestroyed += pusher_OnChannelDestroyed;
pusher.OnChannelException += pusher_OnChannelException;
pusher.OnDeviceSubscriptionChanged += pusher_OnDeviceSubscriptionChanged;
pusher.OnDeviceSubscriptionExpired += pusher_OnDeviceSubscriptionExpired;
pusher.OnNotificationRequeue += pusher_OnNotificationRequeue;
pusher.OnServiceException += pusher_OnServiceException;
//注册推送服务
byte[] certificateData = File.ReadAllBytes(CertificatePath);
pusher.RegisterAppleService(new ApplePushChannelSettings(false, certificateData, CertificatePassword));
foreach (string token in deviceToken)
{ //给指定设备发送消息
pusher.QueueNotification(new AppleNotification()
.ForDeviceToken(token)
.WithAlert(message)
.WithBadge()
.WithSound("default"));
}
} void pusher_OnServiceException(object sender, Exception error)
{
msg = error.ToString(); Console.WriteLine("消息发送失败,错误详情:" + error.ToString());
} void pusher_OnNotificationRequeue(object sender, PushSharp.Core.NotificationRequeueEventArgs e)
{
msg = "pusher_OnNotificationRequeue"; Console.WriteLine("pusher_OnNotificationRequeue");
} void pusher_OnDeviceSubscriptionExpired(object sender, string expiredSubscriptionId, DateTime expirationDateUtc, PushSharp.Core.INotification notification)
{
msg = "pusher_OnDeviceSubscriptionChanged"; Console.WriteLine("pusher_OnDeviceSubscriptionChanged");
} void pusher_OnDeviceSubscriptionChanged(object sender, string oldSubscriptionId, string newSubscriptionId, PushSharp.Core.INotification notification)
{
msg = "pusher_OnDeviceSubscriptionChanged"; Console.WriteLine("pusher_OnDeviceSubscriptionChanged");
} void pusher_OnChannelException(object sender, PushSharp.Core.IPushChannel pushChannel, Exception error)
{
msg = error.ToString(); Console.WriteLine("消息发送失败,错误详情:" + error.ToString());
} void pusher_OnChannelDestroyed(object sender)
{
msg = "pusher_OnChannelDestroyed";
//JScript.alert("pusher_OnNotificationRequeue");
Console.WriteLine("pusher_OnChannelDestroyed");
} void pusher_OnChannelCreated(object sender, PushSharp.Core.IPushChannel pushChannel)
{ msg = "pusher_OnChannelCreated";
Console.WriteLine("pusher_OnChannelCreated");
} void pusher_OnNotificationFailed(object sender, PushSharp.Core.INotification notification, Exception error)
{
msg = error.ToString(); Console.WriteLine("消息发送失败,错误详情:" + error.ToString());
} void pusher_OnNotificationSent(object sender, PushSharp.Core.INotification notification)
{
msg = "消息发送成功"; Console.WriteLine("消息发送成功!");
}
#endregion
4,我遇到的异常The maximum number of Send attempts to send the notification was reached!
可以修改
FeedbackService.cs和 ApplePushChannel.cs中的System.Security.Authentication.SslProtocols.Ssl3为System.Security.Authentication.SslProtocols.Tls两处即可
IOS通过PushSharp开源框架发送推送的更多相关文章
- 转:向IOS设备发送推送通知
背景 SMS 和 MMS 消息是由无线运营商通过设备的电话号码向特定设备提供的.实现 SMS/MMS 的服务器端应用程序的开发人员必须费大量精力才能与现有的封闭电信基础架构进行交互(其中包括获取电话号 ...
- Android、iOS和Windows Phone中的推送技术
推送并不是什么新技术,这种技术在互联网时代就已经很流行了.只是随着进入移动互联网时代,推送技术显得更加重要.因为在智能手机中,推送从某种程度上,可以取代使用多年的短信,而且与短信相比,还可以向用户展示 ...
- iOS超全开源框架、项目和学习资料汇总--数据库、缓存处理、图像浏览、摄像照相视频音频篇
iOS超全开源框架.项目和学习资料汇总--数据库.缓存处理.图像浏览.摄像照相视频音频篇 感谢:Ming_en_long 的分享 大神超赞的集合,http://www.jianshu.com/p/f3 ...
- iOS直播-基于RTMP的视频推送
iOS直播-基于RTMP的视频推送 所谓的视频推送就是把摄像头和麦克风捕获到视频和音频推送到直播服务器上.我们这里使用推送协议是RTMP协议. 扩展:腾讯直播平台,阿里直播平台,百度直播平台提供均为R ...
- 李洪强iOS经典面试题154- 通知与推送
李洪强iOS经典面试题154- 通知与推送 通知与推送 本地通知和远程推送通知对基本概念和用法? image 本地通知和远程推送通知都可以向不在前台运行的应用发送消息,这种消息既可能是即将发生的事 ...
- iOS超全开源框架、项目和学习资料汇总(5)AppleWatch、经典博客、三方开源总结篇
完整项目 v2ex – v2ex 的客户端,新闻.论坛.apps-ios-wikipedia – apps-ios-wikipedia 客户端.jetstream-ios – 一款 Uber 的 MV ...
- 【转】iOS超全开源框架、项目和学习资料汇总
iOS超全开源框架.项目和学习资料汇总(1)UI篇iOS超全开源框架.项目和学习资料汇总(2)动画篇iOS超全开源框架.项目和学习资料汇总(3)网络和Model篇iOS超全开源框架.项目和学习资料汇总 ...
- iOS打包后收不到推送信息
今天遇到的一个特别神奇的问题: 应用在测试环境下打的包收不到推送了,打包之后都没有推送,但是我真机测试又是可以收到推送消息的.经过好久才找到原因,感觉很坑.这里记录一下问题: 1.由于我的推送第三方使 ...
- [Apple开发者帐户帮助]六、配置应用服务(5.3)推送通知(APN):从您的Web服务器发送推送通知
要使用APN从Web服务器向macOS用户发送推送通知,请注册网站推送标识符并创建网站推送证书. 对于每个网站,请注册一个网站推送标识符,用于验证通知是否来自您的服务器.然后创建一个网站推送证书以签署 ...
随机推荐
- NoSql中的B-tree、B+tree和LSM-tree
总结: 1.B+树将数据完全排序,读数据时很快,但当要修改数据时,就需要将新入数据下面的数据重新排位,特别是当写入的数据排在较高的位置时,需要大量的移位操作才能完成写入. 2.SLM牺牲部分的读性能, ...
- CSS样式总结
CSS: Cascading Style Sheet,层叠样式表 Css由三部分组成:选择符.样式属性.值: 基本语法:选择符 {样式属性:值:样式属性:值.....} 一,选择器 常用的选择器有:标 ...
- CSS3属性之一:border-radius
语法: border-radius : none | <length>{1,4} [ / <length>{1,4} ]? 相关属性: border-top-right-rad ...
- VMware网络配置 实现与物理机互访
虚拟机和物理主机互访,两台机器可以互访并可以被局域网内其他机器访问,可以ping通并可以访问网站. 这几天正好有空搞个虚拟机,并装了不同系统,以备不同部署环境需要.明明是搞编程的,却不得不学各种知识, ...
- IOS响应式编程框架ReactiveCocoa(RAC)使用示例-备
ReactiveCocoa是响应式编程(FRP)在IOS中的一个实现框架,它的开源地址为:https://github.com/ReactiveCocoa/ReactiveCocoa# :在网上看了几 ...
- 关于Android界面编程与视图(View)组件
UI组件--------------->android.widget.* View组件------------->android.view.* 视图(View)组件 所有UI组件都是建立在 ...
- (转)fastcgi协议的简单实现
FastCgi不仅可以用于webserver与PHP的交互,也可用于任何两个应用之间的交互,PHPer用的比较多的应该就是用于两个子系统之间的交互. 比如A系统和B系统分部独立的部署在两台机器上,其之 ...
- RTP 协议
转载http://www.cnblogs.com/qingquan/archive/2011/07/28/2120440.html 概述: 实时传送协议(Real-time Transport Pro ...
- add BOM to fix UTF-8 in Excel
fputs($fp, $bom =( chr(0xEF) . chr(0xBB) . chr(0xBF) ));
- ie6下a标签的onclick事件不执行问题解决方案
<a href="javascript:void(0)" onclick="loadiframe()">点我咯</a> <scri ...