# Push Notification

{% hint style="warning" %}

1. You need to setup OneSignal account to support push notification (<https://onesignal.com>)&#x20;
2. Install [OneSignal Wordpress plugin](https://vi.wordpress.org/plugins/onesignal-free-web-push-notifications) to support push notification after publish a post:&#x20;
   {% endhint %}

## iOS Config

Login to Onesignal, create a new app, go to app setting Config the Apple IOS

![](https://1983211154-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LHBIhMvzFkd_uhi8KQ3%2F-LHCJCEymMO1fBF_nZ7R%2F-LHCK0nNkUm6ofexfGQ8%2FScreen%20Shot%202018-07-12%20at%202.10.21%20PM.png?alt=media\&token=3f86e73d-c5d5-46b1-82f7-0a7a7ef0ab79)

Click Config to open the popup config, follow the guide [Generate ios push Certificate](https://documentation.onesignal.com/docs/generate-an-ios-push-certificate) to generate the certificate and upload to the site.

![](https://1983211154-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LHBIhMvzFkd_uhi8KQ3%2F-LHCJCEymMO1fBF_nZ7R%2F-LHCK2jofsI3-kJM1mec%2FScreen%20Shot%202018-07-12%20at%202.10.27%20PM.png?alt=media\&token=04550275-7b30-444c-8863-01df67f2cd1d)

Select Tab **"Keys & Id**" to get the OneSignal app id, and open **MStore** project, common/config.js file and change the AppId:

```objectivec
 OneSignal: {
    appId: '85cbc2b5-4e0d-4214-9653-8054d06f4256'
  },
```

## Android config

Follow the same guide above for iOS

![](https://1983211154-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LHBIhMvzFkd_uhi8KQ3%2F-LHCJCEymMO1fBF_nZ7R%2F-LHCK4y_5u_X2T74dtxI%2FScreen%20Shot%202018-07-12%20at%202.10.34%20PM.png?alt=media\&token=6b9a4359-c41e-4bef-90af-a7f91e856d74)

Select Tab **"Keys & Id**" to get the OneSignal app id, and open **MStore** project, common/config.js file and change the AppId:

```objectivec
 OneSignal: {
    appId: '85cbc2b5-4e0d-4214-9653-8054d06f4256'
  },
```

{% hint style="info" %}
NOTE: The download package has already configure all the setting for you, but you need to replace the `APP_ID` to integrate with your OneSignal account. You can also refer [detail document here](https://github.com/geektimecoil/react-native-onesignal) for setting up.
{% endhint %}

## Install Wordpress plugin

Go to Configuration and fill in the APP ID, REST API Key, and your subdomain.

![](https://1983211154-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LHBIhMvzFkd_uhi8KQ3%2F-LHCJCEymMO1fBF_nZ7R%2F-LHCK7-dFvOSx6xCfYyA%2FScreen%20Shot%202018-07-12%20at%202.10.39%20PM.png?alt=media\&token=387ffb1e-f14b-473f-bb22-f706e227dec6)

The default setting for the plugin **"Automatically send a push notification when I create a post from the WordPress editor"** is turn on, it's mean whenever you publish the post item, it will send notification auto to your user mobiles.

{% hint style="info" %}
Notes: when testing the app with push notification, you may could not open the post directly when receiving the message, instead of opening the Webview from the app. To fix this issues, please update the **functions.php** file, this file is also discussed at the [Basic app setting](https://inspireui.gitbook.io/beonews/basic-app-setting) topic (the comment section):
{% endhint %}

```php
function onesignal_send_notification_filter($fields, $new_status, $old_status, $post)
{
    $fields['isAndroid'] = true;
    $fields['isIos'] = true;
    $fields['isAnyWeb'] = false;
    $fields['isChrome'] = false;
    $fields['data'] = array(
        "id" => $post->ID,
    );
    /* Unset the URL to prevent opening the browser when the notification is clicked */
    unset($fields['url']);
    return $fields;
}
add_filter('onesignal_send_notification', 'onesignal_send_notification_filter', 10, 4);
```

{% hint style="info" %}
You can also send the push notification manually through the OneSignal admin.
{% endhint %}
