I want to redirect user to my App\'s Facebook page, so I have the following code:
[[UIApplication sharedApplication] openURL:
[NSURL URLWithString: @\"ht
After much testing I have found one of the most effective solutions:
NSString *facebookID = @"XXXXXXXXXX";
NSString *facebookURL = @"www.facebook.com/XXXXXXXX";
NSURL *urlModal = [NSURL URLWithString:[NSString stringWithFormat:@"fb://facewebmodal/f?href=%@", facebookURL]];
NSURL *urlWithID = [NSURL URLWithString:[NSString stringWithFormat:@"fb://page/%@", facebookID]]; // or "fb://profile/%@" or another type of ID
NSURL *url = [NSURL URLWithString:facebook_url];
if(facebookID && !facebookID.isEmpty && [[UIApplication sharedApplication] canOpenURL:urlWithID]) {
// open facebook app with facebookID
[[UIApplication sharedApplication] openURL:urlWithID];
} else if (facebookURL && !facebookURL.isEmpty && [[UIApplication sharedApplication] canOpenURL:urlModal]) {
// open facebook app with facebookUrl
[[UIApplication sharedApplication] openURL:urlModal];
} else if (![[UIApplication sharedApplication] openURL:url]) {
// somehow open
NSLog(@"%@%@",@"Failed to open url:",[url description]);
}
Order of sentences "if else" vary to your liking ...
Enjoy it!! :-)