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消息的更多相关文章

  1. 阿里云移动推送 ios项目添加SDK步骤

    添加阿里云Pods仓库和各产品SDK Pod依赖,配置步骤如下: 1. CocoaPods集成添加阿里云Pods仓库,Podfile添加: source 'https://github.com/ali ...

  2. 微软云平台媒体服务实践系列 2- 使用动态封装为iOS, Android , Windows 等多平台提供视频点播(VoD)方案

    文章微软云平台媒体服务实践系列 1- 使用静态封装为iOS, Android 设备实现点播(VoD)方案  介绍了如何针对少数iOS, Android 客户端的场景,出于节约成本的目的使用媒体服务的静 ...

  3. .net平台推送ios消息

    1,ios应用程序中允许向客户推送消息 2,需要有苹果的证书以及密码(怎么获取,网上搜一下,需要交费的) 3,iphone手机一部,安装了该ios应用程序 4,.net 项目中引用PushSharp. ...

  4. 推送 iOS 10

    1:APNs通知与应用内消息对比 极光文档上面是这么写的 后来更直接的说法是: 2:下面是介绍app不同状态下面接受到通知调用的方法: // iOS 10 Support,这个是程序在前台接受到通知是 ...

  5. 从微信推送看Android Service的创建和销毁

    启动服务是有两组参数影响服务的状态. 1.在onStartCommand(Intent intent, int flags, int startId) 接口中返回值,例如 START_STICKY;  ...

  6. 【转载自友盟消息推送iOS文档】在appDelegate中注册推送

    1.2   基本功能集成指南 提示 请先在友盟的消息推送管理后台中创建App,获得AppKey和AppSecret 导入SDK 下载 UMessage_Sdk_All_x.x.x.zip并解压缩 导入 ...

  7. [置顶] 手把手教你iOS消息推送证书生成以及Push消息

    iOS推送消息是许多iOS应用都具备的功能,今天在给应用加推送功能,在生成证书的过程中,发生了各种令人蛋痛的事.下面就把步骤拿出来分享下: iOS消息推送的工作机制可以简单的用下图来概括: Provi ...

  8. 百度云推送----iOS

    前言 记录一下这几天学习的百度推送,觉得这个东西弄的还挺糟心的,好多注意的地方 正文 1.先申请一个百度开发者账号 http://push.baidu.com/fc 2.创建一个新应用,并应用配置 3 ...

  9. 远程推送-----iOS

    前言 说一下我了解的推送 正文 APNs--------Apple Push Notification service 1 远程推送的大概流程及其原理 我们的设备联网时(无论是蜂窝联网还是Wi-Fi联 ...

随机推荐

  1. 【Java】 jar解压与压缩

    jar解压与压缩 命令格式:jar {c t x u f }[ v m e 0 M i ][-C 目录]文件名 # 解压,到当前目录 jar -xvf source.jar # 打包,不进行压缩 ja ...

  2. Centos 7 搭建git服务器及使用gitolite控制权限

    一.安装git yum install git git --version #查看git版本 二.升级git(可选,如果之前已经安装git,需要升级git到最新版本) git clone https: ...

  3. 一个SQL server的事务存储

    -- ============================================= -- Author: Evan -- Create date: 2018年6月14日 16点27分 - ...

  4. 网站安全webshell扫描

    做个记录,使用Detector进行php网站webshell扫描 开源项目托管地址:https://github.com/emposha/PHP-Shell-Detector安装使用都很简单

  5. 拷贝文件至U盘——提示:对于目标系统文件过大

    一.问题描述: 在制作U盘启动工具的时候,通常制作出的U盘文件系统是FAT32,但是当需要拷贝进去的系统文件大小超过4GB时,就会提示上述问题 二.解决办法: 1.格式化U盘,在格式化界面“文件系统” ...

  6. java面试题(杨晓峰)---第五讲String、StringBuffer、StringBuilder有什么区别?

    线程 字符 操作频繁度 1 String (1)String的创建机制 由于String在java世界中使用过于频繁,java为了避免在一个系统中产生大量重复的String对象,引入了字符串常量池,其 ...

  7. Js笔记-第11课

    // 第11课         作用域精解     运行期上下文,当函数执行时,会创建一个成为执行期上下文的内部对象.一个执行期上下文定义了一个函数执行时的环境,函数每次执行时对应的执行期上下文都是独 ...

  8. tcp 高性能服务, netty,mqtt

    1. io 线程不要有比较长的服务. 全部异步化. [1] netty 权威指南上只是说业务复杂时派发到业务线程池种. 共用的线程池最好都轻量. 多层线程池后, 下层的可以进行隔离. 这个是 mqtt ...

  9. jq封装插件,简单dome

    (function($) { $.fn.extend({ bold: function() { this.css({ fontWeight: "bold", color: 'red ...

  10. vuePress的使用

    今天来玩一玩vuePress的使用,用markdown来编辑一个页面网站,这里谈论到了简单使用,细节可以去官网上去查看 开始安装 项目依赖 // package.json { "name&q ...