1

Is there a way to open iOS/Android native Contacts application to show some specific contact?

I'm creating a Phonegap app that uses phone's contact list via the contacts plugin API. For users convenience I have a [Show contact] button that should switch to a native Contacts application on that specific contact.

Is it possible?

tillda
  • 18,150
  • 16
  • 51
  • 70

2 Answers2

5

Use a plug-in to go native via the browser javascript code. Here is an excellent guide for building a custom PhoneGap plugin for iOS. Its very well documented and you will find a lot of screenshots of every step.

If you want to go deep about the subject i recomend you to read this two documents in order:

  1. Apache Cordova Plugin Development Guide
  2. Apache Cordova iOS Plugins

If you need more assistance and have a more specific question i will be happy to help.

Francisco Félix
  • 2,413
  • 13
  • 16
  • Do you know for sure that it is possible to open a specific contact in the Contacts app by writing it as a native plugin in ObjC/Swift? – tillda Mar 18 '15 at 16:29
  • Once you call your native code you can do whatever you need. Use the ABPersonViewController class of the Address Book UI framework, it implements the view used to display a person record but remember that person view controllers must be used with a navigation controller in order to function properly. You can read a step by step explanation of the process and download the source of a full working example app here https://developer.apple.com/library/ios/documentation/ContactData/Conceptual/AddressBookProgrammingGuideforiPhone/Chapters/UI_Controllers.html#//apple_ref/doc/uid/TP40007744-CH5-SW1 – Francisco Félix Mar 18 '15 at 17:33
  • 1
    this is how the cordova plugin works, it let you choose the contact from the list, but you can't open the contacts app. There is no point of doing your own plugin, you can't open the contacts app – jcesarmobile Mar 19 '15 at 18:49
  • With ABPersonViewController you need to set the displayedPerson property to the person record you want to display, its not true that the user needs to choose anything. That happens with the ABPeoplePickerNavigationController which i didnt quote. The op asked for a way to switch from a browser phone app to a native contacts application on a specific contact. I presented a solution to do exactly that. – Francisco Félix Mar 20 '15 at 01:39
  • 1
    but you get the data of the person, you don't switch to the contacts app, the cordova contacts plugin already use ABPersonViewController – jcesarmobile Mar 22 '15 at 11:23
  • I have installed contacts plugin in android. How can i open the mobile contacts list – Mohaideen Ismail May 18 '15 at 11:36
2

This has been answered before here: how do I open iphone apps via phonegap

"The only way that one app, PhoneGap-based or otherwise, can cause another app to launch is to open an URL "

Opening Contacts:

You would need a "URL scheme" such as the one defined here:

// In config.xml
<gap:url-scheme>
    <scheme>app1scheme</scheme>
</gap:url-scheme>
Then from your other app you'll just have a link to app1scheme://, eg simply

<a href="app1scheme://">Start App1</a>

Contacts Database:

If you have not already, you can access the "Contacts database" using PhoneGap:

iOS (in the named application directory's config.xml)

<feature name="Contacts">
    <param name="ios-package" value="CDVContacts" />
</feature>

Source: http://docs.phonegap.com/en/edge/cordova_contacts_contacts.md.html#Contacts

Another Example, without PhoneGap(accessing the Calender):

<a href="calendar://">Click me!</a>

Now go to your iOS app's info.plist file. In that add the following tags:

<key>CFBundleURLTypes</key>
<array>
<dict>
    <key>CFBundleURLName</key>
    <string>com.companyname.appname</string>
    <key>CFBundleURLSchemes</key>
    <array>
        <string>calendar</string>
    </array>
</dict>
</array>
Save the plist file and exit it. After this when you open the web page in Safari browser of your iOS device and click on the link, your iOS app will invoke. I hope it helps!

Source: https://stackoverflow.com/a/7658785/950427

Community
  • 1
  • 1
Jared Burrows
  • 54,294
  • 25
  • 151
  • 185
  • 1
    Is there some way to opem a specific contact (for example by its id) in the Contacts app? – tillda Mar 16 '15 at 12:06
  • @tillda That is a good question. I am not sure about specific contacts. Check this PhoneGap example, why not access the data directly and keep them in your app? http://devcenter.appery.io/tutorials/using-the-contacts-component/. – Jared Burrows Mar 16 '15 at 12:09
  • 1
    You have basically performed a google search. That's not research. Have you worked with PhoneGap/Cordova before? You said: "You would need a "URL scheme" such as the one defined here". No. The URL scheme would have to be defined by the application: in this case, Android's Contacts app & iOS's Contacts app - user tillda clearly cannot modify system apps and add these schemes. If these schemes were already defined, and you would have found them, that would be research! Downvoted. – Athena Mar 22 '15 at 16:30
  • Ouch. I was just trying to help. You should calm down. Why waste your time? You will hurt your reputation more than it will hurt mine. – Jared Burrows Mar 22 '15 at 17:05
  • @Athena is right, this answer doesn't provide any valuable information and doesn't answer the question at all. I can believe it got 3 upvotes. – jcesarmobile Mar 23 '15 at 08:09
  • @jcesarmobile Once again, I was just try to aggregate important information that would help lead someone to the correct answer. – Jared Burrows Mar 23 '15 at 14:19