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开源框架发送推送的更多相关文章

  1. 转:向IOS设备发送推送通知

    背景 SMS 和 MMS 消息是由无线运营商通过设备的电话号码向特定设备提供的.实现 SMS/MMS 的服务器端应用程序的开发人员必须费大量精力才能与现有的封闭电信基础架构进行交互(其中包括获取电话号 ...

  2. Android、iOS和Windows Phone中的推送技术

    推送并不是什么新技术,这种技术在互联网时代就已经很流行了.只是随着进入移动互联网时代,推送技术显得更加重要.因为在智能手机中,推送从某种程度上,可以取代使用多年的短信,而且与短信相比,还可以向用户展示 ...

  3. iOS超全开源框架、项目和学习资料汇总--数据库、缓存处理、图像浏览、摄像照相视频音频篇

    iOS超全开源框架.项目和学习资料汇总--数据库.缓存处理.图像浏览.摄像照相视频音频篇 感谢:Ming_en_long 的分享 大神超赞的集合,http://www.jianshu.com/p/f3 ...

  4. iOS直播-基于RTMP的视频推送

    iOS直播-基于RTMP的视频推送 所谓的视频推送就是把摄像头和麦克风捕获到视频和音频推送到直播服务器上.我们这里使用推送协议是RTMP协议. 扩展:腾讯直播平台,阿里直播平台,百度直播平台提供均为R ...

  5. 李洪强iOS经典面试题154- 通知与推送

    李洪强iOS经典面试题154- 通知与推送   通知与推送 本地通知和远程推送通知对基本概念和用法? image 本地通知和远程推送通知都可以向不在前台运行的应用发送消息,这种消息既可能是即将发生的事 ...

  6. iOS超全开源框架、项目和学习资料汇总(5)AppleWatch、经典博客、三方开源总结篇

    完整项目 v2ex – v2ex 的客户端,新闻.论坛.apps-ios-wikipedia – apps-ios-wikipedia 客户端.jetstream-ios – 一款 Uber 的 MV ...

  7. 【转】iOS超全开源框架、项目和学习资料汇总

    iOS超全开源框架.项目和学习资料汇总(1)UI篇iOS超全开源框架.项目和学习资料汇总(2)动画篇iOS超全开源框架.项目和学习资料汇总(3)网络和Model篇iOS超全开源框架.项目和学习资料汇总 ...

  8. iOS打包后收不到推送信息

    今天遇到的一个特别神奇的问题: 应用在测试环境下打的包收不到推送了,打包之后都没有推送,但是我真机测试又是可以收到推送消息的.经过好久才找到原因,感觉很坑.这里记录一下问题: 1.由于我的推送第三方使 ...

  9. [Apple开发者帐户帮助]六、配置应用服务(5.3)推送通知(APN):从您的Web服务器发送推送通知

    要使用APN从Web服务器向macOS用户发送推送通知,请注册网站推送标识符并创建网站推送证书. 对于每个网站,请注册一个网站推送标识符,用于验证通知是否来自您的服务器.然后创建一个网站推送证书以签署 ...

随机推荐

  1. PHP原始的数据库操作

    <?php    //这是一个工具类;作用是完成对数据库的操作;    class SqlHelper{        public $conn;        public $dbname=& ...

  2. uva201 Squares

     Squares  A children's board game consists of a square array of dots that contains lines connecting ...

  3. 提交 应用ID 证书

    https://developer.apple.com/account/ios/profile/profileCreate.action?formID=960914622

  4. php平台移植windows和linux

    2015/1/14 今天项目中遇到一个问题,在本地运行没有问题,挂到服务器上,就运行错误.过程中比较粗心,知道导致这样的原因,居然小时漏掉了一些细节. 比如,在php中通过声明__autoload() ...

  5. KEIL里 Volatile的用法

    volatile用于防止相关变量被优化. 例如对外部寄存器的读写.对有些外部设备的寄存器来说,读写操作可能都会引发一定硬件操作,但是如果不加volatile,编译器会把这些寄存器作为普通变量处理,例如 ...

  6. 【转】android TV CTS 4.0.3_r1测试

    原文网址:http://blog.sina.com.cn/s/blog_539ad34301012764.html 做CTS测试已经一月有余,经过不断的摸索,现总结经验,与大家分享. 一.Downlo ...

  7. bzoj3721 [PA2014 Final] Bazarek

    Description 有n件商品,选出其中的k个,要求它们的总价为奇数,求最大可能的总价. Input 第一行一个整数n(1<=n<=1000000),表示商品数量.接下来一行有n个整数 ...

  8. 关于链表的一些重要操作(Important operations on a Linked List)

    上篇博文中讨论了链表的一些基本操作: 链表的基本操作(Basic Operations on a Linked List) 然而,为创建一个多功能的链表,在深度学习之前我们还需要了解更多的链表操作. ...

  9. hadoop深入研究:(十六)——Avro序列化与反序列化

    转载请写明来源地址:http://blog.csdn.net/lastsweetop/article/details/9773233 所有源码在github上,https://github.com/l ...

  10. Unity 白猫操作小实例

    最近师兄找我说白猫的操作如何做,  0.0 结果白猫没有android的客户端玩不了,看了下视频介绍就简单做了下 效果图:   核心代码: using UnityEngine; using Syste ...