简体   繁体   中英

UIButton to open Facebook app

im trying to make a button that will exit my app and open up the facebook app (if available) to my apps profile. And I cant figure out how I would do this.

Get your button to call the following method when clicked:

- (void)buttonClicked:(id)sender {

    NSURL *url = [NSURL URLWithString:@"fb://profile/<your_profile_id>"];

    if ([[UIApplication sharedApplication] canOpenURL:url]) {
        [[UIApplication sharedApplication] openURL:url];
    }

}

If the Facebook app is installed on your device, then it should open to your profile.

Facebook app on the iPhone conforms to the fb:// URL pattern, fb://profile/{profile id number} will open the Facebook app to the specified profile id number

You could make your button open the URL specific to your apps profile.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM