How do I specify that a CNContactStore in a framework project request access from an App Group instead of from the framework's default container?

I need to be able to access Contacts in a framework without requesting access to it from the framework, but requesting access to Contacts from within my app, so that by the time I access Contacts from my framework, request for access would have been done from within the app. I suspect the way to do this is to create an App Group. How would I go about specifying that the CNContactStore object be associated with the shared App Group instead of with the framework's container?

Replies

Access to contacts is covered by asking for permission from the user, but that request can come from your framework calling requestAccess(for:completionHandler:). Regardless if the request for access comes from a framework or the app, the usage description string to describe why you need access to contacts must be in the main app's Info.plist.


App Groups are about shared storage between apps you control - sharing access with multiple apps you ship, or between an app and its app extensions. A framework doesn't have a sandboxed container, as frameworks aren't binaries that execute independently. They are loaded by a process which is either the app or an app extension, and that's what defines the sandbox boundaries. If you only need the data in the main app and no app extensions, an App Group isn't strictly necessary.

So if I have already received permission from the user for my app to access their Contacts and then code in my framework in that app accesses Contacts, the code in my framework would not have to get permission again because the user already granted access for the app. Is that what you mean?

That's correct.