I had this demo built to allow reading from the IOS contacts using Delphi Firemonkey. It allows you to access the name, phone number, and email addresses on the user’s mobile device in your application using Apple’s native APIs. If you have not already done so you will need to import the AddressBook and AddressBookUI frameworks into Delphi XE5 to be able to compile this demo. Also see the Android Contacts Manager demo for accessing contacts on your Android device.
Update: Keep in mind that your app must first request permission to access the contacts list. I used TDPFAddressBook to do that in my production project and here is the code.
Can you give a more detailed explanation of what you mean by ” import the AddressBook and AddressBookUI frameworks into Delphi XE5″?
Thanks
Here are the instructions from DPF IOS (http://sourceforge.net/projects/dpfdelphiios/):
Add this frameworks in the SDK Manager (see Frameworks.png picture after installing)
/System/Library/Frameworks/AddressBookUI
/System/Library/Frameworks/AddressBook
Tools -> Options -> SDK Manager -> Scroll down remote paths listview ->Go Frameworks section -> Select one of framework item (e.g: select /System/Library/Frameworks/UIKit) -> click Add the new path item
————————————–
In XE5 You must be add $(SDKROOT) the beginning of each path on remote machine value
like this: [ $(SDKROOT)/System/Library/Frameworks ]
————————————–
2-1)
path on remote machine : /System/Library/Frameworks
Framework name: AddressBookUI
include subdirectories: unchecked
Add again:
2-2)
path on remote machine : /System/Library/Frameworks
Framework name: AddressBook
include subdirectories: unchecked
after Ok dialog, click Update local File Cache button.
Thanks for the reply – I followed the instructions and the app compiled to my IPhone without error, however, it did not read my contacts into the listbox. The listbox showed “ContactsList(0)” at the top. Is there something else I need to do to for the app to find the contacts on my phone?
Thanks,
Glenn
Glenn,
Yeah I don’t really know. You can debug the source yourself in iOSContactsManager.pas in the procedure TiOSContactsManager.ExtractContacts;. It does some explicit stuff in there like if it doesn’t have an email or phone it may not return anything. Are you on IOS6 or 7? My main test here was with an iPod on IOS6.
Thanks.
IOS6 on an iPhone 5.
There is one hint/warning during the compile – directory not found for option -‘LC:\Users\kelhedadi.DOCUMALIS\Downloads\DPF.iOS.Native.Components.v7.46’
Are there some native components I should have installed to make this work?
Thanks,
Glenn
I don’t think that error is related as I have a similar error. The demo should be stand alone so you shouldn’t need anything like DFP to make it work. How many contacts are in your device? Do they have phone numbers and/or emails?
I have around 150 contacts and they all have either a phone number and/or email address. I loaded the app on my phone with the Delphi debugger and stepped through the FormCreate lines. After fiOSContactManager.ExtractContacts. I checked the value of fiOSContactManager.ContactsCount and it was zero.
Thanks for your help!
Glenn
I think it may have something to do with granting access. The Privacy settings should have a request from the app to access the contacts – but I do not see that request being made on my phone. (Settings->Privacy->Contacts)
You’re right. In my production project I used TDPFAddressBook to request permission. I have updated this post to include that code.
http://stackoverflow.com/questions/16478053/how-to-ask-for-permission-to-access-iphone-contacts-adressbook-again
Thanks for your help – I got it working. However, the email address is not showing in the details. There may be a problem in extracting the emails from the array of emails.
There are multiple email fields and phone fields in IOS. For my purposes I just needed the first mobile number and email address. You may want to walk through all of the fields to get access to the others.
How do I edit a contact?