mui 跳转到设置界面 和 ios 无法上线的解决办法

好多人都这么写:

if(mui.os.ios){
    plus.runtime.launchApplication({action:'App-Prefs:root=WIFI'}, function(e){
        console.log(JSON.stringify(e));
    }); //WIFI
} else {
    var main = plus.android.runtimeMainActivity();
    var Intent = plus.android.importClass("android.content.Intent");
    var mIntent = new Intent('android.settings.WIFI_SETTINGS');
    main.startActivity(mIntent);
}

ios这么写的话,苹果是不让审核通过的,苹果公司回复:“Prefs:root”,使用了私有方法,

有两种方法解决:

1. "App-Prefs:root=WIFI" 把这个字符串转为十六进制,这样就可以跳过苹果的代码扫描

“0x4170702d50726566733a726f6f743d57494649” 为字符串“App-Prefs:root=WIFI”的16进制

//字符串转16进制
function strToHexCharCode(str) {  
	if(str === "")     return "";  
	var hexCharCode = [];  
	hexCharCode.push("0x");  
	for(var i = 0; i < str.length; i++) {    
		hexCharCode.push((str.charCodeAt(i)).toString(16));  
	}  
	return hexCharCode.join("");
}
//16进制转字符串
function hexCharCodeToStr(hexCharCodeStr) {  
	var trimedStr = hexCharCodeStr.trim();  
	var rawStr =   trimedStr.substr(0, 2).toLowerCase() === "0x"   ?   trimedStr.substr(2)   :   trimedStr;  
	var len = rawStr.length;  
	if(len % 2 !== 0) {    
		alert("Illegal Format ASCII Code!");    
		return "";  
	}  
	var curCharCode;  
	var resultStr = [];  
	for(var i = 0; i < len; i = i + 2) {    
		curCharCode = parseInt(rawStr.substr(i, 2), 16); // ASCII Code Value
		    
		resultStr.push(String.fromCharCode(curCharCode));  
	}  
	return resultStr.join("");
}
if(mui.os.ios) {
	plus.runtime.launchApplication({
		action: hexCharCodeToStr("0x4170702d50726566733a726f6f743d57494649")
	}, function(e) {
		console.log(JSON.stringify(e));
	}); //WIFI
} else {
	var main = plus.android.runtimeMainActivity();
	var Intent = plus.android.importClass("android.content.Intent");
	var mIntent = new Intent('android.settings.WIFI_SETTINGS');
	main.startActivity(mIntent);
}

2.使用公开的api

var UIApplication = plus.ios.import("UIApplication");
var NSURL = plus.ios.import("NSURL");
var setting = NSURL.URLWithString("app-settings:");
var application = UIApplication.sharedApplication();
application.openURL(setting);
plus.ios.deleteObject(setting);
plus.ios.deleteObject(application);

说明:由于苹果新规定,ios10以后,不能跳转到设置页面的子页面

你可能感兴趣的:(mui,html5,plus,native.js,html5+,native.js,HBuilder,移动web)