在. net平台下,推送IOS,Android,Windows Phone消息
1,新建项目,在项目中添加引用,dll文件已经上传在百度网盘,点击下载

2,引入命名空间
using PushSharp;
using PushSharp.Android;
using PushSharp.Apple;
using PushSharp.Core;
using PushSharp.Windows;
using PushSharp.WindowsPhone;
3,初始化写入下面代码
var push = new PushBroker();
//Wire up the events for all the services that the broker registers
push.OnNotificationSent += NotificationSent;
push.OnChannelException += ChannelException;
push.OnServiceException += ServiceException;
push.OnNotificationFailed += NotificationFailed;
push.OnDeviceSubscriptionExpired += DeviceSubscriptionExpired;
push.OnDeviceSubscriptionChanged += DeviceSubscriptionChanged;
push.OnChannelCreated += ChannelCreated;
push.OnChannelDestroyed += ChannelDestroyed;
//-------------------------
// 苹果推送
//-------------------------
//Configure and start Apple APNS
// IMPORTANT: 获取正确的证书
var appleCert = File.ReadAllBytes(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "../../../Resources/PushSharp.Apns.Sandbox.p12"));
//IMPORTANT: 正确的密码
push.RegisterAppleService(new ApplePushChannelSettings(appleCert, "CERTIFICATE PASSWORD HERE")); //Extension method
//开始推送
push.QueueNotification(new AppleNotification()
.ForDeviceToken("设备的TokenID")
.WithAlert("Hello World!")
.WithBadge()
.WithSound("sound.caf"));
//---------------------------
// ANDROID GCM 推送
//---------------------------
//Configure and start Android GCM
//IMPORTANT: 正确的Google API's key
push.RegisterGcmService(new GcmPushChannelSettings("YOUR Google API's Console API Access API KEY for Server Apps HERE"));
//IMPORTANT: 手机设备注册号
push.QueueNotification(new GcmNotification().ForDeviceRegistrationId("手机设备注册号")
.WithJson("{\"alert\":\"Hello World!\",\"badge\":7,\"sound\":\"sound.caf\"}"));
//-----------------------------
// WINDOWS PHONE 推送
//-----------------------------
//Configure and start Windows Phone Notifications
push.RegisterWindowsPhoneService();
push.QueueNotification(new WindowsPhoneToastNotification()
.ForEndpointUri(new Uri("设备注册CHANNEL URI"))
.ForOSVersion(WindowsPhoneDeviceOSVersion.MangoSevenPointFive)
.WithBatchingInterval(BatchingInterval.Immediate)
.WithNavigatePath("/MainPage.xaml")
.WithText1("PushSharp")
.WithText2("This is a Toast"));
Console.WriteLine("Waiting for Queue to Finish...");
//停止
push.StopAllServices();
Console.WriteLine("Queue Finished, press return to exit...");
Console.ReadLine();
4,实现注册方法
static void DeviceSubscriptionChanged(object sender, string oldSubscriptionId, string newSubscriptionId, INotification notification)
{
//Currently this event will only ever happen for Android GCM
Console.WriteLine("Device Registration Changed: Old-> " + oldSubscriptionId + " New-> " + newSubscriptionId + " -> " + notification);
} static void NotificationSent(object sender, INotification notification)
{
Console.WriteLine("Sent: " + sender + " -> " + notification);
} static void NotificationFailed(object sender, INotification notification, Exception notificationFailureException)
{
Console.WriteLine("Failure: " + sender + " -> " + notificationFailureException.Message + " -> " + notification);
} static void ChannelException(object sender, IPushChannel channel, Exception exception)
{
Console.WriteLine("Channel Exception: " + sender + " -> " + exception);
} static void ServiceException(object sender, Exception exception)
{
Console.WriteLine("Channel Exception: " + sender + " -> " + exception);
} static void DeviceSubscriptionExpired(object sender, string expiredDeviceSubscriptionId, DateTime timestamp, INotification notification)
{
Console.WriteLine("Device Subscription Expired: " + sender + " -> " + expiredDeviceSubscriptionId);
} static void ChannelDestroyed(object sender)
{
Console.WriteLine("Channel Destroyed for: " + sender);
} static void ChannelCreated(object sender, IPushChannel pushChannel)
{
Console.WriteLine("Channel Created for: " + sender);
}
5,大功告成,每一种系统都需要不同的验证信息,有完整的信息在使用本例子(比如ios证书,密码,设备tokenID等),亲自测过,正常!
6,有什么不懂的地方和我联系(shixudong3@yeah.net)
在. net平台下,推送IOS,Android,Windows Phone消息的更多相关文章
- 阿里云移动推送 ios项目添加SDK步骤
添加阿里云Pods仓库和各产品SDK Pod依赖,配置步骤如下: 1. CocoaPods集成添加阿里云Pods仓库,Podfile添加: source 'https://github.com/ali ...
- 微软云平台媒体服务实践系列 2- 使用动态封装为iOS, Android , Windows 等多平台提供视频点播(VoD)方案
文章微软云平台媒体服务实践系列 1- 使用静态封装为iOS, Android 设备实现点播(VoD)方案 介绍了如何针对少数iOS, Android 客户端的场景,出于节约成本的目的使用媒体服务的静 ...
- .net平台推送ios消息
1,ios应用程序中允许向客户推送消息 2,需要有苹果的证书以及密码(怎么获取,网上搜一下,需要交费的) 3,iphone手机一部,安装了该ios应用程序 4,.net 项目中引用PushSharp. ...
- 推送 iOS 10
1:APNs通知与应用内消息对比 极光文档上面是这么写的 后来更直接的说法是: 2:下面是介绍app不同状态下面接受到通知调用的方法: // iOS 10 Support,这个是程序在前台接受到通知是 ...
- 从微信推送看Android Service的创建和销毁
启动服务是有两组参数影响服务的状态. 1.在onStartCommand(Intent intent, int flags, int startId) 接口中返回值,例如 START_STICKY; ...
- 【转载自友盟消息推送iOS文档】在appDelegate中注册推送
1.2 基本功能集成指南 提示 请先在友盟的消息推送管理后台中创建App,获得AppKey和AppSecret 导入SDK 下载 UMessage_Sdk_All_x.x.x.zip并解压缩 导入 ...
- [置顶] 手把手教你iOS消息推送证书生成以及Push消息
iOS推送消息是许多iOS应用都具备的功能,今天在给应用加推送功能,在生成证书的过程中,发生了各种令人蛋痛的事.下面就把步骤拿出来分享下: iOS消息推送的工作机制可以简单的用下图来概括: Provi ...
- 百度云推送----iOS
前言 记录一下这几天学习的百度推送,觉得这个东西弄的还挺糟心的,好多注意的地方 正文 1.先申请一个百度开发者账号 http://push.baidu.com/fc 2.创建一个新应用,并应用配置 3 ...
- 远程推送-----iOS
前言 说一下我了解的推送 正文 APNs--------Apple Push Notification service 1 远程推送的大概流程及其原理 我们的设备联网时(无论是蜂窝联网还是Wi-Fi联 ...
随机推荐
- Vue Scroller:Vue 下拉刷新及无限加载组件
Vue Scroller Vue Scroller is a foundational component ofVonic UI. In purpose of smooth scrolling, pu ...
- MVC与Holla聊天工具
MVC 是一种设计模式, 它将应用划分为 3 个部分 : 数据( 模型). 展现层( 视图) 和用 户交互层( 控制器). 换句话说, 一个事件的发生是这样的过程 : 1. 用户和应用产生交互. 2. ...
- 【开发小结】Two Steps from Deadline
进度条可以救我也可以杀死我 # START 2018年4月17日晚我测试了11组四则运算的UI,每个exe程序生成的每一道题都有恐怖的倒计时.PSP表格清晰的记录了开发过程中消耗的时间,但是在结对作业 ...
- 微软大礼包 | 集合在线学习资源,助你秒变AI达人
编者按:人工智能的浪潮正如火如荼地袭来,未来人工智能将大有所为,人们的生活轨迹也正在技术不断向前推进的过程中逐渐改变.人工智能不是科研人员或开发人员的专属,微软希望能够将人工智能带给每个人,从开发者到 ...
- POJ 2411 Mondriaan's Dream (状压DP,骨牌覆盖,经典)
题意: 用一个2*1的骨牌来覆盖一个n*m的矩形,问有多少种方案?(1<=n,m<=11) 思路: 很经典的题目,如果n和m都是奇数,那么答案为0.同uva11270这道题. 只需要m个b ...
- [VC]获取本地程序的版本信息信息
CString CQwerApp::IS_GetAppVersion(char *AppName) { ////需要加上version.lib在link里 CString AppVersion; // ...
- AE开发关于OnMapReplaced方法的使用原理
The OnMapReplaced event is triggered whenever the IMapControl2::Map is replaced by another map, such ...
- 使用ServiceController组件控制计算机服务
实现效果: 知识运用: ServiceController组件的MachineName属性 //获取或设置服务所驻留的计算机名称 public string MachineName{get;set;} ...
- 主成分分析法(PCA)答疑
问:为什么要去均值? 1.我认为归一化的表述并不太准确,按统计的一般说法,叫标准化.数据的标准化过程是减去均值并除以标准差.而归一化仅包含除以标准差的意思或者类似做法.2.做标准化的原因是:减去均值等 ...
- Bootstrap历练实例:默认的媒体对象
Bootstrap 多媒体对象(Media Object) 本章我们将讲解 Bootstrap 中的多媒体对象(Media Object).这些抽象的对象样式用于创建各种类型的组件(比如:博客评论), ...