问题
I'm new to iOS development so please bear with me..
I'm in the process of creating a simple app. There is a facebook button and I'd like that button to send the user to my facebook page, either in the browser or if they have the facebook app open that up.
I know there's probably a lot to explain, but if someone could point me in the right direction that would be great, thanks.
回答1:
As of the 4.0 update for Facebook, you can jump to pages with this URI schema:
fb://page/{fbid}
Just make sure you check to make sure that the device you're working with can respond to it:
[[UIApplication sharedApplication] canOpenURL:[NSURL urlWithString:@"fb://page/{fbid}"]];
Your method might end up looking something like this:
- (IBAction)openFBPage:(id)sender {
if ([[UIApplication sharedApplication] canOpenURL:[NSURL urlWithString:@"fb://page/{fbid}"]]) {
[[UIApplication sharedApplication] openURL:[NSURL urlWithString:@"fb://page/{fbid}"]];
} else {
NSLog(@"Facebook isn't installed.");
// or do the sensible thing and openURL the HTTP version of the page in safari
}
... and you'd link the above method with your button in Interface Builder.
回答2:
You need to download the FacebookSDK and follow the steps that are described over there. Check out this page https://developers.facebook.com/docs/getting-started/facebook-sdk-for-ios/3.1/
Hope helps...
来源:https://stackoverflow.com/questions/12680205/how-to-send-user-to-facebook-page-on-button-click