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:
0 commit comments