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用户发送推送通知,请注册网站推送标识符并创建网站推送证书. 对于每个网站,请注册一个网站推送标识符,用于验证通知是否来自您的服务器.然后创建一个网站推送证书以签署 ...
随机推荐
- Tree 使用方式
Traditional Ways of Tree Traversal This page contains examples of some “standard” traversal algorith ...
- /users/products.:format 这种写法的其对应解析字符写法
“products.:format" 这种写法可以有对应的下面两种路由形式 /products.json /products.xml "products.:format?" ...
- Spring + Tomcat 启动报错java.lang.ClassNotFoundException: org.apache.commons.pool.impl.GenericObjectPool
错误如下: -- ::,-[TS] INFO http-- org.springframework.beans.factory.support.DefaultListableBeanFactory - ...
- [android]-如何在向服务器发送request时附加已保存的cookie数据
[android]-如何在向服务器发送request时附加已保存的cookie数据 应用场景:在开发android基于手机端+服务器端的应用时,登陆->获取用户信息->获取授权用户相关业务 ...
- Codeforces 518D Ilya and Escalator
http://codeforces.com/problemset/problem/518/D 题意:n个人,每秒有p的概率进电梯,求t秒后电梯里人数的期望 考虑dp:f[i][j]代表第i秒有j个人的 ...
- 【温故而知新:文件操作】C#的文件读写相关
StreamReader类以及其方法ReadLine,Read,ReadToEnd的分析 首先StreamReader类的构造参数非常丰富在这里,我觉得最常用的就是StreamReader(Strea ...
- linux awk 使用
awk是linux下的一个命令,他对其他命令的输出,对文件的处理都十分强大,其实他更像一门编程语言,他可以自定义变量,有条件语句,有循环,有数组,有正则,有函数等.他读取输出,或者文件的方式是一行,一 ...
- unix c 11
多线程(thread) 操作系统支持多进程,进程内部使用多线程. 进程是 重量级的,拥有自己 独立的内存空间. 线程是 轻量级的,不需要拥有自己 独立的内存空间,线程的内存空间:1 ...
- java 实现排序
package com.cjs.sort; /** * 此类用来提供针对整数的各种排序算法 * * @author S * @version 1.0 */ public class MySort { ...
- Java配置文件Properties的读取、写入与更新操作
/** * 实现对Java配置文件Properties的读取.写入与更新操作 */ package test; import java.io.BufferedInputStream; import j ...