如果您已經有Azure託管的MVC應用程序從終端用戶iOS應用程序獲取並存儲設備令牌,那麼您可以在其中創建Service Bus名稱空間和通知中心,上傳APNS證書,然後您的MVC應用程序就能夠註冊令牌並使用Microsoft.ServiceBus.dll發送通知。
這裏是非常基本的代碼示例:
var notificationHubClint = NotificationHubClient.CreateClientFromConnectionString("{connection string from the portal}", "{your hub name}");
// Register device token with notification hub. Call it when you get device token from iOS app first time.
var registration = await notificationHubClint.CreateAppleNativeRegistrationAsync("{device token}",new []{"SomeUserId"});
// You can modify properties or refresh device token and then update registration
registration.DeviceToken = "{new token}";
registration.Tags.Add("{new tag}");
await notificationHubClint.UpdateRegistrationAsync(registration);
// Send notification. Call when you want to send notification to user.
await notificationHubClint.SendAppleNativeNotificationAsync("{your message}","some user id");
在這裏,我使用的標籤定位到該消息的特定用戶。如果您僅調用SendAppleNativeNotificationAsync(「{your message}」),則消息將傳遞給所有用戶。瞭解more about tags and tag expressions以使您的發送效率更高。
嗨,謝謝你有這樣的代碼嗎?我似乎無法弄清楚如何使用設備令牌與ServiceBus DLL – aherrick 2014-09-25 17:48:07
我已更新帖子。 – efimovandr 2014-09-25 20:20:07
這看起來正是我需要的,謝謝! – aherrick 2014-09-25 20:22:17