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. Destoon标签使用技巧十则

    Destoon标签 1.全局标签 网站名称:{$DT[sitename]}网站地址:{DT_PATH}网站LOGO: {if $MODULE[$moduleid][logo]}{DT_SKIN}ima ...

  2. jQuery验证表单格式

    工作之余整理一些工作中编写的代码,记录自己工作中的技术要点,便于自己记忆已经整合.以下是关于此jQuery验证的一些标记以及使用方法: 整个js代码都放入jquery_validate_1.1.0.j ...

  3. INI文件格式

    最近在看git命令,遇到INI文件格式,上网查了一下,把它总结一下: 程序没有任何配置文件,那么它对外是全封闭的,一旦程序需要修改一些参数必须要修改程序代码本身并重新编译,为了让程序出厂后还能根据需要 ...

  4. 磁盘IO性能监控(Linux 和 Windows)

    磁盘IO性能监控(Linux 和 Windows) 作者:终南   <li.zhongnan@hotmail.com> 磁盘的IO性能是衡量计算机总体性能的一个重要指标.Linux提供了i ...

  5. 《Programming WPF》翻译 第9章 6.我们进行到哪里了?

    原文:<Programming WPF>翻译 第9章 6.我们进行到哪里了? 只有当任何内嵌控件都没有提供你需要的底层行为时,你将要写一个自定义控件.当你写一个自定义控件,你将要使用到依赖 ...

  6. .NET 使用unity实现依赖注入

    原文地址:http://www.cnblogs.com/wujy/p/3317795.html 一:理论部分 依赖注入:这是 Ioc 模式的一种特殊情况,是一种基于改变对象的行为而不改变类的内部的接口 ...

  7. PowerShell 中的目录文件管理

    前面的一篇文章我们说了部分在PS中进行文件浏览的基本概念,说到了几个虚拟驱动器的概念.并没有深入的描述相关的命令,这里我们进一步对这一知识点进行描述. 2.1 管理当前工作路径/位置 在日常管理中经常 ...

  8. linux网址

    1. 上海爱墨电子科技有限公司 http://www.shaimo.cn/showproduct.asp?piccat_id=196&pic_id=780 2. http://lxr.free ...

  9. Calculate Number Of Islands And Lakes 解答

    Question 1 1 1 1 1 01 0 1 0 0 11 0 1 0 0 11 1 0 1 1 1 1 is earth, 0 is water. i) count the number of ...

  10. Majority Element 解答

    Solution 1 Naive way First, sort the array using Arrays.sort in Java. Than, scan once to find the ma ...