国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > iOS > 正文

在. net平臺下,推送IOS,Android,Windows Phone消息

2019-11-17 03:17:14
字體:
來源:轉載
供稿:網友

在. 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(7)                                       .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)


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 卓资县| 宝鸡市| 陈巴尔虎旗| 丁青县| 岳阳市| 鄂温| 屯昌县| 隆子县| 东乌珠穆沁旗| 锡林郭勒盟| 仙居县| 华亭县| 平果县| 新营市| 南靖县| 高陵县| 乌审旗| 闽侯县| 随州市| 乐昌市| 荣昌县| 大荔县| 赞皇县| 三穗县| 宁城县| 达州市| 宁陵县| 北安市| 股票| 金塔县| 大丰市| 富平县| 瓦房店市| 富源县| 盘锦市| 万载县| 渝北区| 云浮市| 宜黄县| 酉阳| 彝良县|