|
1 |
| -# react-native-azurenotificationhub |
| 1 | +# React Native Azure Notification Hub |
| 2 | + |
2 | 3 | React Native module to support Azure Notification Hub push notifications on Android, iOS, and Windows.
|
| 4 | + |
| 5 | +# Installation |
| 6 | + |
| 7 | +``` |
| 8 | +npm isntall react-native-azurenotificationhub |
| 9 | +``` |
| 10 | + |
| 11 | +## Set up Azure Notification Hub |
| 12 | + |
| 13 | +### Creating a new Notification Hub |
| 14 | + |
| 15 | +* Log on to the [Azure Portal](https://portal.azure.com) and create a new **Notification Hub**. |
| 16 | + |
| 17 | + |
| 18 | + |
| 19 | +* Take note of the two connection strings that are made available to you in **Settings > Access Policies**, as you will need them to handle push notifications later. |
| 20 | + |
| 21 | + |
| 22 | + |
| 23 | +## Android Installation |
| 24 | + |
| 25 | +Coming soon. |
| 26 | + |
| 27 | +## Windows Installation |
| 28 | + |
| 29 | +### Associate your app with the Windows Store |
| 30 | + |
| 31 | +* Open your Visual Studio .sln (generally ./windows/[app name].sln) file in Visual Studio 2015. |
| 32 | +* In Solution Explorer, right-click the Windows Store app project, click **Store**, and then click **Associate App with the Store...** |
| 33 | + |
| 34 | + |
| 35 | + |
| 36 | +* Follow the instructions to login, reserve an app name, associate the app with the app name, and automatically configure the required Windows Store registration in the application manifest. |
| 37 | + |
| 38 | +### Register app with Notification Hub |
| 39 | + |
| 40 | +* On the [Windows Dev Center](https://dev.windows.com/overview) page for your new app, click **Services**, click **Push notifications**, and then click **Live Services site** under **Windows Push Notification Services (WNS) and Microsoft Azure Mobile Apps**. |
| 41 | + |
| 42 | + |
| 43 | + |
| 44 | +* On the registration page for your app, make a note of the **Application Secret** password and the **Package security identifier** (SID) located in the Windows Store platform settings. |
| 45 | + |
| 46 | + |
| 47 | + |
| 48 | +* Back on the [Azure Portal](https://portal.azure.com) page for your notification hub, select **Settings > Notification Services > Windows (WNS)**. Then enter the **Application Secret** password in the Security Key field. Enter your **Package SID** value that you obtained from WNS in the previous section, and then click **Save**. |
| 49 | + |
| 50 | +### Export React Native Module from app |
| 51 | + |
| 52 | +* In Solution Explorer of your open .sln in Visual Studio 2015, right-click the Solution, click **Add > Existing Project...**. |
| 53 | + |
| 54 | + |
| 55 | + |
| 56 | +* Assuming you've already installed `react-native-azurenotificationhub` with NPM, find and select `ReactWindowsAzureNotificationHub.csproj` in `.\node_modules\react-native-azurenotificationhub\windows\ReactWindowsAzureNotificationHub`. |
| 57 | +* Right-click the Windows Store app project, click ** Add > Reference**, and check `ReactWindowsAzureNotificationHub` from **Projects > Solution**. |
| 58 | + |
| 59 | + |
| 60 | + |
| 61 | +* In **MainPage.cs** of your Windows Store app, add the the `ReactAzureNotificationHubPacakge` to your configured set of packages: |
| 62 | + |
| 63 | +```c# |
| 64 | + public override List<IReactPackage> Packages |
| 65 | + { |
| 66 | + get |
| 67 | + { |
| 68 | + new List<IReactPackage> |
| 69 | + { |
| 70 | + new MainReactPackage(), |
| 71 | + new ReactAzureNotificationHubPackage(), // Also add using ReactWindowsAzureNotificationHub; |
| 72 | + } |
| 73 | + } |
| 74 | + } |
| 75 | +``` |
| 76 | + |
| 77 | +* At this point you can register and unregister from the Azure Notification Hub instance using JavaScript as in the following example: |
| 78 | + |
| 79 | +```js |
| 80 | +const NotificationHub = require('react-native-azurenotificationhub'); |
| 81 | + |
| 82 | +class myapp extends Component { |
| 83 | + register() { |
| 84 | + NotificationHub.register({connectionString, hubName}) |
| 85 | + .catch(reason => console.warn(reason)); |
| 86 | + } |
| 87 | + |
| 88 | + unregister() { |
| 89 | + NotificationHub.unregister({connectionString, hubName}) |
| 90 | + .catch(reason => console.warn(reason)); |
| 91 | + } |
| 92 | + |
| 93 | + render() { |
| 94 | + return ( |
| 95 | + <View style={styles.container}> |
| 96 | + <TouchableOpacity onPress={this.register.bind(this)}> |
| 97 | + <View style={styles.button}> |
| 98 | + <Text style={styles.buttonText}> |
| 99 | + Register |
| 100 | + </Text> |
| 101 | + </View> |
| 102 | + </TouchableOpacity> |
| 103 | + <TouchableOpacity onPress={this.unregister.bind(this)}> |
| 104 | + <View style={styles.button}> |
| 105 | + <Text style={styles.buttonText}> |
| 106 | + Unregister |
| 107 | + </Text> |
| 108 | + </View> |
| 109 | + </TouchableOpacity> |
| 110 | + </View> |
| 111 | + ); |
| 112 | + } |
| 113 | +``` |
| 114 | +
|
| 115 | +## iOS Installation |
| 116 | +
|
| 117 | +Coming soon. |
0 commit comments