尝试打开联系人时出错

时间:2015-02-18 20:05:41

标签: ios objective-c xcode

我正在使用objective-c构建应用程序。 当我按下链接到func的按钮时应该打开设备的联系人我得到以下错误并且应用程序崩溃:

  

插件com.apple.MobileAddressBook.ContactsViewService中断了Hub   连接错误错误Domain = NSCocoaErrorDomain Code = 4097" The   操作无法完成....未被捕获的例外   ' NSInvalidArgumentException',原因:' *** - [__ NSArrayM   insertObject:atIndex:]:object不能为nil'

重要的是说它并非总是发生..有时联系人会打开,有时我会收到上述错误。

这是我打开联系人的代码:

- (IBAction)addContacts:(id)sender {
    self.user = [[User alloc] init];
    NSLog(@"ADD CONTACT");
    _addressBookController = [[ABPeoplePickerNavigationController alloc] init];
    [_addressBookController setPeoplePickerDelegate:self];
    [self presentViewController:_addressBookController animated:YES completion:nil];
}

有人可以指出我的问题吗?

我添加了peoplePickerNavigationController:

- (void)peoplePickerNavigationController:(ABPeoplePickerNavigationController*)peoplePicker didSelectPerson:(ABRecordRef)person{
    NSLog(@"PEOPLE PICKER");
    CFTypeRef generalCFObject = ABRecordCopyValue(person, kABPersonFirstNameProperty);
    if (generalCFObject) {
        self.user.firstName = (__bridge NSString *)generalCFObject;
        CFRelease(generalCFObject);
    }

    generalCFObject = ABRecordCopyValue(person, kABPersonLastNameProperty);
    if (generalCFObject) {
        self.user.lastName = (__bridge NSString *)generalCFObject;
        CFRelease(generalCFObject);
    }

    ABMultiValueRef phonesRef = ABRecordCopyValue(person, kABPersonPhoneProperty);
    for (int i=0; i<ABMultiValueGetCount(phonesRef); i++) {
        CFStringRef currentPhoneLabel = ABMultiValueCopyLabelAtIndex(phonesRef, i);
        CFStringRef currentPhoneValue = ABMultiValueCopyValueAtIndex(phonesRef, i);

        if (CFStringCompare(currentPhoneLabel, kABPersonPhoneMobileLabel, 0) == kCFCompareEqualTo) {
            self.user.phoneNumber = (__bridge NSString *)currentPhoneValue;
        }

        CFRelease(currentPhoneLabel);
        CFRelease(currentPhoneValue);
    }

    CFRelease(phonesRef);

    [self.assignment.usersList addObject:self.user];
    [self.tableViewCell reloadData];
    [_addressBookController dismissViewControllerAnimated:YES completion:nil];

}

-(BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier{
    return NO;
}
//enable contact cancel buttopn
-(void)peoplePickerNavigationControllerDidCancel:(ABPeoplePickerNavigationController *)peoplePicker{
    [_addressBookController dismissViewControllerAnimated:YES completion:nil];
}

0 个答案:

没有答案