作为 objective-c 和 ios 开发的新手,我正在尝试弄清楚如何从 Address Book Programming Guide for iOS
中实现地址簿代码。 .
我希望能够记录用户在通讯录中点击的地址。
我设法在我的应用中实现了地址簿。
在 ios4 中,以下“有效”:
- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker
shouldContinueAfterSelectingPerson:(ABRecordRef)person
property:(ABPropertyID)property
identifier:(ABMultiValueIdentifier)identifier
{
if (property == kABPersonAddressProperty) // if tapped is equal to a phone property
{
NSLog(@"Address tapped!");
NSMutableDictionary * cfaddress;
ABMultiValueRef address = ABRecordCopyValue(person, kABPersonAddressProperty);
for(CFIndex i = 0; i < ABMultiValueGetCount(address); i++) {
if(identifier == ABMultiValueGetIdentifierAtIndex (address, i)) { //if tapped number identifier is the same as identifier number tapped
cfaddress = ABMultiValueCopyValueAtIndex(address, i); // copy the number to CFSTRING number
}
}
NSLog(@"%@", [cfaddress objectForKey:@"City"]);
NSLog(@"%@", [cfaddress objectForKey:@"Street"]);
// City and street present ?
if([cfaddress objectForKey:@"City"] && [cfaddress objectForKey:@"Street"]){
NSLog(@"STAD EN STRAAT");
}
else{
NSLog(@"GEEN STAD EN/OF STRAAT");
}
}
[self dismissModalViewControllerAnimated:YES];
return YES;
}
不幸的是,在 ios5 中自动引用计数会给我以下错误:
error: Automatic Reference Counting Issue: Implicit conversion of a non-Objective-C pointer type 'CFTypeRef' (aka 'const void *') to 'NSMutableDictionary *' is disallowed with ARC
我猜我这样做的方式(对于 ios4)无论如何都不是一个好方法,我真的很感激关于如何实现这一点的一些建议。提前致谢!
最佳答案
替换这个
cfaddress = ABMultiValueCopyValueAtIndex(address, i);
有了这个
cfaddress = [NSMutableDictionary dictionaryWithDictionary:(NSDictionary *)ABMultiValueCopyValueAtIndex(address, i)];
关于iphone - 使用带有 ARC 的 ios5 选择地址簿地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8537335/