0

I wanted to open Facebook and Twitter apps from my app. I find very simple way like:

NSURL *url = [NSURL URLWithString:@"fb://profile"];
[[UIApplication sharedApplication] openURL:url];

And there are many others url for open different page of Facebook. How can I check if Facebook app exist on iPhone? What happens if the application is not install on device? Now I try to use this method on iOS Simulator but nothing happened. It's bug of iOS Simulator? Only tomorrow I will have chance to check on device.

Neznajka
  • 305
  • 5
  • 19

2 Answers2

4

You can check if a URL would likely open ahead of time using the canOpenURL method of UIApplication.

http://developer.apple.com/library/ios/DOCUMENTATION/UIKit/Reference/UIApplication_Class/Reference/Reference.html#//apple_ref/occ/instm/UIApplication/canOpenURL:

Also! You can pass values for the facebook page you'd like. This Stack Overflow includes a link to a wiki with all the variations: Launching Facebook and Twitter application from other iOS app

Community
  • 1
  • 1
Billy Lazzaro
  • 476
  • 2
  • 13
3

If you know the URL scheme that the other app is using (e.g. fb:// for the Facebook app), you can first ask whether your UIApplication object can open such URLs in the first place, with canOpenURL:. You can use this, for instance, to decide whether to display a link at all, or whether to direct the user to Safari (with a normal web URL) instead.

As third-party apps cannot be installed on the Simulator as far as I know, the only way to test compatibility with them is on an actual device.

villapossu
  • 2,737
  • 4
  • 18
  • 19