MUI NativeJS for iOS判断是否安装了指定应用

使用Objective-C可以轻松实现判断应用是否安装:

1
BOOL result=[[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"weixin://"]];

转换为NativeJS写法为:

1
2
3
4
5
6
7
8
9
function test(){
var NSURL = plus.ios.import('NSURL');
var UIA = plus.ios.import('UIApplication');
var obj = new UIA.sharedApplication();
var result = obj.canOpenURL(NSURL.URLWithString('weixin://'));
//return result;
alert(result);
//[[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"weixin://"]];
}

返回值为1则安装了"weixin",返回0则没安装。