简体   繁体   中英

Facebook share button on iOS 9 opens browser instead of native Facebook app

My app uses an FBSDKShareButton , which launches a popup from the native Facebook app on iOS 8. However, on iOS 9 it launches a browser window, even though I've followed all the instructions for supporting iOS 9 here and added the necessary LSApplicationQueriesSchemes (and recompiled for iOS 9).

I keep reading that it's "by design" that the facebook login opens a browser instead of the native app on iOS 9, but there's no info on why/whether the share button is supposed to launch the native app. It appears that the share dialog ( FBSDKShareDialog ) indeed launches the native app, but I'd like to avoid using my own button if I can.

And a secondary question: if I do use my own button and launch an FBSDKShareDialog , I get the following errors in the log (although the actual sharing seems to work fine). Why?

-canOpenURL: failed for URL: "fbapi20150629:///" - error: "This app is not allowed to query for scheme fbapi20150629"

plugin com.apple.share.Facebook.post invalidated

I'm using the latest Facebook SDK (v4.6), so the referenced URL scheme should not be necessary. I'm compiling with Xcode 7.0.1.

I believe the problem is due to the FBSDKShareButton constructing a FBSDKShareDialog without a ViewController. And so without the VC, it is falling back to using the Safari view for sharing. :( You can see this behavior in the FB SDK source here:

https://github.com/facebook/facebook-ios-sdk/blob/fe777bd7a8b335c5780e2ee160d81719e132e76c/FBSDKShareKit/FBSDKShareKit/FBSDKShareButton.m

I've subclassed FBSDKShareButton to launch a dialog directly, which correctly uses the sharesheet for me, with a minimal amount of overriding code, and maintains the native look and feel (and localization) of the FBSDKShareButton:

public class EventShareButton: FBSDKShareButton {
    func _share(sender: AnyObject) {
        FBSDKShareDialog.showFromViewController(parentViewController(), withContent: shareContent, delegate: nil)
    }
}

Unfortunately, I have no answer to the fbapi20150629 warning, and my attempts to search for an answer are what led me here. :)

FBSDKShare , with iOS 9 , swift2.0

For first question: Facebook Share content can share url other than iTunes with content description. If iTunes url is shared it wont share our description.

I was having the same issue, FB Share button clicking redirects me to browser and the workaround I'm using is to set the Share Dialog mode to use the native app.

This occurs consistently if the URL you are sharing is an iTunes App Store URL. Changing the URL to any other website solved the problem. https://developers.facebook.com/docs/sharing/ios "Note: If your app share links to the iTunes or Google Play stores, we do not post any images or descriptions that you specify in the share. Instead we post some app information we scrape from the app store directly with the Webcrawler. This may not include images. To preview a link share to iTunes or Google Play, enter your URL into the URL Debugger."

     func shareFB(sender: AnyObject) {
        let content : FBSDKShareLinkContent = FBSDKShareLinkContent()

        content.contentURL = NSURL(string: "http://google.com")
        content.contentTitle = “MyApp”
        content.contentDescription = “//Desc“

        content.imageURL = NSURL(string:“//Image URL”)


        let dialog : FBSDKShareDialog = FBSDKShareDialog()
        dialog.mode = FBSDKShareDialogMode.Native
      // if you don't set this before canShow call, canShow would always return YES
        if !dialog.canShow() {
            // fallback presentation when there is no FB app
          dialog.mode = FBSDKShareDialogModeFeedBrowser
         }
        dialog.show()
     }

I am not certain that this solves your problem. To be honest I don't really understand the workings of this API very clearly - just a workable knowledge... but maybe this helps.

https://developers.facebook.com/docs/ios/ios9

For apps using the SDK v4.5 and earlier, insert the following into the app's info.plist

<key>LSApplicationQueriesSchemes</key>
<array>
    <string>fbapi</string>
    <string>fbapi20130214</string>
    <string>fbapi20130410</string>
    <string>fbapi20130702</string>
    <string>fbapi20131010</string>
    <string>fbapi20131219</string>    
    <string>fbapi20140410</string>
    <string>fbapi20140116</string>
    <string>fbapi20150313</string>
    <string>fbapi20150629</string>
    <string>fbauth</string>
    <string>fbauth2</string>
    <string>fb-messenger-api20140430</string>
</array>

In my case, it got rid of this error:

-canOpenURL: failed for URL: "fbapi20150629:///" - error: "This app is not allowed to query for scheme fbapi20150629"

and did not get rid of this message:

plugin com.apple.share.Facebook.post invalidated

(I am using the latest SDK, above v4.5)

Hope this is of some assistance.

For your first question: Facebook share content only shares URL in iOS 9

For your secondary question: It happened to me even though I have the new Facebook SDK (4.6.0), I added the string "fbapi20150629" also to the p.list ("Whitelist Facebook Apps").

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