程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> C# >> C#入門知識 >> .net平台推送ios消息,.net平台ios消息

.net平台推送ios消息,.net平台ios消息

編輯:C#入門知識

.net平台推送ios消息,.net平台ios消息


1,ios應用程序中允許向客戶推送消息

2,需要有蘋果的證書以及密碼(怎麼獲取,網上搜一下,需要交費的)

3,iphone手機一部,安裝了該ios應用程序

4,.net 項目中引用PushSharp.Apple.dll,PushSharp.Core.dll(這兩個文件在網上搜一下,有源碼的)

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

6,注冊方法

復制代碼
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 ...獲取推送出錯的信息
            Log.Error("推送出錯的信息", error);
        }

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

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

        static void pusher_OnDeviceSubscriptionChanged(object sender, string oldSubscriptionId, string newSubscriptionId, INotification notification)
        {
            // 把數據庫中的oldSubscriptionId更新為newSubscriptionId
        }
復制代碼

startApp()方法中有兩個參數,

CertificatePath:證書的路徑
CertificatePassword:密碼

7,推送代碼

pusher.QueueNotification(new AppleNotification().ForDeviceToken(TokenID)  .WithAlert("推送的內容").WithBadge(1).WithSound("default"));// 從數據庫或者其他等地方獲取設備的TokenID,每個iphone一個TokenID

8,准備好這些以後就可以測試,本人親自測試通過,如果有什麼不明白的地方留言溝通,希望對大家有幫助!

9,如果想在Android設備上推送,項目要引進PushSharp.Android.dll,代碼的話後期為大家更新,敬請關注你!

10,源碼地址:http://pan.baidu.com/s/1pJoD8IR


怎實現net平台推送IOS信息 各路指教

資料來源於網上
1,ios應用程序中允許向客戶推送消息

2,需要有蘋果的證書以及密碼(怎麼獲取,網上搜一下,需要交費的)

3,iphone手機一部,安裝了該ios應用程序

4,.net 項目中引用PushSharp.Apple.dll,PushSharp.Core.dll(這兩個文件在網上搜一下,有源碼的)

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

6,注冊方法

復制代碼

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 ...獲取推送出錯的信息

Log.Error("推送出錯的信息", error);

}

static void pusher_OnNotificationSent(object sender, INotification
notification)

{

//消息推送成功後

var n = (AppleNotification)notification;

//n.Payload.Alert.Body 獲取推送的消息內容...

Log.Error("推送內容"+n.Payload.Alert.Body);

}

static void pusher_OnDeviceSubscriptionExpired(object sender,
string expiredSubscriptionId, DateTime expirationDateUtc, INotification
notification)

{

......余下全文>>
 

NET推送做IOS推送的時出現 "調用 SSPI 失敗,參見內部異常"

斷點,看看Exception的InnerException裡面顯示的是啥
 

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved