Send Notification to User

This chapter shows how to develop a program that sends a Remote Notification.

Grade 1 users are able to use user to user remote notification function from March 19 2014.
You can only use fixed phrase when using remote notification service.

Enabling Remote Notification (on Android devices)

GCM is used for Remote Notification on Android devices. GCM is automatically enabled, so no explicit setting is necessary.

Check "Enable C2DM" and click the "Apply" button. When the screen appears as shown below, you will be able to use Remote Notification.


 

Enabling Remote Notification (on iOS devices)

On iOS devices, Check "Enable APN for Sandbox" and click the "Apply" button. When the screen appears as shown below, you will be able to use Remote Notification.

It is possible to upload remote SSL certificates for both Sandbox and production environments. The uploaded files are of type ".pem".

For details on how to create .pem files, please refer to the procedure below, or reference the following file (Japanese):
file
1. Access the iOS Provisioning Portal in the iOS Dev Center.
2. From the menu on the left, click on "App IDs".
3. For an application already in development, click the Configure button of the relevant App ID. To start with a new application, click New App ID in the upper right of the screen to create a new App ID (for details of new App ID creation, please refer to "How to upload your application to iTunes Connect".
4. Check "Enable for Apple Push Notification service", near the middle of the window.
5. For the Sandbox environment, click the "Configure" button under Development Push SSL Certificate. For the production environment, click the "Configure" button under Production Push SSL Certificate. Clicking either button will launch the Apple Push Notification service SSL Certificate Assistant.
6. Launch Keychain Access, and create a CertificateSigningRequest.certSignningRequest, via the following steps:
  a. In the menu bar, click "Keychain Access" -> "Certificate Assistant" -> "Request Certificate from Certificate Authority."
  b. Input the user's email address and username, select "Save to Disk" in "Request Process", and click the "Continue" button. You can leave the Certificate Authority e-mail address blank and the checkbox for designating key pair information unchecked.
  c. Select a save file of your choice, click the "Save" button, and save "CertificateSigningRequest.certSignningRequest".
7. Return to the Apple Push Notification service SSL Certificate Assistant and click "Continue".
8. The program will switch to the Submit Certificate Signing Request screen. Click the "Select File" button and select the previously created "CertificateSigningRequest.certSignningRequest".
9. A dialog will appear displaying "Your APNs SSL Certificate has been generated". Click the "Continue" button.
10. Click the "Download" button to download the certificate. When the download is complete, click the "Done" button at the lower right. Verify that the Push SSL Certificate Status is "Enabled".
11. Double-click the downloaded certificate to add the certificate to the keychain.
12. From the "Type" item at the lower left of Keychain Access, select "Certificate", select the registered "Apple Development IOS Push Services", select "File" -> "Export" in the menu bar, and save "Personal Information Exchange File (p12)" at a location of your choice. You will need to set a password when exporting the file.
13. Enter the following command in Terminal to convert the "Personal Information Exchange File (p12)" to a .pem file:

Click the "Upload SSL Certificate for Sandbox" button to upload the .pem file that you created. The Development Push SSL Certificate will be uploaded for Sandbox, and the Production Push SSL Certificate will be uploaded for production applications. The expiration date of the certificate will be displayed when the certificate has been correctly uploaded.

Please check "Enabled" of "Push Notification SSL Certificate (Sandbox)".

Sending a Remote Notification

This chapter explains how to develop a program which sends a Remote Notification using the Remote Notification configuration which was enabled in the preceding chapter. The Remote Notification APIs for either native apps or ngCore apps are used, and thus, RESTful API endpoint Remote Notifications for applications are used. There are two modes for sending Remote Notifications: User to User and Game to User. Only the Game to User type may be used when sending Remote Notifications in the Shell App Framework.

The PHP code which sends the Remote Notification is in a file called remote_notification_send.php, as shown below. This program broadcasts to all users who have the application in question installed:

Start by verifying validity, using validator.php:

Next, "Consumer Key" and "Consumer Secret" are set. Use the values listed under "common" in the Mobage Developer Site:Next, parameters are configured for sending the RESTful API Remote Notification:

A request is issued to the RESTful API using PHP Curl:

The status code of the RESTful API is checked during the response, and error display processing is performed if a fault occurs, i.e. if the status code is not 202:

Receiving a Remote Notification

This chapter shows how to develop a program that receives a Remote Notification.

The program which receives the Remote Notification message and payload is written in JavaScript. In this instance, JavaScript code is written in the index.html start page as shown below:

After the Shell App Framework client loads the page, an onShellAppReady event is generated when a mobage.shellapp object becomes available, and the process is logged within the event handler. Under normal circumstances, the onShellAppReady event is called after onLoad.

When the mobage.shellapp.Remote Notification.getPayload function is called, the content of the payload can be obtained as a JavaScript object, which in this processing causes the content to be simply displayed with an alert function:

A link to the remote_notification_send.php which is a program on th? sending side, is also added to index.html:

This section explains how to verify operation of the programs for sending and receiving Remote Notifications which were developed in the preceding sections.

Application Re-sign (iOS only)

An iOS app file must be re-signed with a special re-sign tool in order to use the Remote Notification procedure.

Download the following tool and re-sign the app according to the example:

usage: $sh re-sign-notification.sh  <application> <mobileprovision> <identity> <appPrefix> <bundleId> <environment: development or production>

// Use the following format when using this tool for Sandbox application development:
example: $sh re-sign-notification.sh webgame.app test.mobileprovision "iPhone Developer: Dan Weeks (ABCDEF1234)" ABCDEFG my.bundle.id development
// Use the following format when using this tool for actual production applications for uploading to iTunesConnect:
example: $sh re-sign-notification.sh webgame.app test.mobileprovision "iPhone Distribution: Dan Weeks" ABCDEFG my.bundle.id production
  • Description of Command
    • <application>
      • Specify the path to the downloaded .app file.
    • <mobileprovision>
      • Specify the path to the file downloaded from the iOS Provisioning Portal with the mobileprovision extension.
    • <identity>
      • Specify the certificate alias for Distribution Certificates registered on the iOS Provisioning Portal.
    • <appPrefix>
      • Specify the Bundle Seed ID (App ID Prefix) which is automatically created when the App ID is registered on the iOS Provisioning Portal. The Description of an App ID on the iOS Provisioning Portal includes the text string "BundleSeedID"."BundleID", however, for the command only enter the "BundleSeedID" part.
    • <bundleId>
      • Specify only the "BundleID" part.
    • <environment: development or production>
      • Specify "development" for the development environment, and "production" for the production environment.

Verify on an Actual Device

Prepare two actual devices and two test accounts. Install the client application on both devices, log in to both accounts, and quit the application on one device.

Click the Send Remote Notification to All Users link on the device on which the application is running and send RemoteNotificaion.

The transmission is completed. Next, confirm the receipt of the notification.

The device which sent the notification will have the application running in the foreground, meaning that the notification has already been delivered. Click the Home button in the header to move to index.html which will allow the content of the notification to be received:

On the receiving device, the application will have been terminated and the notification will be received in the notifications bar.

Click the notification in the notifications bar to launch the application and receive the content in index.html as per the foregoing.

When the application is running in the background, the notification is received in the notifications bar and clicking the notification will bring the application back to the foreground. When the application is in the foreground, the WebView page is not loaded, and the notification cannot be received. The content of the notification can be obtained with the mobage.shellapp.Remote Notification.getPayload function either when moving to another page or reloading the current page.

Finally, click the Send Remote Notification to All Users link once more on either device to end a RemoteNotification:

Note that sending "Game to All Users" is limited to one transmission every four hours, and if exceeded a "429 Too Many Requests" error will result. While "Game to All Users" can be sent normally in another four hours, such a lag is inefficient during development. Accordingly, when developing in the Sandbox, developers may deactivate this limitation in the "Limitation" submenu in the Mobage Developer Site.

This concludes the tutorial on sending Remote Notifications.

Regarding devices that receive remote notifications

Remote notifications are sent to devices based on the following rules:

  • On logging in to Mobage, the user’s Mobage UserId and the device’s DeviceId are linked, and it becomes possible to send remote notifications to the device.
  • On logging out of Mobage, the information linking the UserId and DeviceId is deleted, and it therefore becomes impossible to send remote notifications to the device.
  • When a user logs in with the same UserId on multiple devices, remote notifications are only sent to the last device the application was used. If the user logs out from an Android device, remote notifications will no longer be sent to their Android devices. Likewise, if the user logs out from an iOS device, remote notifications will not be sent to their iOS devices.
     

    Reference Documents

    For more information on ngCore ClientAPI, check here.
    For more information on RESTful API, check here.

Regarding devices that receive remote notifications

Remote notifications are sent to devices based on the following rules:

  • On logging in to Mobage, the user’s Mobage UserId and the device’s DeviceId are linked, and it becomes possible to send remote notifications to the device.
  • On logging out of Mobage, the information linking the UserId and DeviceId is deleted, and it therefore becomes impossible to send remote notifications to the device.
  • When a user logs in with the same UserId on multiple devices, remote notifications are only sent to the last device the application was used. If the user logs out from an Android device, remote notifications will no longer be sent to their Android devices. Likewise, if the user logs out from an iOS device, remote notifications will not be sent to their iOS devices.

References

For more information about JavaScript getPayload function, please see here.

Revision History

  • 12/11/2012:
    • Initial release.

PREVIOUS

Invite Friends and Reward

NEXT

Playing Sound