色尼玛亚洲综合影院,亚洲3atv精品一区二区三区,麻豆freexxxx性91精品,欧美在线91

.net平臺(tái)推送ios消息的實(shí)現(xiàn)方法

本文實(shí)例講述了.NET平臺(tái)推送ios消息的實(shí)現(xiàn)方法。分享給大家供大家參考。

具體實(shí)現(xiàn)步驟如下:

1、ios應(yīng)用程序中允許向客戶推送消息

2、需要有蘋果的證書以及密碼(怎么獲取,網(wǎng)上搜一下,需要交費(fèi)的)

3、iphone手機(jī)一部,安裝了該ios應(yīng)用程序

4、.NET 項(xiàng)目中引用PushSharp.Apple.dll,PushSharp.Core.dll(這兩個(gè)文件在網(wǎng)上搜一下,有源碼的)

5、開始寫代碼,定義全局的對(duì)象PushBroker pusher = new PushBroker();

6、注冊方法:

復(fù)制代碼 代碼如下:protected void startApp()
{
 pusher.RegisterAppleService(new ApplePushChannelSettings(File.ReadAllBytes(CertificatePath), CertificatePassword));
 pusher.OnDeviceSubscriptionChanged += pusher_OnDeviceSubscriptionChanged;
 pusher.OnDeviceSubscriptionExpired += pusher_OnDeviceSubscriptionExpired;
 pusher.OnNotificationSent += pusher_OnNotificationSent;
 pusher.OnNotificationFailed += pusher_OnNotificationFailed;

}
static void pusher_OnNotificationFailed(object sender, INotification notification, Exception error)
{
    var n = (AppleNotification)notification;
    //error.Message ...獲取推送出錯(cuò)的信息
    Log.Error("推送出錯(cuò)的信息", error);
}

static void pusher_OnNotificationSent(object sender, INotification notification)
{
    //消息推送成功后
    var n = (AppleNotification)notification;
    //n.Payload.Alert.Body  獲取推送的消息內(nèi)容...
    Log.Error("推送內(nèi)容"+n.Payload.Alert.Body);
}

static void pusher_OnDeviceSubscriptionExpired(object sender, string expiredSubscriptionId, DateTime expirationDateUtc, INotification notification)
{
    // 從數(shù)據(jù)庫刪除過期的expiredSubscriptionId
}

static void pusher_OnDeviceSubscriptionChanged(object sender, string oldSubscriptionId, string newSubscriptionId, INotification notification)
{
    // 把數(shù)據(jù)庫中的oldSubscriptionId更新為newSubscriptionId
}

startApp()方法中有兩個(gè)參數(shù):

CertificatePath:證書的路徑
CertificatePassword:密碼

7、推送代碼:
復(fù)制代碼 代碼如下:pusher.QueueNotification(new AppleNotification().ForDeviceToken(TokenID)  .WithAlert("推送的內(nèi)容").WithBadge(1).WithSound("default"));// 從數(shù)據(jù)庫或者其他等地方獲取設(shè)備的TokenID,每個(gè)iphone一個(gè)TokenID

8、準(zhǔn)備好這些以后就可以測試,本人親自測試通過,如果有什么不明白的地方歡迎留言交流!

9、如果想在Android設(shè)備上推送,項(xiàng)目要引進(jìn)PushSharp.Android.dll,代碼的話后期會(huì)為大家更新,敬請關(guān)注!

10、完整實(shí)例代碼點(diǎn)擊此處本站下載。

希望本文所述對(duì)大家的.NET程序設(shè)計(jì)有所幫助。

AspNet技術(shù).net平臺(tái)推送ios消息的實(shí)現(xiàn)方法,轉(zhuǎn)載需保留來源!

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請第一時(shí)間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: 太湖县| 呈贡县| 哈巴河县| 澳门| 淄博市| 罗甸县| 三穗县| 西平县| 隆化县| 东阳市| 巴青县| 民乐县| 吉木乃县| 汾西县| 离岛区| 阿荣旗| 沧源| 涟源市| 建平县| 兴安县| 江门市| 岫岩| 田林县| 绵竹市| 白城市| 台北市| 霍城县| 土默特左旗| 沛县| 绥棱县| 苏尼特右旗| 镶黄旗| 玉屏| 乌兰县| 金川县| 西乡县| 长泰县| 九寨沟县| 河津市| 军事| 南平市|