Disable Launch URL in OneSignal Push Notification when opened

Issue

Unable to disable the launch url in OneSignal push notification when opened. Tried toggling kOSSettingsKeyInAppLaunchURL from true to false and it still opens up Safari.

What can I do to completely remove the launch Url? Thanks in advance.

My code in for OneSignal app.component.ts is as follows,

if (this.appConfig.Onesignal_Enable == true) {
        this.oneSignal.startInit(this.appConfig.OneSignal_AppID, this.appConfig.GCM_SenderID);
        this.oneSignal.iOSSettings({
          kOSSettingsKeyInAppLaunchURL: false,
          kOSSettingsKeyAutoPrompt: true,
        });

        this.oneSignal.handleNotificationOpened().subscribe(() => {
          // do something when a notification is opened
          this.navCtrl.navigateForward('positions');
        });
        this.oneSignal.endInit();
      }

Solution

Solved it on the web side instead with PHP. For anyone running on WordPress, this is a great filter.

add_filter( 'onesignal_send_notification', 'onesignal_send_notification_filter', 10, 4 );
function onesignal_send_notification_filter($fields, $new_status, $old_status, $post) {
    // Set player ids as subscribed to onesignal notification (see users in onesignal dashboard)
    $fields['isAndroid'] = true;
    $fields['isIos'] = true;
    $fields['isAnyWeb'] = false;
    $fields['isChrome'] = false;
    $fields['data'] = array(
        "myappurl" => $fields['url']
    );
    /* Unset the URL to prevent opening the browser when the notification is clicked */
    unset($fields['url']);
    return $fields;
}

Answered By – Calvin Seng

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published