IOS 通訊錄信息讀取兼容的實(shí)現(xiàn)方法
創(chuàng)新互聯(lián)公司長(zhǎng)期為上1000家客戶提供的網(wǎng)站建設(shè)服務(wù),團(tuán)隊(duì)從業(yè)經(jīng)驗(yàn)10年,關(guān)注不同地域、不同群體,并針對(duì)不同對(duì)象提供差異化的產(chǎn)品和服務(wù);打造開放共贏平臺(tái),與合作伙伴共同營(yíng)造健康的互聯(lián)網(wǎng)生態(tài)環(huán)境。為昌黎企業(yè)提供專業(yè)的做網(wǎng)站、成都網(wǎng)站設(shè)計(jì),昌黎網(wǎng)站改版等技術(shù)服務(wù)。擁有10余年豐富建站經(jīng)驗(yàn)和眾多成功案例,為您定制開發(fā)。
項(xiàng)目中有一個(gè)功能需要讀取通訊錄中聯(lián)系人的手機(jī)。在iOS8以前都是可用的,主要使用如下三個(gè)代理方法來實(shí)現(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);
其中兩個(gè)方法被干掉了(對(duì)于iOS開發(fā)者來說來說這種情況太常見了)
參考文檔發(fā)現(xiàn)可以使用如下兩個(gè)方法來代替:
// 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);
這兩個(gè)方法是這樣的,因?yàn)閕OS8以后通訊錄的結(jié)構(gòu)有所變化:第一層是人名列表,點(diǎn)擊某個(gè)人名進(jìn)去之后是這個(gè)人的詳細(xì)信息。
其中:
第一個(gè)方法是選中這個(gè)人之后調(diào)用。
第二個(gè)方法是選中這個(gè)人的詳細(xì)信息后調(diào)用。
解析具體信息的代碼可以完全不變
以上就是IOS 通訊錄信息讀取兼容的實(shí)例詳解,如有疑問請(qǐng)留言或者到本站社區(qū)交流討論,感謝閱讀,希望能幫助到大家,謝謝大家對(duì)本站的支持!