Skip to Content

Enable Push Notifications in the MDK Public Store Client

test
0 %
Enable Push Notifications in the MDK Public Store Client
Details

Enable Push Notifications in the MDK Public Store Client

November 3, 2020
Created by
November 22, 2019
Use the SAP Cloud Platform Mobile Services to enable push notifications in the MDK public store client.

You will learn

  • How to use MDK push register action
  • How to use predefined push configuration for the public store version of SAP Mobile Services client (MDK client)
  • How to send push notification to an MDK app

Prerequisites

You may clone an existing metadata project from GitHub repository and start directly with step 4 in this tutorial.


MDK
Step 1: Define push notification settings in app configuration
  1. Open the SAP Cloud Platform Mobile Services cockpit, click Mobile Push Notification feature.

    MDK

    You can add Mobile Push Notification feature by clicking on + icon in case feature is not already assigned to the application.

  2. Select SAP Mobile Services Client under Predefined for option, click Save.

    MDK

    Predefined push is supported only for the MDK (SAP Mobile Services client) public store client.

    If you want to enable push notification in your custom MDK client then follow this tutorial.

Which option is not available under Predefined for dropdown?
×
Step 2: Create a new MDK project in SAP Business Application Studio
  1. Launch the Dev space in SAP Business Application Studio.

  2. Navigate to File menu → click New Project from Template.

    MDK
  3. Select MDK Project and click Next.

    MDK
  4. In Basic Information step, select or provide the below information and click Next:

    Field Value
    MDK template type Select Empty from the dropdown
    Your project name MDK_Push
    Your application name <default name is same as project name, you can provide any name of your choice>
    MDK

    More details on MDK template is available in help documentation.

    If you see Cloud foundry token expired, continue without mobile services connection? message, then set the Cloud Foundry environment again by clicking at bottom left corner of your status bar to initiate a valid session and repeat above steps.

  5. After clicking Next, the wizard will generate your MDK Application based on your selections. You should now see the MDK_Push project in the project explorer. As you have already opened the workspace, there is no need to open the generated project in a new workspace. Ignore the pop-up or click the cross icon to hide the window.

    MDK
Log on to answer question
Step 3: Create MDK actions to register for push notifications

In this step, you will create the following actions:

  • Push Notification Register action: this will register the device with SAP Cloud Platform Mobile Services for push notification.

  • Message actions: these will display a message if Push Notification Register action has succeeded or failed.

  1. Create a Push Notification Register action.

    Right-click the Actions folder | MDK: New Action | choose MDK Other Actions in Category | click Push Notification Register Action | Next.

    MDK

    Provide the below information:

    Property Value
    Action Name PushRegister
    MDK

    More details on Push Notification Action is available in help documentation.

    Click Next and then Finish on the confirmation step.

  2. Define a success message if the Push Register Notification action is succeeded.

    Right-click the Actions folder | MDK: New Action | choose MDK Message Actions in Category | click Message Action | Next.

    MDK

    Provide the below information:

    Property Value
    Action Name PushRegisterSuccessMessage
    Type Select Message from the dropdown
    Message Push Notification registered
    Title Success
    OKCaption OK
    OnOK --None--
    CancelCaption leave it blank
    OnCancel --None--
    MDK

    Click Next and then Finish on the confirmation step.

  3. Define a failure message if the Push Register Notification action is failed.

    Right-click the Actions folder | MDK: New Action | choose MDK Message Actions in Category | click Message Action | Next.

    MDK

    Provide the below information:

    Property Value
    Action Name PushRegisterFailureMessage
    Type Select Message from the dropdown
    Message Push Notification didn't register
    Title Failure
    OKCaption OK
    OnOK --None--
    CancelCaption leave it blank
    OnCancel --None--
    MDK

    Click Next and then Finish on the confirmation step.

  4. Define Success and Failure actions for PushRegister.action.

    In the action editor for the new action, expand the Common Action Properties and provide the below information:

    Property Value
    Success Action Select PushRegisterSuccessMessage.action from the dropdown
    Failure Action Select PushRegisterFailureMessage.action from the dropdown

    When PushRegister.action gets executed successfully then PushRegisterSuccessMessage.action will be triggered or if PushRegister.action fails then PushRegisterFailureMessage.action will be triggered.

    MDK
Log on to answer question
Step 4: Call the push register action

In the step, you will set and call the Push Register Notification action when app is updated with the new metadata.

It is up to developers how they want to call a Push Register Notification action.

Double-click Application.app file, select the PushRegister.action for the OnDidUpdate event.

MDK
Log on to answer question
Step 5: Deploy and activate application

So far, you have learned how to build an MDK application in the SAP Business Application Studio editor. Now, we deploy this application definition to Mobile Services.

  1. Right-click Application.app and select MDK: Deploy.

    MDK
  2. Select deploy target as Mobile Services.

    MDK
  3. Select the application from Mobile Services.

    MDK

    You should see Deploy succeeded message.

    MDK
Log on to answer question
Step 6: Populate the QR code for app onboarding

SAP Business Application Studio has a feature to generate QR code for app onboarding.

Double-click the Application.app to open it in MDK Application Editor and click Application QR Code icon to populate the QR code.

MDKMDK
Log on to answer question
Step 7: Run the app in MDK client

Make sure you are choosing the right device platform tab above. Once you have scanned and onboarded using the onboarding URL, it will be remembered. When you Log out and onboard again, you will be asked either to continue to use current application or to scan new QR code.

  1. Follow these steps to on-board the MDK client.

  2. Once you accept the App update, a message should show Push Notification Registered. Click OK.

    MDK
  3. It is time now to send the first push notification from the SAP Cloud Platform Mobile Services push notification feature.

    Navigate to Mobile Services cockpit. In Mobile Push Notification feature, switch to Push Registrations tab.

    There you will find information about user registered for push notification and also details about Push providers. Identify your Device ID and click Send Notification.

    MDK
  4. In notification dialog, type a notification message and click Send.

    MDK

    You will see a success toast message.

    MDK

    After sending notification, mobile device should receive the message.

    MDK
  1. Follow these steps to on-board the MDK client.

  2. Once you accept app update, you will notice that it will first ask permission to display notifications.

    MDK
  3. If push registration is successful, a message should show Push Notification Registered. Click OK.

    MDK
  4. It is time now to send the first push notification from the SAP Cloud Platform Mobile Services push notification feature.

    Navigate to Mobile Services cockpit. In Mobile Push Notification feature, switch to Push Registrations tab.

    There you will find information about user registered for push notification and also details about Push providers. Identify your Device ID and click Send Notification.

    MDK
  5. In notification dialog, type a notification message and click Send.

    MDK

    You will see a success toast message.

    MDK

    After sending notification, mobile device should receive the message.

    MDK

    If you have Apple watch connected to the iPhone device, you can also see same push notification on the Apple Watch.

    MDK

    MDK supports rich push notification. MDK does not run on smart watches or as an Apple watch application.

Once you have scanned and onboarded using the onboarding URL, it will be remembered. When you Log out and onboard again, you will be asked either to continue to use current application or to scan new QR code.

Congratulations! You have successfully implemented Enable Push Notifications in the MDK Public Store Client and you are now all set to Consume a REST API in an MDK App.

Log on to answer question

Next Steps

Back to top