iphone - 使用带有 ARC 的 ios5 选择地址簿地址

标签 iphone objective-c ios ios5 automatic-ref-counting

作为 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/

相关文章:

iphone - 每隔x分钟在后台检查一次条件,如果为true,则发送通知

iphone - 如何制作全局数组?

iphone - 添加用户界面标签

ios - 有没有办法从 Apple Developer Portal 中实际删除设备?

objective-c - Cocoapods 安装具有 subspec 的 pod 不起作用

objective-c - 在 Objective-C 中记录错误的更简洁的方法

android - 从 Android、iOS 设备管理 Amazon SNS 主题、订阅和推送通知

ios - Node.js 使用的 websocket 版本是哪个?

ios - 永远不应触发嵌套优化。这可能是由于自动布局工作发生在 NSISVariable 委托(delegate)回调中

ios - 调试 xcode 4 : says it's running application on device, 但实际上什么也没发生