Contact Integration for Your Swift App

Contact Integration for Your Swift App

by 

| August 16, 2022 | in

iOS and Mac have built-in systems to house many things, such as contacts. If you are building software that has contacts, there is a good chance you will want to pull those system contacts and integrate them into your system.

So how does one go about integrating those contacts? The code to do so isn’t very complex.

The first step is to request access to contacts.

The next step is to retrieve the list of contacts and iterate over them. Pretty straightforward.

That seemed pretty straightforward, and in all honestly, it is. But we are not done yet. When we run this application, we will run into a problem. We won’t have access to contacts. We will receive an error like this:

UserInfo={NSLocalizedDescription=Access Denied, NSLocalizedFailureReason=This application has not been granted permission to access Contacts.}

We need to add a key and value to our plist.info file to work around this error. This is done through an editor (e.g., Xcode) nowadays.

Adding a key and value in Xcode

You need to add a key for “Privacy – Camera Usage Description” with the text you want the user to see when requesting access to contacts.

You see, not so difficult. Getting contacts from iOS or Mac isn’t too difficult and can help your application become more integrated with the user.

Full Code

References

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