<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                ## iOS:ABPeoplePickerNavigationController系統通訊錄使用 昨天因項目需求要訪問系統通訊錄獲取電話號碼,于是乎從一無所知,開始倒騰,倒騰了一下午,總算了弄好了。寫這邊博客是為了記錄一下,自己下一次弄的時候就別在出錯了。同時,有和我一樣的菜鳥能夠避免走一下彎路。 好了,言歸正傳,要訪問系統的通訊錄,首先需要添加`AddressBook.framework`?和?`AddressBookUI.framework`?兩個框架到你工程中build phase的"Link Binary With Libraries"之下,然后就可以開始了。 首先我們需要創建一個控制器:ViewController,在.h文件中導入頭文件:<AddressBook/AddressBook.h>、??<AddressBookUI/AddressBookUI.h>, ~~~ #import <AddressBook/AddressBook.h> #import <AddressBookUI/AddressBookUI.h> ~~~ 然后在控制器實現?ABPeoplePickerNavigationControllerDelegate, UINavigationControllerDelegate協議 ~~~ @interface ViewController ()<ABPeoplePickerNavigationControllerDelegate, UINavigationControllerDelegate> ~~~ 在viewDidAppear方法中創建ABPeoplePickerNavigationController,同時設置viewController作為委托對象 ~~~ - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; ABPeoplePickerNavigationController *pNC = [[ABPeoplePickerNavigationController alloc] init]; pNC.peoplePickerDelegate = self; [self presentViewController:pNC animated:YES completion:nil]; } ~~~ 接下來需要實現ABPeoplePickerNavigationControllerDelegate協議 ~~~ #pragma mark - ABPeoplePickerNavigationControllerDelegate - (void)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker didSelectPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier { ABMultiValueRef phone = ABRecordCopyValue(person, kABPersonPhoneProperty); long index = ABMultiValueGetIndexForIdentifier(phone,identifier); NSString *phoneNO = (__bridge NSString *)ABMultiValueCopyValueAtIndex(phone, index); phoneNO = [phoneNO stringByReplacingOccurrencesOfString:@"-" withString:@""]; NSLog(@"%@", phoneNO); if (phone && phoneNO.length == 11) { [peoplePicker dismissViewControllerAnimated:YES completion:nil]; return; }else{ UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"錯誤提示" message:@"請選擇正確手機號" delegate:self cancelButtonTitle:@"確定" otherButtonTitles:nil]; [alertView show]; } } - (void)peoplePickerNavigationController:(ABPeoplePickerNavigationController*)peoplePicker didSelectPerson:(ABRecordRef)person NS_AVAILABLE_IOS(8_0) { ABPersonViewController *personViewController = [[ABPersonViewController alloc] init]; personViewController.displayedPerson = person; [peoplePicker pushViewController:personViewController animated:YES]; } - (void)peoplePickerNavigationControllerDidCancel:(ABPeoplePickerNavigationController *)peoplePicker { [peoplePicker dismissViewControllerAnimated:YES completion:nil]; } - (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person NS_DEPRECATED_IOS(2_0, 8_0) { return YES; } - (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier NS_DEPRECATED_IOS(2_0, 8_0) { ABMultiValueRef phone = ABRecordCopyValue(person, kABPersonPhoneProperty); long index = ABMultiValueGetIndexForIdentifier(phone,identifier); NSString *phoneNO = (__bridge NSString *)ABMultiValueCopyValueAtIndex(phone, index); phoneNO = [phoneNO stringByReplacingOccurrencesOfString:@"-" withString:@""]; NSLog(@"%@", phoneNO); if (phone && phoneNO.length == 11) { [peoplePicker dismissViewControllerAnimated:YES completion:nil]; return NO; }else{ UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"錯誤提示" message:@"請選擇正確手機號" delegate:self cancelButtonTitle:@"確定" otherButtonTitles:nil]; [alertView show]; } return YES; }@end ~~~ 到這里本以為大功告成,的確在iOS7是沒有任何問題,但是iOS8出現了坑爹的問題,就是選擇聯系人后 ABPeoplePickerNavigationController會自動dismiss掉,這個問題可坑壞我了。問了谷歌和度娘,在stackvoerflow找到了類似的問題,但是都沒有得到解決,在覺得沒有辦法的時候,又開始看ABPeoplePickerNavigationController.h的頭文件,發現了 predicateForSelectionOfPerson屬性,于是乎在viewDidAppear方法中加入如下代碼: ~~~ if([[UIDevice currentDevice].systemVersion floatValue] >= 8.0){ pNC.predicateForSelectionOfPerson = [NSPredicate predicateWithValue:false]; } ~~~ 運行程序,大功告成
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看