Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open Facebook url in Safari instead of native app

is there any way to open Facebook url (ex. http://www.facebook.com/facebook) in Safari instead of native app? I'm tried to do this:

NSURL *url = [NSURL URLWithString:@"http://www.facebook.com/facebook"];
[[UIApplication sharedApplication] openURL:url];

but iOS automatically launch native client (of course if it's installed) if you try to open url with in facebook domain. thanks.

like image 300
danylokos Avatar asked Mar 12 '13 01:03

danylokos


1 Answers

Ok, I think I found answer, you must replace "www.facebook.com" with "facebook.com" in url.

Something like this:

NSString *facebookUrlString = @"http://www.facebook.com/facebook";

if ([[facebookUrlString pathComponents] count] > 0) {
    if ([[facebookUrlString pathComponents][1] isEqualToString:@"www.facebook.com"]) {
        NSMutableArray *pathComponents = [[facebookUrlString pathComponents] mutableCopy];
        [pathComponents replaceObjectAtIndex:1 withObject:@"facebook.com"];
        facebookUrlString = [NSString pathWithComponents:pathComponents];
    }
}
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:facebookUrlString]];
like image 200
danylokos Avatar answered Oct 17 '22 06:10

danylokos