1

How can I open an app from my app in Swift? I need open contacts book to select the contact and save on my app, but I don't know how to do this.. I'm reading how read the contacts and show into a table view but not about how to open the contact book app. And also I'm reading how to open with UIApplication.sharedApplication() but I only show how to open urls...

There is some form to make this?

Thanks!

rmaddy
  • 314,917
  • 42
  • 532
  • 579
user3745888
  • 6,143
  • 15
  • 48
  • 97
  • if the targeted app supports URL-scemes, then it is piece of cake (without returning to your app, of course), otherwise you cannot do such thing without risking a possible rejection. – holex Aug 08 '14 at 09:18

2 Answers2

2

As with what @jtbandes posted, the only way to do this is with URL schemes. You have no access to launch/read other applications or settings unless your application shares the same bundle identifier as the others (Facebook + Facebook Messenger, for example would share these and be able to detec

drmarvelous
  • 1,663
  • 10
  • 18
  • Then I can convert this code to Swift to open facebook: //facebook if(![[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"fb://profile/181239321918026"]]) { [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"https://www.facebook.com/plungeinteractive"]]; } But what is the url to open the contacts app address books?? – user3745888 Aug 07 '14 at 21:25
  • Unfortunately as it stands right now there is no URL scheme for the Contacts application in iOS. – drmarvelous Aug 08 '14 at 19:13
0

Open contacts book is pretty simple. Here a nice tutorial that explain how to do that:

http://www.raywenderlich.com/63885/address-book-tutorial-in-ios

Also: in iOS 8, you can use the inter-app communication extension! It's a really nice feature. You can see that keynote video about this here: http://www.theverge.com/2014/6/2/5765048/apple-wwdc-2014-os-x-yosemite-ios-8-and-all-the-news-you-need-to-know

EDIT:

Here is my init method used in my app to present a controller which is the contacts tableView:

- (id)init
{
    self = [super init];
    if (self) {
        ABPeoplePickerNavigationController *picker = [ABPeoplePickerNavigationController new];

        ABAddressBookRef addressBook = ABAddressBookCreate();

        picker.addressBook = addressBook;
        picker.displayedProperties = @[[NSNumber numberWithInt:kABPersonAddressProperty]];
        picker.peoplePickerDelegate = self;

        if (addressBook != nil)
            CFRelease(addressBook);

        _controller = picker;
    }
    return self;
}

I don't know if this can help you. Anyway, don't forget to use appropriate new methods (not deprecated). I think there are small changes about ABAddressBookCreate();

Lapinou
  • 1,467
  • 2
  • 20
  • 39
  • This tutorial is approximately that I want make, but I want access to native app contacts, select a contact and show in my app. This is possible. Now I have the code to show all contact in an array, but not show this into native contacts book iphone.. Thanks!! – user3745888 Aug 07 '14 at 20:29
  • I've updated my post. Hope this help you to continue your app ;) If you have any questions, don't hesitate to ask ;) – Lapinou Aug 08 '14 at 09:01