参照w_wh写的<通过Native.js访问iOS原生通讯录界面>后仿造写了个使用NJS在ios调用mediaPicker的例子 能调出系统选择器 但是设置delegate后运行会闪退(不设置的话取不到选择的文件结果) 不知道有没有大佬帮忙看看什么问题
var picker = plus.ios.newObject("MPMediaPickerController");
plus.ios.invoke(picker, "initWithMediaTypes:", 0x00ff);
picker.plusSetAttribute("prompt", "请选择需要播放的歌曲")
picker.plusSetAttribute("showsCloudItems", false)
picker.plusSetAttribute("allowsPickingMultipleItems", true)
let delegate = plus.ios.implements("MPMediaPickerControllerDelegate", {
"mediaPicker:didPickMediaItems:": function(mediaPicker, mediaItemCollection){
console.log(mediaPicker, mediaItemCollection);
//plus.ios.deleteObject(mediaPicker);
},
"mediaPickerDidCancel:":function(mediaPicker){
console.log(mediaPicker)
//plus.ios.deleteObject(mediaPicker);
}
});
picker.plusSetAttribute("delegate", delegate);
var UIApplicationClass = plus.ios.importClass("UIApplication");
var UIAppObj = UIApplicationClass.sharedApplication();
var del = plus.ios.invoke(UIAppObj,"delegate");
var appWindowObj = plus.ios.invoke(del,"window");
var appRootController = plus.ios.invoke(appWindowObj,"rootViewController");
plus.ios.invoke(appRootController,"presentViewController:animated:completion:",picker,true,null);
plus.ios.deleteObject(picker);
1 个回复
FullStack - 【插件开发】【专治疑难杂症】【ios上架、马甲包、白包、过审、已成功上架过几百个】【多款插件已上架:https://ext.dcloud.net.cn/publisher?id=22130】【非诚勿扰】QQ:543610866
Native.js的delegate本来就有问题,用原生插件吧