Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Share on Facebook IOS 11 Swift

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)
    }
like image 886
Sasha Avatar asked Oct 11 '17 14:10

Sasha


People also ask

Does Facebook Work on iOS 11?

In iOS 11, Facebook, Twitter, Vimeo, and Flickr are treated the same as other apps. App permissions, contacts, calendar events, and other content will have to be added via the Share extension. This also means that Facebook and Twitter integration with Siri has changed.

Does Facebook use Swift?

Today, Facebook uses Swift to make it easier for developers to build their iOS-based apps and to improve user experience.


2 Answers

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>
like image 180
Jaydeep Vyas Avatar answered Sep 23 '22 02:09

Jaydeep Vyas


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/

like image 39
shilei365 Avatar answered Sep 20 '22 02:09

shilei365