zoukankan      html  css  js  c++  java
  • 打开通讯录及回调

    - (IBAction)openPhoneBook:(UIButton *)sender {//打开电话本
        
        _tableView.hidden = YES;
        
        ABPeoplePickerNavigationController *peoplePicker = [[ABPeoplePickerNavigationController alloc] init];
        peoplePicker.peoplePickerDelegate = self;
        peoplePicker.delegate = self;
        [self presentViewController:peoplePicker animated:YES completion:nil];
    }
    
    #pragma mark - 打开通讯录
    
    #pragma mark - ABPeoplePickerNavigationControllerDelegate
    - (void)peoplePickerNavigationControllerDidCancel:(ABPeoplePickerNavigationController *)peoplePicker
    {
        [peoplePicker dismissViewControllerAnimated:YES completion:^{}];
    }
    
    
    // Called after a person has been selected by the user.
    - (void)peoplePickerNavigationController:(ABPeoplePickerNavigationController*)peoplePicker didSelectPerson:(ABRecordRef)person NS_AVAILABLE_IOS(8_0)
    {
        ABMultiValueRef phoneNumbers = (ABMultiValueRef)ABRecordCopyValue(person, kABPersonPhoneProperty);
        NSString * phone  = @"";
        if (phoneNumbers) {
            //CFIndex count = ABMultiValueGetCount(phoneNumbers);
            phone = (__bridge NSString*)ABMultiValueCopyValueAtIndex(phoneNumbers, 0);
            CFRelease(phoneNumbers);
        }
    //    
    //    NSString * firstname = (__bridge NSString *)(ABRecordCopyValue(person, kABPersonLastNameProperty)); ////    NSString * lastname = (__bridge NSString *)(ABRecordCopyValue(person, kABPersonFirstNameProperty)); ////    NSString * name = [firstname==nil?@"":firstname stringByAppendingString:lastname==nil?@"":lastname];
        
        if(phone.length && [phone hasPrefix:@"+86"]){
            phone = [phone substringFromIndex:3];
        }
        
        phone =  [phone stringByReplacingOccurrencesOfString:@"-" withString:@""];
        self.searchTField.text = phone;
        
        [peoplePicker dismissViewControllerAnimated:NO completion:^{
        
            [self.searchTField becomeFirstResponder];
        }];
    }
    
    // Deprecated, use predicateForSelectionOfPerson and/or -peoplePickerNavigationController:didSelectPerson: instead.
    - (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person NS_DEPRECATED_IOS(2_0, 8_0)
    {
        ABMultiValueRef phoneNumbers = (ABMultiValueRef)ABRecordCopyValue(person, kABPersonPhoneProperty);
        NSString * phone  = @"";
        if (phoneNumbers) {
            //CFIndex count = ABMultiValueGetCount(phoneNumbers);
            phone = (__bridge NSString*)ABMultiValueCopyValueAtIndex(phoneNumbers, 0);
            CFRelease(phoneNumbers);
        }
        
        NSLog(@"phone=%@",phone);
        
        if(phone.length && [phone hasPrefix:@"+86"]){
            phone = [phone substringFromIndex:3];
        }
        
        phone =  [phone stringByReplacingOccurrencesOfString:@"-" withString:@""];
        
        self.searchTField.text = phone;
        
        [peoplePicker dismissViewControllerAnimated:YES completion:^{}];
        
        return NO;
    }
  • 相关阅读:
    jq 换图片路径
    sql 把一列的数据按逗号分隔转换成多行
    sql 数据库查看主外键关联
    sql 表连接 join
    sql 查看 锁定的表 或者 未提交 的事务
    WMI技术介绍和应用——查询硬件信息
    System.Web.HttpContext.Current.Server.MapPath("~/upload/SH") 未将对象引用设置为实例对象
    sql server output用法说明
    merge into 的用法
    JAVA Stop The World 第八节
  • 原文地址:https://www.cnblogs.com/h-tao/p/4981067.html
Copyright © 2011-2022 走看看