Can't return type callbacks for 3

2023-12-14 14:18
文章标签 type return callbacks

本文主要是介绍Can't return type callbacks for 3,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

转载自:http://victorchee.github.io/blog/address-book-in-ios/

iOS中使用通讯录

App开发中用到通讯录的不多,现在接到个同步通讯录的需求,所以研究了一下通讯录开发,总结如下,设计到联系人的读取,修改和删除。

@interface AddressBookViewController ()
{ABAddressBookRef addressBookRef;
}
@end

请求权限

addressBookRef = ABAddressBookCreate();
ABAddressBookRequestAccessWithCompletion(addressBookRef, ^(bool granted, CFErrorRef error) {dispatch_async(dispatch_get_main_queue(), ^{if (granted) {CFIndex localContactsCount = ABAddressBookGetPersonCount(addressBookRef);} else {// failed}});
});

读取所有联系人

CFArrayRef localContacts = ABAddressBookCopyArrayOfAllPeople(addressBookRef);
for (int i = 0; i < CFArrayGetCount(localContacts); ++i) {ABRecordRef person = CFArrayGetValueAtIndex(localContacts, i);NSString *firstName = (NSString *)ABRecordCopyValue(person, kABPersonFirstNameProperty);NSString *lastName = (NSString *)ABRecordCopyValue(person, kABPersonLastNameProperty);ABMutableMultiValueRef personEmail = ABRecordCopyValue(person, kABPersonEmailProperty);for (int j = 0; j < ABMultiValueGetCount(personEmail); ++j) {NSString *emailLabel = (NSString *)ABAddressBookCopyLocalizedLabel(ABMultiValueCopyLabelAtIndex(personEmail, j));NSString *email = (NSString *)ABMultiValueCopyValueAtIndex(personEmail, j);}ABMultiValueRef personPhone = ABRecordCopyValue(person, kABPersonPhoneProperty);for (int j = 0; j < ABMultiValueGetCount(personPhone); ++j){NSString *phoneLabel = (NSString *)ABAddressBookCopyLocalizedLabel(ABMultiValueCopyLabelAtIndex(personPhone, j));NSString *phone = (NSString *)ABMultiValueCopyValueAtIndex(personPhone, j);}NSData *image = (NSData*)ABPersonCopyImageData(person);// 其他字段依此类推
}
CFRelease(localContacts);

写入联系人

ABRecordRef person = ABPersonCreate();NSString *firstName = @"First Name";
ABRecordSetValue(person, kABPersonFirstNameProperty, (__bridge CFTypeRef)firstName, NULL);NSString *lastName = @"Last Name";
ABRecordSetValue(person, kABPersonLastNameProperty, (__bridge CFTypeRef)lastName, NULL);NSString *phoneNumber = @"13212312312";
NSString *phoneLabel = @"Home";
ABMutableMultiValueRef phone = ABMultiValueCreateMutable(kABMultiStringPropertyType);
ABMultiValueAddValueAndLabel(phone, (__bridge CFTypeRef)phoneNumber, (__bridge CFTypeRef)phoneLabel, NULL);
ABRecordSetValue(person, kABPersonPhoneProperty, phone, NULL);BOOL addSuccess = ABAddressBookAddRecord(addressBookRef, person, NULL);
if (addSuccess) {BOOL saveSuccess = ABAddressBookSave(addressBookRef, NULL);
}

如果报错Can’t return type callbacks for 3,检查ABMutableMultiValueRef创建的时候是否传入的是kABMultiStringPropertyType。

删除联系人

CFArrayRef localContacts = ABAddressBookCopyArrayOfAllPeople(addressBookRef);
for (int i = 0; i < CFArrayGetCount(localContacts); ++i) {ABRecordRef person = CFArrayGetValueAtIndex(localContacts, i);NSString *personFirstName = (NSString *)ABRecordCopyValue(person, kABPersonFirstNameProperty);if ([personFirstName isEqualToString:@"First Name"]) {ABAddressBookRemoveRecord(addressBookRef, person, NULL);BOOL saveSuccess = ABAddressBookSave(addressBookRef, NULL);}
}
CFRelease(localContacts);

这篇关于Can't return type callbacks for 3的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/492844

相关文章

Oracle type (自定义类型的使用)

oracle - type   type定义: oracle中自定义数据类型 oracle中有基本的数据类型,如number,varchar2,date,numeric,float....但有时候我们需要特殊的格式, 如将name定义为(firstname,lastname)的形式,我们想把这个作为一个表的一列看待,这时候就要我们自己定义一个数据类型 格式 :create or repla

Caused by: org.hibernate.MappingException: Could not determine type for: org.cgh.ssh.pojo.GoodsType,

MappingException:这个主要是类映射上的异常,Could not determine type for: org.cgh.ssh.pojo.GoodsType,这句话表示GoodsType这个类没有被映射到

try -catch-finally的理解,同时在try-catch-finally中含有return和throws的理解

在没有try-catch或try-catch-finally的情况下,程序正常执行到某行,在这行报错后,这行后面的代码就不执行了,程序就停止了,中断了。 例如   在有try-catch或try-catch-finally 情况上,在某行执行错误,在try中这行下的代码不执行,try外的代码执行。当然是catch在没有做处理的情况下。如果catch中做了处理,在不影响当前程序下,try

王立平--AES加密图片实现 SkImageDecoder::Factory return null

这个问题是在加密图片,存入sd卡,在解密出来展示,出现的。我个人研究了很久没解决。最后经过高人指点,终于解决了。 在此,拿出来分享,希望各位少走弯路。 我之前的设计思路是:(可以不看哦) 1.把图片从drawable读入成bitmap 2.bitmap-->byte 3.调用AES的byte加密算法。 4.加密成byte,在转化为string 5,把string存入sd卡。

兔子--The method setLatestEventInfo(Context, CharSequence, CharSequence, PendingIntent) from the type

notification.setLatestEventInfo(context, title, message, pendingIntent);     不建议使用 低于API Level 11版本,也就是Android 2.3.3以下的系统中,setLatestEventInfo()函数是唯一的实现方法。  Intent  intent = new Intent(

AI模型:追求全能还是专精?-- 之6 语言复杂度类别(Category 0~3 类)和语言功能性类型(Type 0~Ⅲ 型)之2

Q17、我前面说过,语言复杂度的0~3级(Category 0~3)表示了语言的的上下文相关性 : 完全不相关, 单相关的 单词上下文, 双相关的句子上下文 全相关的文章上下文 。我准备翻译为 Context - irrelative /relative/correlative/ full-correlative,显式表达了语言复杂度的0~3级(Category 0~3)区别的上下文相关性是一种关

【TS高频面试题】interface与type的区别

参考文章 一、基本概念 1. type(类型别名) 用来给一个类型起新名字,使用 type 创建类型别名。 2. interface(接口) 专门用于定义对象的结构(比如属性和方法) 二、相同点 (1)都可以描述对象或函数 interface interface User {name: stringage: number}interface SetUser {(name: st

ssh登录服务器报错“no matching host key type found. Their offer: ssh-rsa,ssh-dss”解决方法

这个错误表明你尝试使用 ssh 连接到远程服务器时,客户端和服务器之间没有匹配的 host key 类型。具体来说,远程服务器提供了 ssh-rsa 和 ssh-dss 类型的 host key,但你的 SSH 客户端配置可能不再支持这些较旧的算法。最近的 OpenSSH 版本默认禁用了不够安全的算法,如 ssh-rsa 和 ssh-dss。 解决方法 临时启用 ssh-rsa: 你可以在

Numpy中type()、ndim、shape、size、dtype、astype的用法

目录 numpy基础介绍示例分析及总结:itemsize、nbytes函数 numpy基础介绍 Numpy 补充了Python语言所欠缺的数值计算能力,是其它数据分析及机器学习库的底层库。因其完全标准C语言实现,运行效率充分优化。最重要一点是开源免费。numpy的核心是矩阵(即多维数组)。 示例 import numpy as nparr =np.array([[1,2,3]

struts2 result type= redirect redirectAction chain dispatcher等类型

struts.xml <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE struts PUBLIC     "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"     "http://struts.apache.org/dtds/struts-2.0.