in my iOS App, i want to open a certain facebook page in the safari browser upon clicking a button. I do this in the app in this way:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"https://www.facebook.com/myapp"]];
this works if the native facebook app is not installed on the device. But if it is, the facebook app opens instead of safari (and it shows only whatever is currently open in the app, for example the users newsfeed).
I want that in any case the url is opened in the safari browser (at least as long as it's not about jailbroken devices which tampered with the browsers).
How can I achieve this?
我最终通过转发到www.fb.com而不是www.facebook.com解决了该问题
Do 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]];
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.