EDN Admin
Well-known member
[This is the iOS version of the previously posted Walkthrough. If youve already watched the Windows 8 Edition, skip to 10 minutes 25 seconds where the actual code walkthrough starts]
In this clip Ill walk you through the basic principles of the brand-new Windows Azure Service Bus Notification Hubs in a somewhat more formal and serious fashion than in my chat with Elio.
Recapping from the other post,Service Bus Notification Hubs are an intrinsic feature of Windows Azure Service Bus and are different from other push notification services in four key areas:
After the basic intro, Im showing how to create and provision a iOS application from scratch, how to hook it up to a new Notification Hub, and send it a notification Alert using the portals and Visual Studio Express 2012 Web. (The equivalent Windows 8 walkthrough is here)
For those of you with a "TL;DW" attention span (too long; didnt watch), heres the whole extent of the code added to the stock iOS code template to enable Service Bus Notifications and that includes re-registering existing registrations at App startup. Decoration excluded its 6 functional lines including one required by iOS - admittedly, without error handling.
- (BOOL)applicationUIApplication *)application didFinishLaunchingWithOptionsNSDictionary *)launchOptions
{
NSString * connectionString =
[SBConnectionString stringWithEndpoint"https://myhub-euw-ns.servicebus.windows.net/" listenAccessSecret"... secret..."];
self.hub = [[SBNotificationHub alloc] initWithConnectionString: connectionString notificationHubPath"myhub"];
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:
UIRemoteNotificationTypeAlert|UIRemoteNotificationTypeBadge|UIRemoteNotificationTypeSound];
...
return YES;
}
- (void)applicationUIApplication *)application didRegisterForRemoteNotificationsWithDeviceTokenNSData *)deviceToken {
[self.hub refreshRegistrationsWithDeviceToken:deviceToken completion:
^(NSError *error) {
if ( error == nil )
{
[self.hub defaultRegistrationExistsWithCompletion:^(BOOL exists, NSError *error2) {
if ( error2 == nil && !exists )
{
[self.hub createDefaultRegistrationWithTags:nil completion:
^(NSError *error3) {
if ( error3 != nil) {
}
}];
}
}];
}
}];
}
The event-source code, written on the server-side for a Windows Azure Web Site in ASP.NET, is similarly terse:
var cs = ServiceBusConnectionStringBuilder.CreateUsingSharedAccessSecretWithFullAccess( "myhub-euw-ns", "...secret...");
var nh = NotificationHubClient.CreateClientFromConnectionString( cs, "myhub");
nh.SendAppleNativeNotification( AppleNotificationJsonBuilder.Create(TextBox1.Text).ToJsonString());
3 lines. Three lines. No management of device ids. No public endpoint for the phone to talk to. Service Bus does all that. It really is worth playing with.
And here are all the key links ....
View the full article
In this clip Ill walk you through the basic principles of the brand-new Windows Azure Service Bus Notification Hubs in a somewhat more formal and serious fashion than in my chat with Elio.
Recapping from the other post,Service Bus Notification Hubs are an intrinsic feature of Windows Azure Service Bus and are different from other push notification services in four key areas:
- Complete client registration management. Your backend application (if you even have one) does not need to worry at all about device-ids or channels or other particulars of push notifications and doesnt need to cooperate in management. It doesnt even have to be a web app thats publicly accessible.
- Platform independence. Service Bus Notification Hubs allow cross-platform push notifications so that iOS Alerts and Windows Live Tiles can be targeted with a single event message.
- Broadcast and tag-based Multicast - Service Bus Notification Hubs are optimized around automatic notification broadcast to many thousand devices with low latency. One message in, thousands of notifications out.
- Mass customization - Notification Hub notification templates allow for customization of notification delivery for each individual registration, allowing each instance of a client App to choose how it wants to receive events.
After the basic intro, Im showing how to create and provision a iOS application from scratch, how to hook it up to a new Notification Hub, and send it a notification Alert using the portals and Visual Studio Express 2012 Web. (The equivalent Windows 8 walkthrough is here)
For those of you with a "TL;DW" attention span (too long; didnt watch), heres the whole extent of the code added to the stock iOS code template to enable Service Bus Notifications and that includes re-registering existing registrations at App startup. Decoration excluded its 6 functional lines including one required by iOS - admittedly, without error handling.
- (BOOL)applicationUIApplication *)application didFinishLaunchingWithOptionsNSDictionary *)launchOptions
{
NSString * connectionString =
[SBConnectionString stringWithEndpoint"https://myhub-euw-ns.servicebus.windows.net/" listenAccessSecret"... secret..."];
self.hub = [[SBNotificationHub alloc] initWithConnectionString: connectionString notificationHubPath"myhub"];
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:
UIRemoteNotificationTypeAlert|UIRemoteNotificationTypeBadge|UIRemoteNotificationTypeSound];
...
return YES;
}
- (void)applicationUIApplication *)application didRegisterForRemoteNotificationsWithDeviceTokenNSData *)deviceToken {
[self.hub refreshRegistrationsWithDeviceToken:deviceToken completion:
^(NSError *error) {
if ( error == nil )
{
[self.hub defaultRegistrationExistsWithCompletion:^(BOOL exists, NSError *error2) {
if ( error2 == nil && !exists )
{
[self.hub createDefaultRegistrationWithTags:nil completion:
^(NSError *error3) {
if ( error3 != nil) {
}
}];
}
}];
}
}];
}
The event-source code, written on the server-side for a Windows Azure Web Site in ASP.NET, is similarly terse:
var cs = ServiceBusConnectionStringBuilder.CreateUsingSharedAccessSecretWithFullAccess( "myhub-euw-ns", "...secret...");
var nh = NotificationHubClient.CreateClientFromConnectionString( cs, "myhub");
nh.SendAppleNativeNotification( AppleNotificationJsonBuilder.Create(TextBox1.Text).ToJsonString());
3 lines. Three lines. No management of device ids. No public endpoint for the phone to talk to. Service Bus does all that. It really is worth playing with.
And here are all the key links ....
- Feature guide (Windows Store Apps) - http://go.microsoft.com/fwlink/?LinkID=275828
- Feature guide (iOS) - http://go.microsoft.com/fwlink/?LinkId=275829
- Fundamentals - http://go.microsoft.com/fwlink/?LinkId=277072
- Tutorial (Windows Store Apps) - http://go.microsoft.com/fwlink/?LinkId=277073
- Tutorial (iOS) - http://go.microsoft.com/fwlink/?LinkId=277074
- Windows 8 Managed Client Library - http://go.microsoft.com/fwlink/?LinkID=277160
- iOS Client Library - http://go.microsoft.com/fwlink/?LinkID=277161
- Preview client NuGet - http://nuget.org/packages/ServiceBus.Preview
View the full article