Share on Facebook IOS 11 Swift
Asked Answered
A

3

7

In versions below 11 ShareButton to facebook works successfull, but in 11 version this function doesn't work. What can u advice?

if SLComposeViewController.isAvailable(forServiceType: SLServiceTypeFacebook) {
        var vc: SLComposeViewController = SLComposeViewController(forServiceType: SLServiceTypeFacebook)
        vc.setInitialText("My text")
        self.present(vc, animated: true, completion: nil)
    }
Amyotonia answered 11/10, 2017 at 14:1 Comment(2)
You should use UIActivityViewController if you don't have your own share extensionStealthy
Look at this link #44880298 might be helpful.Provencal
F
16

You can use the facebook sdk to share content Like

Step 1:

install pod :- pod 'FacebookShare'

Step 2:

import FBSDKShareKit

Step 3:

func shareTextOnFaceBook() {
    let shareContent = ShareLinkContent()
    shareContent.contentURL = URL.init(string: "https://developers.facebook.com")! //your link
    shareContent.quote = "Text to be shared"
    ShareDialog(fromViewController: self, content: shareContent, delegate: self).show()
}

func sharer(_ sharer: Sharing, didCompleteWithResults results: [String : Any]) {
    if sharer.shareContent.pageID != nil {
        print("Share: Success")
    }
}
func sharer(_ sharer: Sharing, didFailWithError error: Error) {
    print("Share: Fail")
}
func sharerDidCancel(_ sharer: Sharing) {
    print("Share: Cancel")
}

Step 4: Must add this in Info.plist

<key>LSApplicationQueriesSchemes</key>
<array>
        <string>fbauth2</string>
</array>
Feininger answered 3/11, 2018 at 12:36 Comment(2)
In Step 3 Callback is not working, any ideas on how to solve?Warchaw
@Warchaw You should add "SharingDelegate" delegate.Scofflaw
C
3

All of social constants (facebook, twitter, LinkedIn and others) have been deprecated on iOS 11 .

See here: https://developer.apple.com/documentation/social/social_constants

You can use the FBSDKShareKit for the sharing function on facebook.

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

Columbite answered 12/10, 2017 at 15:51 Comment(0)
S
0

Now it's more easy and more reliable to share media in facebook using FBSDKShareKit. You can follow the link below for details tutorial.

Facebook, Messenger - Photo, Video, Link sharing in iOS Swift.

Skatole answered 9/6, 2021 at 17:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.