Skip to content

Commit b14495d

Browse files
committed
update xamarin ios push to user tutorial
1 parent 09b3e86 commit b14495d

3 files changed

+42
-14
lines changed

articles/app-service-mobile-dotnet-backend-ios-push-notifications-to-users-preview.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<properties
2-
pageTitle="Send x-plat notifications to a specific user with iOS Configuration"
2+
pageTitle="Send x-plat notifications to a specific user with iOS client"
33
description="Learn how to send push notifications to all devices of a specific user."
44
services="app-service\mobile"
55
documentationCenter="ios"
@@ -56,6 +56,7 @@ Before you start this tutorial, you must have already completed these App Servic
5656
@"testNotificationTemplate": @{ @"body" : @{ @"aps" : @{ @"alert": @"$(message)" } } }
5757
};
5858

59+
// register with templates
5960
[client.push registerDeviceToken:deviceToken template:templates completion:^(NSError *error) {
6061
if (error != nil) {
6162
NSLog(@"Error registering for notifications: %@", error);

articles/app-service-mobile-dotnet-backend-windows-store-dotnet-push-notifications-to-users-preview.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<properties
2-
pageTitle="Send x-plat notifications to a specific user with Windows Store Configuration"
2+
pageTitle="Send x-plat notifications to a specific user with Windows Store client"
33
description="Learn how to send push notifications to all devices of a specific user."
44
services="app-service\mobile"
55
documentationCenter="windows"

articles/app-service-mobile-dotnet-backend-xamarin-ios-push-notifications-to-user-preview.md

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<properties
2-
pageTitle="Send push notifications to a specific user with Xamarin iOS Configuration"
2+
pageTitle="Send push notifications to a specific user with Xamarin iOS client"
33
description="Learn how to send push notifications to all devices of a user"
44
services="app-service\mobile"
55
documentationCenter="windows"
@@ -20,7 +20,9 @@
2020

2121
[AZURE.INCLUDE [app-service-mobile-selector-push-users-preview](../includes/app-service-mobile-selector-push-users-preview.md)]
2222

23-
This topic shows you how to send notifications to all registered devices of a specific user from your mobile backend.
23+
This topic shows you how to send notifications to all registered devices of a specific user from your mobile backend. It introduced the concept of [templates], which gives client applications the freedom of specifying payload formats and variable placeholders at registration. Send then hits every platform with these placeholders, enabling cross-platform notifications.
24+
25+
> [AZURE.NOTE] To get push working with cross-platform clients, you will need to complete this tutorial for each platform you would like to enable. You will only need to do the [mobile backend update](#backend) once for clients that share the same mobile backend.
2426
2527
##Prerequisites
2628

@@ -32,18 +34,42 @@ Before you start this tutorial, you must have already completed these App Servic
3234

3335
##<a name="client"></a>Update your client to register for templates to handle cross-platform pushes
3436

35-
1. In **App.xaml.cs**, replace the **InitNotificationsAsync** method with the following:
37+
1. Move the APNs registration snippets from **FinishedLaunching** in **AppDelegate.cs** to the **RefreshAsync** Task definition in **QSTodoListViewController.cs**. The registrations should happen after authentication completes.
3638

37-
private async void InitNotificationsAsync()
38-
{
39-
var channel = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync();
39+
...
40+
if (todoService.User == null) {
41+
await QSTodoService.DefaultService.Authenticate (this);
42+
if (todoService.User == null) {
43+
Console.WriteLine ("couldn't login!!");
44+
return;
45+
}
4046

41-
string apnsTemplatesJson = '{\"simpleNotification\":{body: "{\"aps\":{\"alert\":\"'+ $message +'\"}}';
47+
// registers for push for iOS8
48+
var settings = UIUserNotificationSettings.GetSettingsForTypes (
49+
UIUserNotificationType.Alert
50+
| UIUserNotificationType.Badge
51+
| UIUserNotificationType.Sound,
52+
new NSSet ());
4253

43-
JObject apnsTemplates = JObject.Parse(apnsTemplatesJson);
44-
45-
var result = MobileService.GetPush().RegisterAsync(channel.Uri, apnsTemplates);
54+
UIApplication.SharedApplication.RegisterUserNotificationSettings (settings);
55+
UIApplication.SharedApplication.RegisterForRemoteNotifications ();
4656
}
57+
...
58+
59+
2. In **AppDelegate.cs**, replace the **RegisterAsync** call in **RegisteredForRemoteNotifications** with the following to work with templates:
60+
61+
// delete await push.RegisterAsync (deviceToken);
62+
63+
var notificationTemplate = "{\"aps\": {\"alert\":\"$(message)\"}}";
64+
65+
JObject templateBody = new JObject();
66+
templateBody["body"] = notificationTemplate;
67+
68+
JObject templates = new JObject();
69+
templates["testApnsTemplate"] = templateBody;
70+
71+
// register with templates
72+
await push.RegisterAsync (deviceToken, templates);
4773

4874
##<a name="backend"></a>Update your service backend to send notifications to a specific user
4975

@@ -68,7 +94,7 @@ Before you start this tutorial, you must have already completed these App Servic
6894

6995
try
7096
{
71-
await Hub.Push.SendTemplateNotificationAsync(notification, userTag);
97+
await Hub.Push.SendTemplateNotificationAsync(notification, userTag);
7298
}
7399
catch (System.Exception ex)
74100
{
@@ -83,4 +109,5 @@ Re-publish your mobile backend project and run any of the client apps you have s
83109

84110
<!-- URLs. -->
85111
[Get started with authentication]: ../articles/app-service-mobile-dotnet-backend-xamarin-ios-get-started-users-preview/
86-
[Get started with push notifications]: ../articles/app-service-mobile-dotnet-backend-xamarin-ios-get-started-push-preview/
112+
[Get started with push notifications]: ../articles/app-service-mobile-dotnet-backend-xamarin-ios-get-started-push-preview/
113+
[templates]: https://msdn.microsoft.com/en-us/library/dn530748.aspx

0 commit comments

Comments
 (0)