Open link to Facebook page from iOS app

前端 未结 8 1119
孤独总比滥情好
孤独总比滥情好 2020-11-30 18:29

I want to redirect user to my App\'s Facebook page, so I have the following code:

[[UIApplication sharedApplication] openURL:
    [NSURL URLWithString: @\"ht         


        
8条回答
  •  星月不相逢
    2020-11-30 19:07

    You have to use the facebook ID for the given page rather than the vanity URL. To get the pages ID, enter your page's vanity name at the following URL and copy the value for "id":

    https://graph.facebook.com/yourappspage

    Once you have the id, you can set up the method to check if FB is installed using the canOpenURL method and serve the appropriate content for both states:

    NSURL *facebookURL = [NSURL URLWithString:@"fb://profile/113810631976867"];
    if ([[UIApplication sharedApplication] canOpenURL:facebookURL]) {
        [[UIApplication sharedApplication] openURL:facebookURL];
    } else {
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://facebook.com"]];
    }
    

提交回复
热议问题