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 an iOS application. You 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).
@@ -70,116 +71,120 @@ In this section, you create a notification hub and configure authentication with
70
71
You have now configured your notification hub with APNS, and you have the connection strings to register your app and send push notifications.
71
72
72
73
## Connect your iOS app to Notification Hubs
74
+
73
75
1. In Xcode, create a new iOS project and select the **Single View Application** template.
74
-
76
+
75
77
![Xcode - Single View Application][8]
76
-
78
+
77
79
2. When setting the options for your new project, make sure to use the same **Product Name** and **Organization Identifier** that you used when you set the bundle identifier in the Apple Developer portal.
78
-
80
+
79
81
![Xcode - project options][11]
80
-
82
+
81
83
3. Under Project Navigator, click your project name, click the **General** tab, and find **Signing**. Make sure you select the appropriate Team for your Apple Developer account. XCode should automatically pull down the Provisioning Profile you created previously based on your bundle identifier.
82
-
84
+
83
85
If you don't see the new provisioning profile that you created in Xcode, try refreshing the profiles for your signing identity. Click **Xcode** on the menu bar, click **Preferences**, click the **Account** tab, click the **View Details** button, click your signing identity, and then click the refresh button in the bottom-right corner.
84
86
85
87
![Xcode - provisioning profile][9]
86
88
87
89
4. Select the **Capabilities** tab and make sure to enable Push Notifications
88
90
89
91
![Xcode - push capabilities][12]
90
-
92
+
91
93
5. Download the [Windows Azure Messaging Framework] and unzip the file. In Xcode, right-click your project and click the **Add Files to** option to add the **WindowsAzureMessaging.framework** folder to your Xcode project. Select **Options** and make sure **Copy items if needed** is selected, and then click **Add**.
92
94
93
95
![Unzip Azure SDK][10]
94
96
95
97
6. Add a new header file to your project named **HubInfo.h**. This file holds the constants for your notification hub. Add the following definitions and replace the string literal placeholders with your *hub name* and the *DefaultListenSharedAccessSignature* noted earlier.
96
98
97
-
```obj-c
98
-
#ifndef HubInfo_h
99
-
#define HubInfo_h
100
-
101
-
#define HUBNAME @"<Enter the name of your hub>"
102
-
#define HUBLISTENACCESS @"<Enter your DefaultListenSharedAccess connection string"
103
-
104
-
#endif/* HubInfo_h */
99
+
```objc
100
+
#ifndef HubInfo_h
101
+
#define HubInfo_h
102
+
103
+
#define HUBNAME @"<Enter the name of your hub>"
104
+
#define HUBLISTENACCESS @"<Enter your DefaultListenSharedAccess connection string"
105
+
106
+
#endif/* HubInfo_h */
105
107
```
106
-
108
+
107
109
7. Open your **AppDelegate.h** file add the following import directives:
8. In your **AppDelegate.m file**, add the following code in the **didFinishLaunchingWithOptions** method based on your version of iOS. This code registers your device handle with APNs:
This code connects to the notification hub using the connection information you specified in HubInfo.h. It then gives the device token to the notification hub so that the notification hub can send notifications.
150
152
151
153
10. In the same file, add the following method to display a **UIAlert** if the notification is received while the app is active:
## Verify that your app receives push notifications
173
+
171
174
To test push notifications on iOS, you must deploy the app to a physical iOS device. You cannot send Apple push notifications by using the iOS Simulator.
172
175
173
176
1. Run the app and verify that registration succeeds, and then press **OK**.
2. Next you send a test push notification from the [Azure portal], as described in the previous section.
179
+
180
+
2. Next you send a test push notification from the [Azure portal], as described in the previous section.
177
181
178
182
3. The push notification is sent to all devices that are registered to receive the notifications from the particular Notification Hub.
179
-
183
+
180
184
![iOS App Push Notification Receive Test][35]
181
185
182
186
## Next steps
187
+
183
188
In this simple example, you broadcasted push notifications to all your registered iOS devices. To learn how to push notifications to specific iOS devices, advance to the following tutorial:
Copy file name to clipboardExpand all lines: articles/notification-hubs/notification-hubs-ios-xplat-localized-apns-push-notification.md
+61-59Lines changed: 61 additions & 59 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -46,11 +46,13 @@ In [Use Notification Hubs to send breaking news], you built an app that used **t
46
46
47
47
At a high level, templates are a way to specify how a specific device should receive a notification. The template specifies the exact payload format by referring to properties that are part of the message sent by your app back-end. In your case, you send a locale-agnostic message containing all supported languages:
48
48
49
-
{
50
-
"News_English": "...",
51
-
"News_French": "...",
52
-
"News_Mandarin": "..."
53
-
}
49
+
```json
50
+
{
51
+
"News_English": "...",
52
+
"News_French": "...",
53
+
"News_Mandarin": "..."
54
+
}
55
+
```
54
56
55
57
Then you ensure that devices register with a template that refers to the correct property. For instance, an iOS app that wants to register for French news registers using the following syntax:
56
58
@@ -67,7 +69,7 @@ For more information on templates, see [Templates](notification-hubs-templates-c
67
69
## Prerequisites
68
70
69
71
- Complete the [Push notifications to specific iOS devices](notification-hubs-ios-xplat-segmented-apns-push-notification.md) tutorial and have the code available, because this tutorial builds directly upon that code.
70
-
- Visual Studio 2012 or later is optional.
72
+
- Visual Studio 2017 is optional.
71
73
72
74
## Update the app user interface
73
75
@@ -149,7 +151,7 @@ Then make sure to add an IBOutlet in your ViewController.h as shown in the follo
149
151
2. Now that you modified the Notifications class, you have to make sure that the ViewController makes use of the new UISegmentControl. Add the following line in the *viewDidLoad* method to make sure to show the locale that is currently selected:
Then, in your *subscribe* method, change your call to the *storeCategoriesAndSubscribe* to the following code:
@@ -187,70 +189,70 @@ Then make sure to add an IBOutlet in your ViewController.h as shown in the follo
187
189
188
190
If you don't have access to Visual Studio, or want to just test sending the localized template notifications directly from the app on the device. You can add the localized template parameters to the `SendNotificationRESTAPI` method you defined in the previous tutorial.
0 commit comments