recordID に基づいて人の ABAddressBook プロパティにアクセスしようとしていますが、プロパティを取得しようとするたびに null 値が返されます。
これは私が試したコードです。
ABAddressBookRef addressBook = NULL;
addressBook = ABAddressBookCreateWithOptions(addressBook, nil);
ABRecordRef person = ABAddressBookGetPersonWithRecordID(addressBook, (ABRecordID) [[object valueForKey:@"recordId"] description]);
NSString *firstName = (__bridge NSString *)ABRecordCopyValue(person, kABPersonFirstNameProperty);
NSLog(@"First Name %@", firstName);
NSString *lastName = (__bridge NSString *)ABRecordCopyValue(person, kABPersonLastNameProperty);
NSString *name = [NSString stringWithFormat:@"%@" "%@", lastName, firstName];
NSLog(@"Full Name %@", name);
ここで何が間違っていますか?
編集:上記の問題をある程度理解しました。これは私が使用したものです。現在私が抱えている問題は、このコード ブロックの実行が完了したときにのみ UITableView をリロードする必要があることです。しかし、このブロックの実行がいつ完了するかはわかりません。助けが必要です。
CFErrorRef myError = NULL;
ABAddressBookRef addressBook = ABAddressBookCreateWithOptions(NULL, &myError);
ABAddressBookRequestAccessWithCompletion(addressBook,
^(bool granted, CFErrorRef error) {
if (granted) {
ABRecordID recID = [recordId intValue];
ABRecordRef person = ABAddressBookGetPersonWithRecordID(addressBook, recID);
NSString *firstName = (__bridge NSString *)ABRecordCopyValue(person, kABPersonFirstNameProperty);
NSString *lastName = (__bridge NSString *)ABRecordCopyValue(person, kABPersonLastNameProperty);
if(!firstName){
firstName = @"";
}
if(!lastName){
lastName = @"";
}
NSString *name = [NSString stringWithFormat:@"%@ %@", lastName, firstName];
if([firstName length] < 1 && [lastName length] < 1){
name = @"No Name";
}
self.personName = name;
NSData *imageData = (NSData *)CFBridgingRelease(ABPersonCopyImageData(person));
if(imageData){
self.personImage = [UIImage imageWithData:imageData];
}
else{
self.personImage = [UIImage imageNamed:@"default.png"];
}
NSMutableArray *array = [NSMutableArray array];
[array addObject:self.personName];
[array addObject:self.personImage];
[self.personDetailsArray addObject:array];
[self.tableView reloadData];
} else {
// Handle the error
}
});
ブロック内の UIElements を更新するのは正しい方法ですか? そうでない場合、代替手段は何ですか。
私がしたいのは、ブロックの実行後にのみ UITableView をロード/更新することです。役に立つものはまだ見つかりませんでした