问题标签 [cncontactstore]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
249 浏览

swift - UNNotificationServiceExtension 退出调用 CNContactStore enumerateContacts

我正在使用 UNNotificationServiceExtension 将电话号码替换为通知中的名称。我正在尝试在 CNContactStore 中查找电话号码并将 Ph# 替换为联系人姓名。

我的问题是,当我调用 CNContactStore enumerateContacts(with: keysToFetch: )时,扩展程序会退出,而不会从enumerateContacts调用中返回。

另一方面,如果我调用 CNContactStore 的UnifiedContacts(matching: predicate, keysToFetch: keys)它会按预期返回。但是,不幸的是,此呼叫找不到电话号码。我发现查找电话号码的唯一方法是调用enumerateContacts

我使用相同的代码在我的应用程序中查找电话号码,它工作正常。我还可以在没有问题的情况下替换通知扩展中的文本。仅当我尝试在 Extension中调用enumerateContacts时才会出现此问题。

0 投票
0 回答
83 浏览

ios - 在群组中创建联系人

我想创建一个功能,其中一些联系人将保存在用户的手机中。现在我知道使用联系人框架,我可以保存联系人。这是我一直在使用的。

但我真正想要的是用我的应用程序名称创建一个组,假设XYZ和我的代码应该检查该组 XYZ 是否已经存在新联系人应该保存在那里,否则创建联系人组并将联系人保存在那里。

提前致谢!

0 投票
2 回答
531 浏览

ios - 逐部分阅读联系人(ios)

我已经阅读了使用的联系方式CNContact.framework,如下

在上面的代码中,我一次读取了所有的联系人。假设我有 10000 个联系人,所有 10K 联系人将立即加载到内存中。有什么方法可以让我通过提供offsetand来获取联系人limit

假设我想从中获取联系人0-100,然后101-200...

提前致谢。

0 投票
1 回答
243 浏览

ios - 将电子邮件添加到 CNMutableContact 错误

我正在尝试使用以下代码将电子邮件添加到我的联系信息中以将其存储在本地设备上,不幸的是该代码使应用程序崩溃。我该如何解决这个问题?Objective-C在所有示例中,我在网上都看不到任何内容Swift

0 投票
1 回答
728 浏览

macos - dispatch_get_main_queue crashes in a method called a second time

I have a ViewController which fetch data in AddressBook. To be notified when data has been fetched, I post a notification to this ViewController to allow it to update a NSViewTable (in the main queue).This ViewController is presented with a transient NSPopover, when a user ends editing a NSTextField in the ViewController view.

When I enter a first string in this field, the popover is displayed then is closed when the user has finishing interacting with it. If I edit again the Text Field, the Popover do not appear in view, but the fetching process starts. When it ends and the DataUpdated method devoted to the notification post is fired. Then I got a crash on the dispatch_sync(dispatch_get_main_queue(), ^{ line itself (no message in console, even with NSZombie enabled). Here is the code in the popover content ViewController:

Any idea of what's happen? The error message in the source code is Thread 1: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)

The Backtrace is:

0 投票
0 回答
777 浏览

swift - 观察接触变化

嗨,我试图观察联系人列表中的变化。在视图控制器中,我设置了接收联系人更改事件的通知。

但是 addressBookDidChange 从来没有被调用过,有人知道为什么吗?来自苹果:

联系人更改通知 保存成功后,联系人存储会向默认通知中心发布 CNContactStoreDidChange 通知。如果您缓存任何 Contacts 框架对象,您需要通过它们的标识符或使用最初用于获取它们的谓词重新获取这些对象,然后释放缓存的对象。请注意,缓存的对象是陈旧的,但不是无效的。

https://developer.apple.com/documentation/contacts

0 投票
0 回答
80 浏览

ios - 无法更改 CNContactViewController forNewContact 中的个人资料图片,当联系人已存在于电话联系人中时

我正在尝试从我的应用程序中添加一个带有个人资料图片的新联系人,该联系人号码已经存在于我的手机电话簿和其他个人资料图片中。CNContactViewController 没有显示我在 CNMutableContact 中形成的图像。

它仅显示电话簿联系人中存在的图像,并且无法更改 CNContactViewController forNewContact 中的个人资料图片,当联系人已存在于电话联系人中时。

创建新联系人:

呈现 CNContactViewController:

0 投票
0 回答
56 浏览

ios - CNContact 缺少新的谓词方法

我正在使用 CNContactStore 和 predicateForContacts(matchingName:)。我需要实现另外两种新类型的方法。我看到以下方法

添加时不编译并且在框架中找不到。任何人都可以帮助我如何让这个东西工作吗?

0 投票
1 回答
122 浏览

swift - 如何获取新创建的联系人的contact.identifier

我试图从一个应用程序创建一个标识符,但我做不到。

提前致谢

0 投票
1 回答
87 浏览

swift - 更新数组中的电话联系人单项

我正在尝试更新 iphone 联系人中的 1 个单项。我正在更新电子邮件数组,不想影响数组中的其他人。

例如,我正在从我的应用程序中更改“家庭”电子邮件地址,但如果他们的手机联系人中也有“工作”电子邮件,它会删除它并只放入新的。我需要将所有其他字段保留在数组中。电话或地址相同。

这是我的更新:

这会添加家庭电子邮件,但会清除工作电子邮件或阵列中的任何其他内容。