You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In this tutorial, you use Azure Notification Hubs to push notifications to a Swift-based iOS application using the [REST API](/rest/api/notificationhubs/). You also create a blank iOS app that receives push notifications by using the [Apple Push Notification service (APNs)](https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/APNSOverview.html#//apple_ref/doc/uid/TP40008194-CH8-SW1).
26
+
In this tutorial, you use Azure Notification Hubs to push notifications to a Swift-based iOS application by using the [REST API](/rest/api/notificationhubs/). You also create a blank iOS app that receives push notifications by using the [Apple Push Notification service (APNs)](https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/APNSOverview.html#//apple_ref/doc/uid/TP40008194-CH8-SW1).
27
27
28
28
This tutorial takes you through the following steps:
29
29
@@ -33,7 +33,7 @@ This tutorial takes you through the following steps:
33
33
> * Create a provisioning profile for the app.
34
34
> * Create a notification hub.
35
35
> * Configure the notification hub with APNs information.
36
-
> * Connect your iOS app to Notification Hubs.
36
+
> * Connect your iOS app to a notification hub.
37
37
> * Test the solution.
38
38
39
39
## Prerequisites
@@ -46,20 +46,20 @@ To follow along, you need:
46
46
- A Mac running Xcode along with a valid developer certificate installed into your Keychain.
47
47
- A physical iPhone device you can run and debug with, as you can't test push notifications with the simulator.
48
48
- Your physical iPhone device registered in the [Apple Portal](https://developer.apple.com) and associated with your certificate.
49
-
- An [Azure Subscription](https://portal.azure.com) where you can create and manage resources.
49
+
- An [Azure subscription](https://portal.azure.com) where you can create and manage resources.
50
50
51
51
Even if you have no prior experience, you should be able to follow along the steps for creating this first-principles example. However, you'll benefit from familiarity with the following concepts:
52
52
53
53
- Building iOS apps with Xcode and Swift.
54
-
- Configuring an [Azure Notification Hub](notification-hubs-ios-apple-push-notification-apns-get-started.md) for iOS.
54
+
- Configuring an [Azure Notification hub](notification-hubs-ios-apple-push-notification-apns-get-started.md) for iOS.
55
55
- The [Apple Developer Portal](https://developer.apple.com) and the [Azure portal](https://portal.azure.com).
56
56
57
57
> [!NOTE]
58
58
> The notification hub will be configured to use the **Sandbox** authentication mode only. You should not use this authentication mode for production workloads.
59
59
60
60
[!INCLUDE [Notification Hubs Enable Apple Push Notifications](../../includes/notification-hubs-enable-apple-push-notifications.md)]
61
61
62
-
## Connect your iOS app to Notification Hubs
62
+
## Connect your iOS app to a notification hub
63
63
64
64
In this section, you'll build the iOS app that will connect to the notification hub.
65
65
@@ -79,18 +79,18 @@ In this section, you'll build the iOS app that will connect to the notification
79
79
80
80
1. Create a new folder called **SupportingFiles**.
81
81
82
-
1. Create a new p-list file called **devsettings.plist** in the **SupportingFiles** folder. Be sure to add this folder to your **gitignore** file so it isn't committed when working with a git repo. In a production app, you would likely be conditionally setting these secrets as part of an automated build process. However, such settings aren't covered in this walkthrough.
82
+
1. Create a new p-list file called **devsettings.plist** in the **SupportingFiles** folder. Be sure to add this folder to your **gitignore** file so it isn't committed when working with a git repo. In a production app, you would likely be conditionally setting these secrets as part of an automated build process. Such settings aren't covered in this walkthrough.
83
83
84
-
1. Update **devsettings.plist** to include the following configuration entries, using your own values from the notification hub that you provisioned:
84
+
1. Update **devsettings.plist** to include the following configuration entries by using your own values from the notification hub that you provisioned:
You can find the required values by navigating to the notification hub resource in the Azure portal. In particular, the **notificationHubName** and **notificationHubNamespace** values are in the top-right corner of the **Essentials** summary within the **Overview** page.
93
+
You can find the required values by navigating to the notification hub resource in the Azure portal. In particular, the **notificationHubName** and **notificationHubNamespace** values are in the upper-right corner of the **Essentials** summary within the **Overview** page.
To keep it simple, specify `DefaultFullSharedAccessSignature` so you can use the token to send notifications as well. However, in practice the `DefaultListenSharedAccessSignature` would be a better choice for situations where you only want to receive notifications.
105
+
To keep it simple, specify `DefaultFullSharedAccessSignature` so you can use the token to send notifications. In practice the `DefaultListenSharedAccessSignature` would be a better choice for situations where you only want to receive notifications.
106
106
107
107
1. Under **Project Navigator**, select the **Project Name** and then select the **General** tab.
108
108
@@ -249,7 +249,7 @@ In this step, you'll create a set of models to represent the [Notification Hubs
249
249
}
250
250
```
251
251
252
-
1. Add a new swift file called **TokenData.swift** to the **Models** folder. This model will be used to store a SAS token along with its expiration.
252
+
1. Add a new Swift file called **TokenData.swift** to the **Models** folder. This model will be used to store a SAS token along with its expiration.
253
253
254
254
```swift
255
255
import Foundation
@@ -283,11 +283,11 @@ The process itself involves the same six key steps:
283
283
1. Preparing the **StringToSign**, which is formatted as `'<UrlEncodedResourceUrl>\n<ExpiryEpoch>'`.
284
284
1. Computing and Base64-encoding the **Signature** by using the HMAC-SHA256 hash of the **StringToSign** value. The hash value is used with the **Key** part of the **Connection String**for the respective **Authorization Rule**.
285
285
1. Formatting the Base64 encoded **Signature** so it's percent encoded.
286
-
1. Constructing the token in the expected format using the **UrlEncodedSignature**, **ExpiryEpoch**, **KeyName**, and **UrlEncodedResourceUrl** values.
286
+
1. Constructing the token in the expected format by using the **UrlEncodedSignature**, **ExpiryEpoch**, **KeyName**, and **UrlEncodedResourceUrl** values.
287
287
288
-
See the [Azure Service Bus documentation](../service-bus-messaging/service-bus-sas.md) for a more thorough overview of shared access signature and how it's used by Azure Service Bus and Notification Hubs.
288
+
See the [Azure Service Bus documentation](../service-bus-messaging/service-bus-sas.md) for a more thorough overview of shared access signature and how Azure Service Bus and Notification Hubs use it.
289
289
290
-
For the purposes of this Swift example, you're going to use Apple's open-source **CommonCrypto** library to help with the hashing of the signature. As it's a C library, it isn't accessible in Swift out of the box. However, you can make the library available by using a bridging header.
290
+
For the purposes of this Swift example, you're going to use Apple's open-source **CommonCrypto** library to help with the hashing of the signature. As it's a C library, it isn't accessible in Swift out of the box. You can make the library available by using a bridging header.
291
291
292
292
To add and configure the bridging header:
293
293
@@ -407,10 +407,10 @@ Follow these steps to call the **installations** API:
407
407
|Key|Value|
408
408
|-------------|----------------|
409
409
| Content-Type | application/json |
410
-
| Authorization |*sasToken*|
410
+
| Authorization |<sasToken>|
411
411
| x-ms-version |2015-01|
412
412
413
-
1. Select the **Code** button that appears on the top-right under the **Save** button. The request should look similar to the following example:
413
+
1. Select the **Code** button that appears on the upper-right under the **Save** button. The request should look similar to the following example:
414
414
415
415
```html
416
416
GET /<hubName>/installations/<installationId>?api-version=2015-01 HTTP/1.1
@@ -422,9 +422,9 @@ Follow these steps to call the **installations** API:
422
422
Postman-Token:<postmanToken>
423
423
```
424
424
425
-
1. Select the **Send** button
425
+
1. Select the **Send** button.
426
426
427
-
No registration exists for the specified **installationId** at this point. However, the verification should result in a "404 Not Found" response rather than a "401 Unauthorized" response. This result should confirm that the SAS token has been accepted.
427
+
No registration exists for the specified **installationId** at this point. The verification should result in a "404 Not Found" response rather than a "401 Unauthorized" response. This result should confirm that the SAS token has been accepted.
428
428
429
429
### Implement the installation service class
430
430
@@ -534,7 +534,7 @@ class NotificationRegistrationService {
534
534
535
535
The requisite details are provided as part of initialization. Tags and templates are optionally passed into the **register** function to form part of the **Device Installation** JSON payload.
536
536
537
-
The **register** function calls the other private functions to prepare the request. Once a response is received, the completion is called and indicates whether the registration was successful.
537
+
The **register** function calls the other private functions to prepare the request. After a response is received, the completion is called and indicates whether the registration was successful.
538
538
539
539
The request endpoint is constructed by the **getBaseAddress** function. The construction uses the notification hub parameters *namespace* and *name* that were provided during initialization.
540
540
@@ -544,7 +544,7 @@ Finally, **encodeToJson** converts the respective model objects into JSON for us
544
544
545
545
### Invoke the Notification Hubs REST API
546
546
547
-
The last step is updating **AppDelegate** to use the **NotificationRegistrationService** to register with our **NotificationHub**.
547
+
The last step is updating **AppDelegate** to use **NotificationRegistrationService** to register with our **NotificationHub**.
548
548
549
549
1. Open **AppDelegate.swift** and add a class-level variable to store a reference to the **NotificationRegistrationService**:
550
550
@@ -585,11 +585,11 @@ The last step is updating **AppDelegate** to use the **NotificationRegistrationS
585
585
586
586
## Test the solution
587
587
588
-
Our app at this stage is registered with **NotificationHub** and can receive push notifications. In Xcode, stop the debugger and close the app if it's currently running. Next, check that the **Device Installation** details are as expected and that our app can now indeed receive push notifications.
588
+
Our app at this stage is registered with **NotificationHub** and can receive push notifications. In Xcode, stop the debugger and close the app if it's currently running. Next, check that the **Device Installation** details are as expected and that our app can now receive push notifications.
589
589
590
590
### Verify the device installation
591
591
592
-
You can now make the same request as you did previously using **Postman**for [verifying the SAS token](#verify-the-sas-token). Assuming that the SAS token hasn't expired, the response should now include the installation details you provided, such as the templates and tags.
592
+
You can now make the same request as you did previously by using **Postman**for [verifying the SAS token](#verify-the-sas-token). Assuming that the SAS token hasn't expired, the response should now include the installation details you provided, such as the templates and tags.
593
593
594
594
```json
595
595
{
@@ -614,17 +614,17 @@ You can now make the same request as you did previously using **Postman** for [v
614
614
615
615
### Send a test notification (Azure portal)
616
616
617
-
The quickest way to test that you can now receive notifications is to navigate to the notification hub in the Azure portal:
617
+
The quickest way to test that you can now receive notifications is to browse to the notification hub in the Azure portal:
618
618
619
-
1. In the Azure portal, navigate to the **Overview** tab on your notification hub.
619
+
1. In the Azure portal, browse to the **Overview** tab on your notification hub.
620
620
621
-
1. Select **Test Send**, which is above the **Essentials** summary in the top-left of the portal window:
621
+
1. Select **Test Send**, which is above the **Essentials** summary in the upper-left of the portal window:
622
622
623
623

624
624
625
625
1. Choose **Custom Template** from the **Platforms** list.
626
626
627
-
1. Enter "12345"for the **Send to Tag Expression**. You had previously specified this tag in our installation.
627
+
1. Enter **12345**for the **Send to Tag Expression**. You had previously specified this tag in our installation.
628
628
629
629
1. Optionally edit the **message**in the JSON payload:
630
630
@@ -634,7 +634,7 @@ The quickest way to test that you can now receive notifications is to navigate t
634
634
635
635

636
636
637
-
Assuming that the app isn't running in the foreground, you should also see a notification in the **Notification Center** on your device. Tapping on the notification should open the app and show the alert.
637
+
Assuming that the app isn't running in the foreground, you should also see a notification in the **Notification Center** on your device. Tapping the notification should open the app and show the alert.
638
638
639
639

640
640
@@ -655,7 +655,7 @@ You can send notifications via the [REST API](/rest/api/notificationhubs/) by us
@@ -667,7 +667,7 @@ You can send notifications via the [REST API](/rest/api/notificationhubs/) by us
667
667
}
668
668
```
669
669
670
-
1. Select the **Code** button, which is under the **Save** button on the top-right of the window. The request should look similar to the following example:
670
+
1. Select the **Code** button, which is under the **Save** button on the upper-right of the window. The request should look similar to the following example:
671
671
672
672
```html
673
673
POST /<hubName>/messages/?api-version=2015-01 HTTP/1.1
@@ -684,7 +684,7 @@ You can send notifications via the [REST API](/rest/api/notificationhubs/) by us
684
684
}
685
685
```
686
686
687
-
1. Select the **Send** button
687
+
1. Select the **Send** button.
688
688
689
689
You should get a success status code and receive the notification on the client device.
690
690
@@ -693,9 +693,9 @@ You now have a basic iOS Swift app connected to a notification hub via the [REST
0 commit comments