BT

InfoQ Homepage News Facebook Announces Open-Source Swift SDK Beta for iOS

Facebook Announces Open-Source Swift SDK Beta for iOS

Bookmarks

Now available in beta, Facebook’s new SDK for Swift aims to make it easier for developers to integrate Facebook services into their iOS apps.

Facebook Swift SDK for Swift includes support for a number of Facebook services, including Facebook Analytics, Facebook Login, Share for Facebook, and Facebook Graph API. It is based on the existing Objective-C Facebook SDK, around which it builds a collection of wrappers aiming to provide a native Swift API and easier developer experience.

Facebook Swift SDK includes support for the two most popular package management systems for iOS/macOS, CocoaPods and Carthage. To include it into your app using CocoaPods, ensure your Podfile looks something like this:

target "YourXcodeTargetNameHere" do

  use_frameworks!

  pod 'FacebookCore'
  pod 'FacebookLogin'
  pod 'FacebookShare'

  ## other pod files here as required
end

If you use Carthage, you can add the following line to your Cartfile:

github "facebook/Facebook-SDK-Swift"

Alternatively, you can include Facebook Swift SDK as a subproject into your Xcode project, although this approach will require you to take care of all dependencies, namely FBSDKCoreKit.framework, FBSDKLoginKit.framework, and FBSDKShareKit.framework, and their updates.

Facebook Swift SDK repo on GitHub includes a sample project showing how you can integrate supported services into your app. This is for example how you can share a photo using the provided ShareDialogViewController:

let photo = Photo(image: UIImage(named: "sky.jpg")!, userGenerated: true)
let content = PhotoShareContent(photos: [photo])

let dialog = ShareDialog(content: content)
dialog.presentingViewController = self
dialog.mode = .Automatic
do {
    try dialog.show()
} catch (let error) {
    let alertController = UIAlertController(title: "Invalid share content", message: "Failed to present share dialog with error \(error)")
    presentViewController(alertController, animated: true, completion: nil)
}

Facebook Swift SDK targets Swift 2.2.1 and 2.3, allowing thus developers to submit apps to the App Store, while support for Swift 3 is scheduled for later this year when Swift 3 reaches GM.

Rate this Article

Adoption
Style

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Community comments

  • Doesn't work

    by Dylan Fernando /

    Your message is awaiting moderation. Thank you for participating in the discussion.

    Unable to find a specification for `FacebookCore`

  • Your message is awaiting moderation. Thank you for participating in the discussion.

    your coding and sayings are really awesome and thus it is very much useful and it is highly relevant

  • Re: Doesn't work

    by James Hubert /

    Your message is awaiting moderation. Thank you for participating in the discussion.

    Have you figured this out? I'm having the same issue.

  • use_frameworks!

    by Joe Parks /

    Your message is awaiting moderation. Thank you for participating in the discussion.

    Have you tried it with the "use_frameworks!" directive?
    From the getting started guide:


    To use the SDK with CocoaPods, add the following lines to your Podfile:

    use_frameworks!

    pod 'FacebookCore'
    pod 'FacebookLogin'
    pod 'FacebookShare'

  • Re: Doesn't work

    by Sergio De Simone /

    Your message is awaiting moderation. Thank you for participating in the discussion.

    I guess you did not specify a target in your Podfile. That should go like this:


    target "testTarget" do
    use_frameworks!
    -- your cocoa pods here --
    end

  • Re: Doesn't work

    by Sergio De Simone /

    Your message is awaiting moderation. Thank you for participating in the discussion.

    Please, see my reply to Dylan Fernando. Hope it helps.

  • Re: Doesn't work

    by Fabiola Werneck /

    Your message is awaiting moderation. Thank you for participating in the discussion.

    Hey! Just update the cocoapods version using
    sudo gem install cocoapods
    command.

    Facebook SDK in Swift supports CocoaPods 1.0.1 or later.

    ;)

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

BT

Is your profile up-to-date? Please take a moment to review and update.

Note: If updating/changing your email, a validation request will be sent

Company name:
Company role:
Company size:
Country/Zone:
State/Province/Region:
You will be sent an email to validate the new email address. This pop-up will close itself in a few moments.