c#关于iOS推送
来源:互联网 发布:记事本编程是什么语言 编辑:程序博客网 时间:2024/05/17 07:02
这个网上已经有比较好的技术了,可以下载别人的代码,稍微改动即可。
我用的是JdSoft.Apns.Notifications.dll 源码已上传
关于遇见的问题
1、Notification Failed to be Queued!
这个问题是由于源码中System.Security.Authentication.SslProtocols.Ssl3造成的
将其修改为System.Security.Authentication.SslProtocols.Default即可
如果找不到在哪,就全局搜索下
(或者可以看看这个文件中有没 NotificationChannel.cs)
2、关于频繁链接apns是否会被禁掉,这个的应该是会会禁掉的,但是此源码中已经有封装了
但是为了保险又用单例做了一遍`
class NotificationServiceManager
{
private static NotificationService service = null;
private static object objLock = new object();
private bool Sandbox;
private string FileName;
private string FilePwd;
public NotificationServiceManager(bool sandbox, string token, string fileName, string filePwd)
{
Sandbox = sandbox;
FileName = fileName;
FilePwd = filePwd;
}
public NotificationService Service { get { if (service == null) { lock (objLock) { if (service != null && service.Connections > 0) return service; service = CreateService(); return service; } } return service; } } private NotificationService CreateService() { service = new NotificationService(Sandbox, FileName, FilePwd, 1); service.SendRetries = 5; //5 retries before generating notificationfailed event service.ReconnectDelay = 1000; //5 seconds service.Error += new NotificationService.OnError(service_Error); service.NotificationTooLong += new NotificationService.OnNotificationTooLong(service_NotificationTooLong); service.BadDeviceToken += new NotificationService.OnBadDeviceToken(service_BadDeviceToken); service.NotificationFailed += new NotificationService.OnNotificationFailed(service_NotificationFailed); service.NotificationSuccess += new NotificationService.OnNotificationSuccess(service_NotificationSuccess); service.Connecting += new NotificationService.OnConnecting(service_Connecting); service.Connected += new NotificationService.OnConnected(service_Connected); service.Disconnected += new NotificationService.OnDisconnected(service_Disconnected); return service; }}`
关于源码,我调试了一下是这样走的
1、Notification.cs有参构造函数,其中对于NotificationPayload、NotificationAlert进行相关处理,
之后 是 NotificationService.cs 中QueueNotification() 经过层层调用到
这是一个过程,加入到了线程队列
2、创建NotificationService对象时用到
public NotificationService( string host, int port, byte[] p12FileBytes, string p12FilePassword, int connections )
{
this.SendRetries = 1;
closing = false;
disposing = false;
Host = host;
Port = port;
P12FileBytes = p12FileBytes;
P12FilePassword = p12FilePassword;
DistributionType = NotificationServiceDistributionType.Sequential;
Connections = connections;
}
在Connections属性中创建NotificationConnection对象,创建Connection对象时,创建了NotificationChannel对证书什么的验证,并且执行了start(),在start()中进行了线程的执行workerMethod(),
apnsChannel.EnsureConnection();
apnsChannel.Send(notification);
apnsStream.Write(notification.ToBytes());
- c#关于iOS推送
- 关于ios 推送问题解决
- 关于ios注册推送
- 关于iOS的推送
- 关于iOS推送原理
- 关于ios推送的教程
- 关于IOS推送的新发现
- iOS 【关于推送如何选择】
- iOS 关于信鸽推送点击推送通知的处理
- iOS 关于推送点击推送通知的处理
- ios 关于推送发布的一些流程
- 关于ios 推送功能的终极解决
- 关于ios 推送功能的终极解决
- Ios关于推送消息的处理
- 关于ios 推送功能的终极解决
- ios 关于推送发布的一些流程
- iOS-关于苹果的推送通知
- ios 关于推送发布的一些流程
- 200. Number of Islands
- DOM编程初探
- Codeforces 508C Anya and Ghosts【贪心】
- 根据色值判断是否为黑色
- 安卓图片异步加载开源库:Universal Image Loader
- c#关于iOS推送
- 信息系统集成专业技术知识(1)
- 一个最简单的php上传图片示例
- py-faster-rcnn + cpu安装及训练自己的数据集
- 查询mysql数据库结构sql
- HelloChart折线图属性及方法
- 浅谈iOS中MVVM的架构设计与团队协作
- 3GPP LTE物理层中的Uplink resource grid和Downlink Synchronization signals
- Linux离线安装pip-8.1.2+ssh+Vim7.4