swift – 在附加电话号码时联系框架崩溃应用程序
发布时间:2020-12-14 04:30:25 所属栏目:百科 来源:网络整理
导读:在尝试更新现有联系人时,我收到sigabrt错误“提取联系人时未请求属性”. var cntct= existingContact.mutableCopy() as! CNMutableContactlet phone= CNLabledValue(label:CNLabelPhoneNumberMain,value:"786967655566") cntct.phoneNumbers.append(phone)
在尝试更新现有联系人时,我收到sigabrt错误“提取联系人时未请求属性”.
var cntct= existingContact.mutableCopy() as! CNMutableContact let phone= CNLabledValue(label:CNLabelPhoneNumberMain,value:"786967655566") cntct.phoneNumbers.append(phone) 解决方法
我一直在与自己的相关问题苦苦挣扎几个小时:我需要为swift的联系人添加生日.通过一些研究,试验和错误以及故障排除,以下是我提出的建议:
var contactStore = CNContactStore() var contactx:CNMutableContact = CNMutableContact() let predicate = CNContact.predicateForContactsMatchingName("(firstnamefield.text!) (lastnamefield.text!) (suffixfield.text!)") // searches for contacts matching the inserted name (inputted by the user as first name,then last name,then any suffixes). let toFetch = [CNContactBirthdayKey] do{ var contacts = try contactStore.unifiedContactsMatchingPredicate( predicate,keysToFetch: toFetch) print(contacts) for contact in contacts { let birthday = NSDateComponents() birthday.year = Int(yearfield.text!)! // sets the birthday year birthday.month = Int(monthfield.text!)! // sets the birthday month birthday.day = Int(dayfield.text!)! // sets the birthday day let mutableContact = contact.mutableCopy() as! CNMutableContact mutableContact.birthday = birthday // sets the contacts found with predicate search to having the birthday set above. let saveRequest = CNSaveRequest() saveRequest.updateContact(mutableContact) try contactStore.executeSaveRequest(saveRequest) 显然,这会增加生日而不是电话号码,但您可以使用完全相同的原则(谓词搜索,联系人中的联系人)来添加电话号码;只是改变联系人循环中联系人内部发生的事情!我希望这会对你有所帮助,抱歉你没有早点得到答复. 基本上,您可以更改联系循环内部的内容 let phone= CNLabledValue(label:CNLabelPhoneNumberMain,value:"786967655566") cntct.phoneNumbers.append(phone) 你应该有一个电话号码添加过程. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- ORACLE 11g 创建数据库时 Enterprise Manager配置失败的解决
- c# – WCF和多个主机头
- 获得postgreSQL的当前周
- reactjs – React Material UI – 导出多个更高阶的组件
- cocostudio scrollview裁切bug
- xml – XSLT apply-template select中的“@ * | node()”是
- c#重构两个几乎相同的方法
- Metasploit CVE-2015-5122 Flash漏洞利用检测试验
- c – 奇怪的未定义的行为与棘手的lambda表达式
- c# – 为什么我不能在类中使用HttpServerUtility.HtmlEncod