简体   繁体   English

如何将我的 iOS 应用程序的默认联系人容器设置为保存在 iCloud 中的联系人容器?

[英]How do I set the default contacts container for my iOS app to the contacts container that is saved in iCloud?

I am writing an iOS app using Swift and Xcode 13.1.我正在使用 Swift 和 Xcode 13.1 编写 iOS 应用程序。 I am using the Contacts Framework, and I read that each app has a default contacts container, and the default container in an app can be different than the default container in another app, and there is not a default container for the entire device.我正在使用联系人框架,我读到每个应用程序都有一个默认的联系人容器,并且一个应用程序中的默认容器可以与另一个应用程序中的默认容器不同,并且整个设备没有默认容器。

What determines which is the default container for the app made by an Xcode project?什么决定了 Xcode 项目创建的应用程序的默认容器是什么? I didn't set the default container for my app and somehow the contacts container for a Google account became the default contacts container for my app.我没有为我的应用程序设置默认容器,并且不知何故,Google 帐户的联系人容器成为我的应用程序的默认联系人容器。 How do I use code to set the default contacts container for my app?如何使用代码为我的应用设置默认联系人容器?

How do I find out which is the default container of Apple's Contacts app that comes with iOS?如何找出 iOS 随附的 Apple 联系人应用程序的默认容器? I would like to set my app's default contacts container to the same default container of Apple's Contacts app, if that is the contacts container that is saved on iCloud.我想将我的应用程序的默认联系人容器设置为与 Apple 的联系人应用程序相同的默认容器,如果那是保存在 iCloud 上的联系人容器。 If not, I would like to set my app's default contacts container to the contacts container that is saved in iCloud.如果没有,我想将我的应用程序的默认联系人容器设置为保存在 iCloud 中的联系人容器。 I assume that only one contacts container is saved on iCloud.我假设只有一个联系人容器保存在 iCloud 上。

The user can specify the default contact container for new contacts in settings.用户可以在设置中为新联系人指定默认联系人容器。 Your app can access the identifier of this container using defaultContainerIdentifier .您的应用可以使用defaultContainerIdentifier访问此容器的标识符。

If you want to allow the user to specify a different container for new contacts created by your app, then you need to code that yourself.如果您想允许用户为您的应用创建的新联系人指定不同的容器,那么您需要自己编写代码。

You need to provide a view that displays the list of contact containers resulting from a call to containers(matching:nil) .您需要提供一个视图,该视图显示通过调用containers(matching:nil)产生的联系人容器列表。 Once the user selects a container, store its identifier in your apps preferences and use that container identifier when you create new contacts.用户选择容器后,将其标识符存储在您的应用首选项中,并在您创建新联系人时使用该容器标识符。

All you can know about a container is its identifier , its name and its type (Exchange, CalDAV or local).关于容器,您所能知道的只有它的identifiernametype (Exchange、CalDAV 或本地)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM