cordova iOS 调起通讯录崩溃问题
来源:互联网 发布:优化一个网站多少钱 编辑:程序博客网 时间:2024/06/05 01:05
是这样的崩溃是因为iOS9以后更换了使用通讯录的框架 以前的AddressBook 更换为Contacts
所以需要判断系统版本来创建addressVC还是contactVC然后分别写下他们的代理方法
之后就是一个比较容易入坑的地方
之前的代理方法里面都是一些 像我这样的培训的iOS 难懂的地方了 ABRecordRef 这是个什么东西 怎么创建 里面存了什么
- (NSMutableDictionary *)convertToDictionary:(ABRecordRef)person { NSString *fullName, *email; fullName = (__bridge NSString*)ABRecordCopyCompositeName(person); if (!fullName) { fullName = @""; } ABMultiValueRef multi = ABRecordCopyValue(person, kABPersonEmailProperty); if(ABMultiValueGetCount(multi) > 0) email = (__bridge NSString *)ABMultiValueCopyValueAtIndex(multi, 0); else email = @""; ABMultiValueRef multiPhones = ABRecordCopyValue(person, kABPersonPhoneProperty); NSMutableDictionary* phones = [NSMutableDictionary dictionaryWithCapacity:2]; for(CFIndex i = 0; i < ABMultiValueGetCount(multiPhones); i++) { NSString *label = (__bridge NSString*)ABMultiValueCopyLabelAtIndex(multiPhones, i); label = (__bridge NSString*)ABMultiValueCopyLabelAtIndex(multiPhones, i); NSLog(@"Phone Label: %@", label); [phones setObject:(__bridge NSString*)ABMultiValueCopyValueAtIndex(multiPhones, i) forKey: label]; } ABMultiValueRef multiAddresses = ABRecordCopyValue(person, kABPersonAddressProperty); NSMutableArray *addresses = [NSMutableArray array]; for (CFIndex i = 0; i < ABMultiValueGetCount(multiAddresses); i++) { NSDictionary *dictionary = (__bridge NSDictionary *)(ABMultiValueCopyValueAtIndex(multiAddresses, i)); NSArray *keys = @[(__bridge NSString *)kABPersonAddressStreetKey, (__bridge NSString *)kABPersonAddressCityKey, (__bridge NSString *)kABPersonAddressStateKey, (__bridge NSString *)kABPersonAddressCountryKey]; NSMutableArray *values = [NSMutableArray array]; for (NSString *key in keys) { NSString *value = dictionary[key]; if (value && ![value isEqualToString:@""]) { [values addObject:value]; } } [addresses addObject:[values componentsJoinedByString:@", "]]; } NSString *imageURL = [self imageURLForRecord:person fullName:fullName]; NSLog(@"%@ %@", fullName, email); NSMutableDictionary* contact = [NSMutableDictionary dictionaryWithCapacity:2]; if (email) { } [contact setObject:email forKey: @"email"]; [contact setObject:fullName forKey: @"displayName"]; [contact setObject:phones forKey:@"phones"]; contact[@"photoUrl"] = imageURL; contact[@"address"] = addresses; ABRecordID recordID = ABRecordGetRecordID(person); // ABRecordID is a synonym (typedef) for int32_t [contact setObject:@(recordID) forKey:@"id"]; return contact;}
好像看不太懂的样子 而cordova-contact 这个三方还要了 ABRecordRef作为参数 但是这个ABRecordRef根本没法创建 无从下手 所以只好再写个方法 其实ABRecordRef里面的参数换了种方式存储了起来:CNContact
这个就一目了然了 任意搞吧
- (NSMutableDictionary *)convertToDictionaryFor:(CNContact *)contact{ NSString *fullName, *email; fullName=contact.givenName; email=@""; NSLog(@"%@",contact.phoneNumbers[0].value); NSMutableDictionary* phones = [NSMutableDictionary dictionaryWithCapacity:2]; for (int i =0; i<contact.phoneNumbers.count; i++) { NSString *phoneNumber=[contact.phoneNumbers[i].value stringValue]; [phones setObject:phoneNumber forKey:[NSString stringWithFormat:@"%d",i]]; } NSMutableArray *addresses = [NSMutableArray array]; NSString *tmpDirectory = NSTemporaryDirectory(); NSString *fileName = [NSString stringWithFormat:@"%@_image.png", [fullName isEqualToString:@""] ? [NSDate date] : fullName]; NSString *imagePath = [tmpDirectory stringByAppendingPathComponent:fileName]; [contact.imageData writeToFile:imagePath atomically:YES]; NSString *imageURL =[NSURL fileURLWithPath:imagePath].absoluteString; NSLog(@"%@ %@", fullName, email); NSMutableDictionary* kContact = [NSMutableDictionary dictionaryWithCapacity:2]; if (email) { } [kContact setObject:email forKey: @"email"]; [kContact setObject:fullName forKey: @"displayName"]; [kContact setObject:phones forKey:@"phones"]; kContact[@"photoUrl"] = imageURL; kContact[@"address"] = addresses; [kContact setObject:@(1) forKey:@"id"]; return kContact;}
捋顺一下 判断是否是iOS8以上 如果是走自己写的方法 自己写的代理方法 使用- (BOOL)peoplePickerNavigationController: (ABPeoplePickerNavigationController *)peoplePicker
方法 就可以接收到我们点击某个联系人所执行的方法了 这样就解决了 iOS10 cordova调用联系人崩溃的问题
shouldContinueAfterSelectingPerson:(ABRecordRef)person
0 0
- cordova iOS 调起通讯录崩溃问题
- iOS 9 通讯录崩溃问题
- 关于iOS10访问通讯录崩溃问题
- iOS 通讯录问题
- iOS获取通讯录问题
- iOS xib崩溃问题
- iOS问题-崩溃错误
- cordova-plugin-datepicker ios模拟器几次就崩溃
- iOS 修改通讯录联系人地址(address)崩溃原因分析
- iOS调起打电话
- 更新iOS10后相册、通讯录、话筒的权限崩溃问题
- iOS 应用崩溃问题现状
- iOS析构崩溃问题
- iOS调起系统邮箱
- IOS JS调起APP
- iOS 6.0+ 下通讯录访问权限问题
- iOS中通讯录电话号码空格问题
- iOS中通讯录电话号码空格问题
- BSOJ1054 洛谷P1054 CODEVS1107【NOIP 2005提高】等价表达式 随机化
- android编译系统分析(三)make
- MyBatis学习总结(八)——Mybatis3.x与Spring4.x整合
- JAVA.SECURITY.POLICY 配置说明
- mac OSX 创建nginx + rtmp本地推流服务器
- cordova iOS 调起通讯录崩溃问题
- TI ZigBee协议栈中终端设备的状态切换详解
- arcgis server 定义 选择要素操作功能
- android编译系统分析(四)实战:新增一个产品
- Java设计模式之模板方法模式(Template Method)
- 【BZOJ 3289】Mato的文件管理 【莫队+BIT】
- hadoop 节点链接不通、datanode无法启动问题解决
- 搭建一个django+react的博客
- tomacat运行报错