OneSignal Info
Your website can access a oneSignalInfo
object that includes OneSignal data and device data for the current device via the Median JavaScript Bridge. As with other JavaScript Bridge functionalities, there are alternate ways to interact with the OneSignal integration. You may send the oneSignalInfo
data to your server via AJAX, or anything else that's required on your website/web application using JavaScript.
// oneSignalInfo contains the below
{
oneSignalUserId: 'xxxxxxx',
oneSignalPushToken: 'xxxxxx',
oneSignalSubscribed: true,
oneSignalRequiresUserPrivacyConsent: false,
platform: 'ios',
appId: 'io.median.example',
appVersion: '1.0.0',
distribution: 'release',
hardware: 'armv8',
installationId: 'xxxx-xxxx-xxxx-xxxx',
language: 'en',
model: 'iPhone',
os: 'iOS',
osVersion: '10.3',
timeZone: 'America/New_York'
}
Call median_onesignal_info()
function each page load
median_onesignal_info()
function each page loadIf your website defines a function called median_onesignal_info()
, it will get called after every page load as shown below with the oneSignalInfo
object.
↔️Median JavaScript Bridge
// You define this function on your page, but do not actually call it // If present on a page it will be called by the app when the page is loaded function median_onesignal_info(oneSignalInfo) { console.log(oneSignalInfo); }
Trigger median_onesignal_info()
manually
median_onesignal_info()
manuallyYou may also run median_onesignal_info()
manually at any time by calling median.onesignal.run.onesignalInfo()
.
↔️Median JavaScript Bridge
// You may also call the median_onesignal_info function manually // e.g. on a single page web app median.onesignal.run.onesignalInfo();
Return data via a promise
Call median.onesignal.onesignalInfo.then()
or use await median.onesignal.onesignalInfo()
to return a promise that will resolve with the oneSignalInfo
object.
↔️Median JavaScript Bridge
// Or return the OneSignal Info via a promise (in async function) var oneSignalInfo = await median.onesignal.onesignalInfo(); median.onesignal.onesignalInfo().then(function (oneSignalInfo) { console.log(oneSignalInfo); });
The
median_onesignal_info()
function is called by the native app when the page is loaded within the app. This function must be available at the time of page load and cannot be loaded asynchronously or in a deferred manner. If this is not possible, use the promise-based methods.
Updated about 2 months ago