您好,登錄后才能下訂單哦!
IOS 通訊錄信息讀取兼容的實(shí)現(xiàn)方法
項(xiàng)目中有一個(gè)功能需要讀取通訊錄中聯(lián)系人的手機(jī)。在iOS8以前都是可用的,主要使用如下三個(gè)代理方法來(lái)實(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ā)者來(lái)說(shuō)來(lái)說(shuō)這種情況太常見了)
參考文檔發(fā)現(xiàn)可以使用如下兩個(gè)方法來(lái)代替:
// 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í)例詳解,如有疑問(wèn)請(qǐng)留言或者到本站社區(qū)交流討論,感謝閱讀,希望能幫助到大家,謝謝大家對(duì)本站的支持!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。