CNContact添加新的联系人问题 [英] CNContact add new contact issue

查看:130
本文介绍了CNContact添加新的联系人问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在通过 Contact Framework 添加联系人时出现问题.

I'm faccing an issue at time of adding contacts throught Contact Framework.

我在iOS 12.1.2上使用了设备iPhone 5s

I used device iPhone 5s with iOS 12.1.2

我添加联系人的代码如下::

My Code for adding contact is as below ::

let saveRequest = CNSaveRequest()
saveRequest.add(self, toContainerWithIdentifier: nil)
do {
    try contactStore.execute(saveRequest)
} catch let error {
    print("Error occurred while saving the request \(error)")
}

每次都会发出如下错误::

This everytime thows error as below ::

保存请求时发生错误错误域= CNErrorDomain代码= 1通信错误" UserInfo = {NSLocalizedDescription =通信错误,NSLocalizedFailureReason =尝试与联系人服务通信时发生错误.}

Error occurred while saving the request Error Domain=CNErrorDomain Code=1 "Communication Error" UserInfo={NSLocalizedDescription=Communication Error, NSLocalizedFailureReason=An error occurred while trying to communicate with the Contacts service.}

现在就此错误给任何人做些什么吗?

Dose any one now anything about this error?

我对此一无所知.

推荐答案

要添加 CNcibtactStore 的单例,只需添加

To add the singleton for the CNcibtactStore just add

/**
 A var to store CNContactStore
 */
let mContactStore = CNContactStore.init()

内部 AppDelegate.swift 文件.

要在任何地方使用它,只需使用此代码

And to use it anywhere just use this code

 contactStore = appDelegate.mContactStore

这将为我解决问题,希望也能为您解决问题.

This will solve the issue for me and hopefully will solve the issue for you too.

这篇关于CNContact添加新的联系人问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆