国产探花免费观看_亚洲丰满少妇自慰呻吟_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)


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 金沙县| 和田县| 苍溪县| 青神县| 亳州市| 托里县| 阿拉善盟| 昌都县| 墨脱县| 台北县| 福海县| 镇远县| 盐津县| 防城港市| 夏津县| 顺义区| 连州市| 铁岭县| 英山县| 河西区| 陈巴尔虎旗| 阳曲县| 色达县| 商洛市| 象山县| 中牟县| 巴塘县| 兰溪市| 兰西县| 肇东市| 辽宁省| 广丰县| 任丘市| 达尔| 烟台市| 涟源市| 雷波县| 通城县| 衡东县| 东至县| 民丰县|