This article will detail the steps required to set up push notifications for a sub-app within a portal

The portal app is the app launched via the app stores or MDM (mobile device manager)

The sub-app is any app that is published through the portal app

Get started

  1. Configure the portal app
  2. Configure the sub app
  3. Make note of your app ID
  4. Add the JavaScript
  5. Publish and test

Step 1 – Configure the portal app

  1. Ensure your portal app is set up to send push notifications 
    1. To do this for Apple click here
    2. To do this for Google click here

Step 2 – Make note of your app ID

  1. Click on the portal component to open the settings

  2. Scroll down in the settings to where you can see your available apps

  3. Make a note of the app ID for your sub app, as you’ll need it for the next step

Step 3 – Add the JavaScript

  1. Inside Fliplet Studio, open your sub app and then open the developer options by choosing the “</>” icon on the right hand side toolbar
  2. In the Javascript section, paste the following snippet of code, making sure to replace “1234” on lines 1 and 2 with the relevant app ID and save
  3. Once saved you will see a message to say it was successful, you can then delete the code snippet and save the developer options again.
const
 portalApp = 1234; // change value 1234 to the ID of your portal app
const subApp = 1234; // change value 1234 to the ID of your sub app
(async function() {
  try {
    const portalResponse = await Fliplet.API.request({
      url: `v1/widget-instances/com.fliplet.push-notifications?appId=${portalApp}&includeSensitiveData=true`
    });
    const pushNotificationSettings = portalResponse.widgetInstance.settings || {};
    const pushNotificationKeys = [
      'apn', 'apnKeyId', 'apnTopic', 'apnTeamId', 'apnAuthKey',
      'gcm', 'gcmSenderId', 'gcmProjectId', 'gcmServerKey',
      'gcmPackageName', 'project_id', 'client_email', 'private_key'
    ];
    const portalSettings = pushNotificationKeys.reduce((settings, key) => {
      if (Object.prototype.hasOwnProperty.call(pushNotificationSettings, key)) {
        settings[key] = pushNotificationSettings[key];
      }
      return settings;
    }, {});
    const subAppResponse = await Fliplet.API.request({
      url: `v1/widget-instances/com.fliplet.push-notifications?appId=${subApp}&includeSensitiveData=true`
    });
    const subAppSettings = subAppResponse.widgetInstance.settings || {};
    Object.assign(subAppSettings, portalSettings);
    await Fliplet.API.request({
      url: `v1/widget-instances/${subAppResponse.widgetInstance.id}`,
      method: 'PUT',
      data: subAppSettings
    });
    Fliplet.Modal.alert({ message: 'Push notification settings updated successfully. You can remove the code.' });
  } catch (error) {
    Fliplet.Modal.alert({ message: 'Failed to update push notification settings. Please try again.' });
    console.error(error);
  }
})()

Step  4- Publish and test

  1. In both the sub app and the portal app, open the notifications settings
  2. To do this, choose “Publish” in the top right corner of studio
  3. Select “More publishing options”
  4. Select, “Notifications” at the top of the page followed by “Push notifications settings”
  5. Ensure the “Apps inside a portal shouldn’t request users to subscribe to push notifications” setting is selected
  6. Save the settings
  7. Publish an in-app update
  8. Test the app notifications as per the instructions here
Was this article helpful?
YesNo