ios:{//供iOS系统调用
/**
- 访问通讯录,将获取的联系人信息通过callBack返回
- 仅限模拟器使用(Native.js 的bug)
- @param {Object} callBack回调
/
visitContacts: function(callBack){
var contactPickerVC = plus.ios.newObject("CNContactPickerViewController");
//实现代理方法【- (void)contactPicker:(CNContactPickerViewController )picker didSelectContact:(CNContact *)contact;】
//同时生成遵守CNContactPickerDelegate协议的代理对象delegate
var delegate = plus.ios.implements("CNContactPickerDelegate", {
"contactPicker:didSelectContact:":function(picker, contact){
//姓名
var name = "";
//姓氏
var familyName = contact.plusGetAttribute("familyName");
//名字
var givenName = contact.plusGetAttribute("givenName");
name = familyName+givenName;
//电话号码
var phoneNo = "";
var phoneNumbers = contact.plusGetAttribute("phoneNumbers");
if (phoneNumbers.plusGetAttribute("count") > 0) {
var phone = phoneNumbers.plusGetAttribute("firstObject");
var phoneNumber = phone.plusGetAttribute("value");
phoneNo = phoneNumber.plusGetAttribute("stringValue");
}
if(callBack){
callBack(name, phoneNo);
}
}
});
//给通讯录控制器contactPickerVC设置代理
plus.ios.invoke(contactPickerVC, "setDelegate:", delegate);
//获取当前UIWebView视图
var currentWebview = plus.ios.currentWebview();
//根据当前UIWebView视图获取当前控制器
var currentVC = nativeCommon.contacts.ios.getViewControllerByView(currentWebview);
//由当前控制器present到通讯录控制器
plus.ios.invoke(currentVC, "presentViewController:animated:completion:", contactPickerVC, true, null);
},
/** - 访问通讯录,将获取的联系人信息通过callBack返回
- 仅限真机使用(Native.js 的bug)
-
@param {Object} callBack
/
visitAddressBook:function(callBack){
var peoplePickerNavController = plus.ios.newObject("ABPeoplePickerNavigationController");
//实现代理方法【- (void)peoplePickerNavigationController:(ABPeoplePickerNavigationController )peoplePicker didSelectPerson:(ABRecordRef)person;】
//同时生成遵守ABPeoplePickerNavigationControllerDelegate协议的代理对象peoplePickerDelegate
var peoplePickerDelegate = plus.ios.implements("ABPeoplePickerNavigationControllerDelegate", {
"peoplePickerNavigationController:didSelectPerson:":function(peoplePicker, person){
//这里的peoplePicker竟然是CNContact实例对象,person是undefined
// console.log(JSON.stringify(peoplePicker));
// console.log(JSON.stringify(person));
// console.log(typeof person);//所以之前的代码不用改 var contact = peoplePicker; //姓名 var name = ""; //姓氏 var familyName = contact.plusGetAttribute("familyName"); //名字 var givenName = contact.plusGetAttribute("givenName"); name = familyName+givenName; //电话号码 var phoneNo = ""; var phoneNumbers = contact.plusGetAttribute("phoneNumbers"); if (phoneNumbers.plusGetAttribute("count") > 0) { var phone = phoneNumbers.plusGetAttribute("firstObject"); var phoneNumber = phone.plusGetAttribute("value"); phoneNo = phoneNumber.plusGetAttribute("stringValue"); } if (callBack) { callBack(name, phoneNo); } } }); //给通讯录控制器peoplePickerNavController设置代理 plus.ios.invoke(peoplePickerNavController, "setPeoplePickerDelegate:", peoplePickerDelegate); //获取当前UIWebView视图 var currentWebview = plus.ios.currentWebview(); //根据当前UIWebView视图获取当前控制器 var currentVC = nativeCommon.contacts.ios.getViewControllerByView(currentWebview); //由当前控制器present到通讯录控制器 plus.ios.invoke(currentVC, "presentViewController:animated:completion:", peoplePickerNavController, true, null); }, /**
- 根据view获取到当前控制器
- @param {Object} view
*/
getViewControllerByView: function(view){
//UIViewController类对象
var UIViewController = plus.ios.invoke("UIViewController", "class");
while(view){
var responder = plus.ios.invoke(view, "nextResponder");
if (plus.ios.invoke(responder, "isKindOfClass:", UIViewController)) {
return responder;
}
view = plus.ios.invoke(view, "superview");
}
return null;
}
},
当前代码在5+sdk的环境中会拉起ios通讯撸的原生页面,选择之后会返回该联系人的电话号码跟用户姓名,但是在uniapp中会引起系统崩溃,闪退,求教该怎么做呢,愿意付费请教
1 个回复
8***@qq.com
代理方法不走是因为什么