Basic Usage

👍

Median not median when using NPM package

When using the NPM Package make note to use capitalized Median to call functions rather than lowercase median which is reserved for the the injected JavaScript library. Your IDE should be configured to help with code hinting to help with completion and avoid semantic errors.

import Median from "median-js-bridge";
import React, { useEffect } from "react";

const App: React.FC = () => {
    useEffect(() => {
        Median.onReady(() => {
            window.alert("Median app ready!");
        });
    }, []);
}

OneSignal example demonstrating login and oneSignalId retrieval

useEffect(() => {
 Median.onReady(async () => {
   const result = await Median.onesignal.login('test-user');
   if (result?.success) {
     const info = await Median.onesignal.info();
     console.log(info?.oneSignalId);
     // Do something with info?.oneSignalId such as store in database
   }})
}, []);

JavaScript Bridge methods specific to NPM Package

↔️Median JavaScript Bridge

To check if running in your app:

Median.isNativeApp(); 
// Returns true or false

To retrieve the current platform:

Median.getPlatform();
// Returns a promise with a string web | android | ios