Calvin Seng
Calvin Seng

Reputation: 193

Disable Launch URL in OneSignal Push Notification when opened

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();
      }

Upvotes: 1

Views: 2178

Answers (1)

Calvin Seng
Calvin Seng

Reputation: 193

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;
}

Upvotes: 1

Related Questions