Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/108.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 调用函数';ABRecordCopyValue';返回带有+;1保留计数_Ios_Objective C_Abaddressbook - Fatal编程技术网

Ios 调用函数';ABRecordCopyValue';返回带有+;1保留计数

Ios 调用函数';ABRecordCopyValue';返回带有+;1保留计数,ios,objective-c,abaddressbook,Ios,Objective C,Abaddressbook,我的项目中有以下代码 - (BOOL)peoplePickerNavigationController: (ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person { [popContactsForm dismissPopoverAnimated:YES]; [ssemailvc setName: (NSStri

我的项目中有以下代码

- (BOOL)peoplePickerNavigationController:
(ABPeoplePickerNavigationController *)peoplePicker
      shouldContinueAfterSelectingPerson:(ABRecordRef)person {

    [popContactsForm dismissPopoverAnimated:YES];

    [ssemailvc setName: (NSString *)ABRecordCopyValue(person,kABPersonFirstNameProperty)];        
    ABMultiValueRef emails = (NSString *)ABRecordCopyValue(person,kABPersonEmailProperty);


    if (ABMultiValueGetCount(emails)>0) {
        [ssemailvc setEmail:(NSString *)ABMultiValueCopyValueAtIndex(emails,0)];
    }else [ssemailvc setEmail:@""];

    CFRelease(emails);


    [peoplePicker dismissModalViewControllerAnimated:YES];      
    [popEmailForm setPopoverContentSize:CGSizeMake(350.0, 225.0)];

    return NO;
}
我收到了以下警告

1.调用函数“ABRecordCopyValue”返回一个具有+1保留计数的corefoundation对象 2.object泄漏:分配的对象在执行的后期未被引用,其保留计数为+1


请告诉我如何克服此问题

如果使用ARC,您可以使用桥接器:

CFStringRef name = (CFStringRef)ABRecordCopyValue(person,kABPersonFirstNameProperty);
[ssemailvc setName:(__bridge NSString*)name];
CFRelease(name);
或过桥:

NSString * name = (__bridge_transfer NSString *)ABRecordCopyValue(person,kABPersonFirstNameProperty);
[ssemailvc setName:name];

如果您正在使用MRC:

CFStringRef name = (CFStringRef)ABRecordCopyValue(person,kABPersonFirstNameProperty);
[ssemailvc setName:(NSString*)name];
CFRelease(name);

您看到此警告的原因是
ABRecordCopyValue
返回一个
CFStringRef
,其中
+1个retain count

试一试


不。我没有使用ARC。您是否尝试过下面发布的两个答案中的任何一个?我已将代码转换为ARC:[ssemailvc setName:(uuu bridge NSString*)ABRecordCopyValue(person,kabbersonfirstnameproperty)];ABMultiValueRef emails=(u桥ABMultiValueRef)(u桥NSString*)ABRecordCopyValue(person,kABPersonEmailProperty));如果(ABMultiValueGetCount(emails)>0){[ssemailvc setEmail:(\uu桥NSString*)ABMultiValueCopyValueAtIndex(emails,0)];}其他[ssemailvc setEmail:@'';发布(电子邮件);但它仍然显示出同样的问题1。你应该接受贾斯汀的回答。2.对于通过
ABMultiValueCopyValueAtIndex
检索的电子邮件,您也应该重复
CFRelease
过程。3.您向
NSString*
发送的
电子邮件的类型转换不正确,您应该删除该类型转换。
- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker
  shouldContinueAfterSelectingPerson:(ABRecordRef)person {

[popContactsForm dismissPopoverAnimated:YES];

CFStringRef strLname = ABRecordCopyValue(person, kABPersonLastNameProperty);
[ssemailvc setName: (NSString *) strLname];  

if(strLname){
CFRelease(strLname);
}

ABMultiValueRef emails = (NSString *)ABRecordCopyValue(person,kABPersonEmailProperty);


if (ABMultiValueGetCount(emails)>0) {
    [ssemailvc setEmail:(NSString *)ABMultiValueCopyValueAtIndex(emails,0)];
}else [ssemailvc setEmail:@""];

if(emails){
CFRelease(emails);
}

[peoplePicker dismissModalViewControllerAnimated:YES];      
[popEmailForm setPopoverContentSize:CGSizeMake(350.0, 225.0)];

return NO;
}