This article is mainly about JS this part of android iOS do not need to see!!
1. Determine whether it is an Android device or an iOS device
function getSystemInfoFromApp(){
var u = navigator.userAgent,
app = navigator.appVersion;
var data = null;
// An Android terminal or uc browser
var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Linux') > -1;
/ / ios terminal
varisiOS = !! u.match(/(i[^;] +; ( U;) ? CPU.+Mac OS X/);
if (isAndroid) {
if (window.android) {
console.log('Enter Android')
data = window.android.method name (); }}else if (isiOS) {
if (window.webkit) {
// Call the IOS jumpjumpNext () method
data = window.webkit.messageHandlers. Method name. PostMessage (null); }}return data
}
Copy the code
2. Js calls Android and iOS modes
Call the android method
window.android.method name ();Copy the code
Call the IOS method
window.webkit.messageHandlers. Method name. PostMessage ('321');
Copy the code
There is a difference between calling iOS and calling Android. When calling Android, android developers can directly define the method name and hang it on the window, and then the Android method can be directly called, while JS can not directly call the method of iOS if you want to use it. Notification must be used in the form of the window. Its. MessageHandlers. The method name. PostMessage (‘ 321 ‘); To tell iOS what method to call, the parentheses must also write something (write anything), not to notify (I don’t know the specific reason, I haven’t found the reason for a long time on the Internet).
3. Android and IOS call js methods
// Just hang a method on the window and tell android or iOS the name of the method.
window.imgList = function(images){}
Copy the code
So any android call that wants to pass a parameter or any iOS call that wants to pass a parameter can only pass a string of parameters.
{name:” Ming “,age:”18″}} {name:” Ming “,age:”18″}} {name:” Ming “,age:”18″}} {name:” Ming “,age:”18″}} {name:” Ming “,age:”18″}} {name:” Ming “,age:”18″}} {name:” Ming “,age:”18″}} {name:” Ming “,age:”18”}}