Last active
September 21, 2021 00:56
-
-
Save marchbold/c052b5ff35f6e2c3a090 to your computer and use it in GitHub Desktop.
AirBridge Javascript helper to communicate from JS to the WebView instance
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* | |
*/ | |
var AirBridge = (function() { | |
var instance; | |
function createInstance() { | |
var object = new Object(); | |
object.useWindowLocation = true; | |
return object; | |
} | |
return { | |
setUseWindowLocation: function( $shouldUseWindowLocation ) { | |
if (!instance) { | |
instance = createInstance(); | |
} | |
instance.useWindowLocation = $shouldUseWindowLocation; | |
}, | |
message: function( $message ) { | |
if (!instance) { | |
instance = createInstance(); | |
} | |
if (!instance.useWindowLocation) { | |
NativeWebView.airBridge( $message ); | |
} | |
else { | |
window.location = "airBridge:" + $message; | |
} | |
} | |
}; | |
})(); | |
// com.distriqt.NativeWebView |
It gives error like
net::ERR_UNKNOWN_URL_SCHEME
in android devices. You should replace;
if (!instance.useWindowLocation) {
NativeWebView.airBridge( $message );
}
else {
window.location = "airBridge:" + $message;
}
with;
if (!instance.useWindowLocation) {
NativeWebView.airBridge( $message );
}
else {
if(sys == 'iOS')
{
location = "airBridge:" + $message;
}else{
location = "http://airBridge:" + $message;
}
}
I've tested both iOs and Android. It works well...
Need this function maybe:
_function getMobileOperatingSystem() {
var userAgent = navigator.userAgent || navigator.vendor || window.opera;
if (/windows phone/i.test(userAgent)) {
return "Windows Phone";
}
if (/android/i.test(userAgent)) {
return "Android";
}
// iOS detection from: http://stackoverflow.com/a/9039885/177710
if (/iPad|iPhone|iPod/.test(userAgent) && !window.MSStream) {
return "iOS";
}
return "unknown";
}
var sys = getMobileOperatingSystem();
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://airnativeextensions.com/extension/com.distriqt.NativeWebView