IOS 通讯录信息读取兼容的实现方法
程序员文章站
2023-12-18 21:16:34
ios 通讯录信息读取兼容的实现方法
项目中有一个功能需要读取通讯录中联系人的手机。在ios8以前都是可用的,主要使用如下三个代理方法来实现
- (void...
ios 通讯录信息读取兼容的实现方法
项目中有一个功能需要读取通讯录中联系人的手机。在ios8以前都是可用的,主要使用如下三个代理方法来实现
- (void) peoplepickernavigationcontrollerdidcancel:(abpeoplepickernavigationcontroller *)peoplepicker
- (bool) peoplepickernavigationcontroller:(abpeoplepickernavigationcontroller *) peoplepicker shouldcontinueafterselectingperson:(abrecordref)person
- (bool)peoplepickernavigationcontroller:(abpeoplepickernavigationcontroller *)peoplepicker shouldcontinueafterselectingperson:(abrecordref)person property:(abpropertyid)property identifier:(abmultivalueidentifier)identifier { return no; }
但是ios8更新以后,悲剧的事情发生了:
// deprecated, use predicateforselectionofperson and/or -peoplepickernavigationcontroller:didselectperson: instead. - (bool)peoplepickernavigationcontroller:(abpeoplepickernavigationcontroller *)peoplepicker shouldcontinueafterselectingperson:(abrecordref)person ns_deprecated_ios(2_0, 8_0); // deprecated, use predicateforselectionofproperty and/or -peoplepickernavigationcontroller:didselectperson:property:identifier: instead. - (bool)peoplepickernavigationcontroller:(abpeoplepickernavigationcontroller *)peoplepicker shouldcontinueafterselectingperson:(abrecordref)person property:(abpropertyid)property identifier:(abmultivalueidentifier)identifier ns_deprecated_ios(2_0, 8_0);
其中两个方法被干掉了(对于ios开发者来说来说这种情况太常见了)
参考文档发现可以使用如下两个方法来代替:
// called after a person has been selected by the user. - (void)peoplepickernavigationcontroller:(abpeoplepickernavigationcontroller*)peoplepicker didselectperson:(abrecordref)person ns_available_ios(8_0); // called after a property has been selected by the user. - (void)peoplepickernavigationcontroller:(abpeoplepickernavigationcontroller*)peoplepicker didselectperson:(abrecordref)person property:(abpropertyid)property identifier:(abmultivalueidentifier)identifier ns_available_ios(8_0);
这两个方法是这样的,因为ios8以后通讯录的结构有所变化:第一层是人名列表,点击某个人名进去之后是这个人的详细信息。
其中:
第一个方法是选中这个人之后调用。
第二个方法是选中这个人的详细信息后调用。
解析具体信息的代码可以完全不变
以上就是ios 通讯录信息读取兼容的实例详解,如有疑问请留言或者到本站社区交流讨论,感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!