1

CNAuthorizationStatus和相关文档似乎建议您需要获得读取或保存到 CNContactStore 的权限。(而且我已经阅读了大多数基于 CNContact 的问题,它们在该主题上非常一致)。

但我发现一个应用程序有一个“保存联系人”按钮,并显示一个看起来像CNContactViewController的联系人,当我按下保存时,该应用程序确实保存到联系人,但没有任何权限对话框(我从来没有给它权限) .

我卸载,重新安装并再次保存联系人,以确认。

有没有人这样做过?我在 iOS 11.4.1 上。

4

1 回答 1

1

I wrote an app that presents the Contact View for a new contact, and saves it to Contacts without:

The has been published in the app store for sometime now, as "DropCard".

The app also uses CNContactPickerViewController to select a single contact from the store, which interestingly says this:

The app using contact picker view does not need access to the user’s contacts and the user will not be prompted for “grant permission” access. The app has access only to the user’s final selection.

I conclude that similar-and-not-documented behavior is allowed for the creation of a single contact.

NOTE: This behavior does not allow a rogue app to programmatically jam large amounts of trash data into the Contacts store, because you still need the user to click on a button to save each new contact.

Here's the code I use for that portion

    let contact = CNMutableContact()

    let saveContactVC = CNContactViewController(forNewContact: contact)

    saveContactVC.contactStore = CNContactStore()
    saveContactVC.delegate = <your delegate here> as? CNContactViewControllerDelegate
    saveContactVC.allowsActions = false

    let navigationController = UINavigationController(rootViewController: saveContactVC)
    root.present(navigationController, animated: false)
    // NOTE: app *will* use right->left slide-over annimation...
    // then the 'animated: false' supresses the NavUI's top->new VC animation.
于 2020-11-23T08:24:18.873 回答