IOS 通訊錄信息讀取兼容的實現(xiàn)方法
IOS 通訊錄信息讀取兼容的實現(xiàn)方法
項目中有一個功能需要讀取通訊錄中聯(lián)系人的手機。在iOS8以前都是可用的,主要使用如下三個代理方法來實現(xiàn)
- (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更新以后,悲劇的事情發(fā)生了:
// 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開發(fā)者來說來說這種情況太常見了)
參考文檔發(fā)現(xiàn)可以使用如下兩個方法來代替:
// 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以后通訊錄的結構有所變化:第一層是人名列表,點擊某個人名進去之后是這個人的詳細信息。
其中:
第一個方法是選中這個人之后調(diào)用。
第二個方法是選中這個人的詳細信息后調(diào)用。
解析具體信息的代碼可以完全不變
以上就是IOS 通訊錄信息讀取兼容的實例詳解,如有疑問請留言或者到本站社區(qū)交流討論,感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!
相關文章
iOS overFullScreen與fullScreen區(qū)別分析
這篇文章主要介紹了iOS overFullScreen與fullScreen區(qū)別分析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2023-11-11
iOS開發(fā)實現(xiàn)搜索框(UISearchController)
這篇文章主要為大家詳細介紹了iOS開發(fā)實現(xiàn)搜索框,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2022-08-08
iOS 11更新后及iPhone X推出后工程中遇到的問題及適配方法
這篇文章主要介紹了iOS 11更新后及iPhone X推出后工程中遇到的問題及適配,需要的朋友可以參考下2017-10-10

