Open link to Facebook page from iOS app

前端 未结 8 1069
孤独总比滥情好
孤独总比滥情好 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:08

    For iOS 9, You must whitelist the url's that your app will call out to using the LSApplicationQueriesSchemes key in your Info.plist.

    Check here.

    <key>LSApplicationQueriesSchemes</key>
        <array>
         <string>fb</string>
         <string>fbapi</string>
         <string>fbauth2</string>
         <string>fbshareextension</string>
         <string>fb-messenger-api</string>
         <string>twitter</string>
         <string>whatsapp</string>
         <string>wechat</string>
         <string>line</string>
         <string>instagram</string>
         <string>kakaotalk</string>
         <string>mqq</string>
         <string>vk</string>
         <string>comgooglemaps</string>
        </array>
    
    0 讨论(0)
  • 2020-11-30 19:11

    // Swift 5, you can use this function to open fb page/profile

           func openFacebookPage() {
                let facebookURL = NSURL(string: "fb://profile/PageId")!
                if UIApplication.shared.canOpenURL(facebookURL as URL) {
                UIApplication.shared.open(facebookURL as URL)
            } else {
                UIApplication.shared.open(NSURL(string: 
                 "https://www.facebook.com/PageName")! as URL)
               }
          }
    //By Using PageId or name only
          func openFacebookPage(pageID:String) {
                let facebookURL = NSURL(string: "fb://profile/\(pageID)")!
                if UIApplication.shared.canOpenURL(facebookURL as URL) {
                UIApplication.shared.open(facebookURL as URL)
             } else {
                 UIApplication.shared.open(NSURL(string: "https://www.facebook.com/\ 
               (pageID)")! as URL)
             }
         }
    //By Using Url only
         func openFacebookPageURL(url:String) {
                   let facebookURL = NSURL(string: url)!
                   if UIApplication.shared.canOpenURL(facebookURL as URL) {
                   UIApplication.shared.open(facebookURL as URL)
                } else {
                   UIApplication.shared.open(NSURL(string: url)! as URL)
                }
            }
    
    0 讨论(0)
提交回复
热议问题