1,新建项目,在项目中添加引用,dll文件已经上传在百度网盘,点击下载

2,引入命名空间

  1. using PushSharp;
  2. using PushSharp.Android;
  3. using PushSharp.Apple;
  4. using PushSharp.Core;
  5. using PushSharp.Windows;
  6. using PushSharp.WindowsPhone;

3,初始化写入下面代码

  1. var push = new PushBroker();
  2.  
  3. //Wire up the events for all the services that the broker registers
  4. push.OnNotificationSent += NotificationSent;
  5. push.OnChannelException += ChannelException;
  6. push.OnServiceException += ServiceException;
  7. push.OnNotificationFailed += NotificationFailed;
  8. push.OnDeviceSubscriptionExpired += DeviceSubscriptionExpired;
  9. push.OnDeviceSubscriptionChanged += DeviceSubscriptionChanged;
  10. push.OnChannelCreated += ChannelCreated;
  11. push.OnChannelDestroyed += ChannelDestroyed;
  12.  
  13. //-------------------------
  14. // 苹果推送
  15. //-------------------------
  16. //Configure and start Apple APNS
  17. // IMPORTANT: 获取正确的证书
  18. var appleCert = File.ReadAllBytes(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "../../../Resources/PushSharp.Apns.Sandbox.p12"));
  19. //IMPORTANT: 正确的密码
  20. push.RegisterAppleService(new ApplePushChannelSettings(appleCert, "CERTIFICATE PASSWORD HERE")); //Extension method
  21. //开始推送
  22. push.QueueNotification(new AppleNotification()
  23. .ForDeviceToken("设备的TokenID")
  24. .WithAlert("Hello World!")
  25. .WithBadge()
  26. .WithSound("sound.caf"));
  27.  
  28. //---------------------------
  29. // ANDROID GCM 推送
  30. //---------------------------
  31. //Configure and start Android GCM
  32. //IMPORTANT: 正确的Google API's key
  33. push.RegisterGcmService(new GcmPushChannelSettings("YOUR Google API's Console API Access API KEY for Server Apps HERE"));
  34. //IMPORTANT: 手机设备注册号
  35. push.QueueNotification(new GcmNotification().ForDeviceRegistrationId("手机设备注册号")
  36. .WithJson("{\"alert\":\"Hello World!\",\"badge\":7,\"sound\":\"sound.caf\"}"));
  37.  
  38. //-----------------------------
  39. // WINDOWS PHONE 推送
  40. //-----------------------------
  41. //Configure and start Windows Phone Notifications
  42. push.RegisterWindowsPhoneService();
  43. push.QueueNotification(new WindowsPhoneToastNotification()
  44. .ForEndpointUri(new Uri("设备注册CHANNEL URI"))
  45. .ForOSVersion(WindowsPhoneDeviceOSVersion.MangoSevenPointFive)
  46. .WithBatchingInterval(BatchingInterval.Immediate)
  47. .WithNavigatePath("/MainPage.xaml")
  48. .WithText1("PushSharp")
  49. .WithText2("This is a Toast"));
  50.  
  51. Console.WriteLine("Waiting for Queue to Finish...");
  52.  
  53. //停止
  54. push.StopAllServices();
  55.  
  56. Console.WriteLine("Queue Finished, press return to exit...");
  57. Console.ReadLine();

4,实现注册方法

  1. static void DeviceSubscriptionChanged(object sender, string oldSubscriptionId, string newSubscriptionId, INotification notification)
  2. {
  3. //Currently this event will only ever happen for Android GCM
  4. Console.WriteLine("Device Registration Changed: Old-> " + oldSubscriptionId + " New-> " + newSubscriptionId + " -> " + notification);
  5. }
  6.  
  7. static void NotificationSent(object sender, INotification notification)
  8. {
  9. Console.WriteLine("Sent: " + sender + " -> " + notification);
  10. }
  11.  
  12. static void NotificationFailed(object sender, INotification notification, Exception notificationFailureException)
  13. {
  14. Console.WriteLine("Failure: " + sender + " -> " + notificationFailureException.Message + " -> " + notification);
  15. }
  16.  
  17. static void ChannelException(object sender, IPushChannel channel, Exception exception)
  18. {
  19. Console.WriteLine("Channel Exception: " + sender + " -> " + exception);
  20. }
  21.  
  22. static void ServiceException(object sender, Exception exception)
  23. {
  24. Console.WriteLine("Channel Exception: " + sender + " -> " + exception);
  25. }
  26.  
  27. static void DeviceSubscriptionExpired(object sender, string expiredDeviceSubscriptionId, DateTime timestamp, INotification notification)
  28. {
  29. Console.WriteLine("Device Subscription Expired: " + sender + " -> " + expiredDeviceSubscriptionId);
  30. }
  31.  
  32. static void ChannelDestroyed(object sender)
  33. {
  34. Console.WriteLine("Channel Destroyed for: " + sender);
  35. }
  36.  
  37. static void ChannelCreated(object sender, IPushChannel pushChannel)
  38. {
  39. Console.WriteLine("Channel Created for: " + sender);
  40. }

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分页下载

    需求.提供公共的可以按照一定条件查询出结果,并提供将查询结果全部下载功能(Excel.CSV.TXT),由于一次性查出结果放到内存会占用大量内存.需要支持分页模式查询出所有数据. 实现思路 1.在公共 ...

  2. tomcat服务器,从前端到后台到跳转

    前端页面: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <tit ...

  3. ftp和sftp

    一.ftp ftp是文件传输协议,ftp协议包括两部分,一个是ftp客户端,另一个是ftp服务器. 原理:一般情况下,当使用FTP服务的时候,我们都知道默认是21号端口,其实还有一个20号端口.FTP ...

  4. PostgreSQL扫盲教程

    在这个链接下载PostgreSQL. 安装时,请记住您给user postgres设置的初始密码,以及默认端口号5432,后面需要使用. 再安装图形化管理UI pgadmin,可以从这个链接获得. 安 ...

  5. rhythmbox插件开发笔记3:安装 makefile && schema && po

    本篇主要讲通过makefile方式来安装rhythmbox插件的相关知识. makefile 如果makefile是什么,请自行谷歌 参考了pandasunny同学的rhythmbox-baidu-m ...

  6. Codeforces Round #321 (Div. 2) C Kefa and Park(深搜)

    dfs一遍,维护当前连续遇到的喵的数量,然后剪枝,每个统计孩子数量判断是不是叶子结点. #include<bits/stdc++.h> using namespace std; ; int ...

  7. UVA 12673 Erratic Expansion 奇怪的气球膨胀 (递推)

    不难发现,每过一个小时,除了右下方的气球全都是蓝色以外,其他都和上一个小时的气球是一样的,所以是可以递推的.然后定义一类似个前缀和的东西f(k,i)表示k小时之后上面i行的红气球数.预处理出k小时的红 ...

  8. OTOH

    OTOH n 网络用语 On the Other Hand 另一方面 [例句]OTOH, pressure on the keys of a digital AFTER bottoming can b ...

  9. Java替换手机号掩码

    String tel = "18304072984"; // 括号表示组,被替换的部分$n表示第n组的内容 tel = tel.replaceAll("(\\d{3})\ ...

  10. python-判断alter是否存在

    from selenium import webdriver import time from selenium.webdriver.support.ui import WebDriverWait f ...