Swift-taylored experience to integrate your app with Facebook. Including:
- Facebook Login - Authenticate people with their Facebook credentials.
- Share and Send Dialogs - Enable sharing content from your app to Facebook.
- App Events - Understand your audience and the performance of your app.
- Graph API - Read and write directly to Facebook social graph.
Getting Started
-
Add the following line to your Podfile:
pod 'FacebookCore' pod 'FacebookLogin' pod 'FacebookShare'
- Run
pod install - You are all set!
You may also exclude any of these dependencies, if you not need the features of those parts of the SDK.
-
Add the following line to your Cartfile:
github "facebook/Facebook-SDK-Swift"Run
carthage update.
This will fetch dependencies into aCarthage/Checkoutsfolder, then build each one.- On your application targets'
Generalsettings tab, in theLinked Frameworks and Librariessection:- Drag & drop the following frameworks from
Carthage/Buildfolder on disk: - At a minimum:
FacebookCore.frameworkFBSDKCoreKit.frameworkBolts.framework
- To use Login with Facebook:
FacebookLogin.frameworkFacebookCore.framework(and it's dependencies)
- To use Share and Send Dialogs
FacebookShare.frameworkFacebookCore.framework(and it's dependencies)
- Drag & drop the following frameworks from
On your application targets'
Build Phasestab:- Click
+icon and chooseNew Run Script Phase. - Create a script with a shell of your choice (e.g.
/bin/sh). Add the following to the script area below the shell:
/usr/local/bin/carthage copy-frameworksAdd the paths to the frameworks you want to use under
Input Files, for example:$(SRCROOT)/Carthage/Build/iOS/FacebookCore.framework $(SRCROOT)/Carthage/Build/iOS/FBSDKCoreKit.framework $(SRCROOT)/Carthage/Build/iOS/Bolts.framework
- Click
Using Facebook SDK as a sub-project
While not recommended, it is entirely possible for you to build the Facebook SDK for Swift outside of any dependency management system.
Note that you will have to manage updating this solution (as well as the dependencies on the Facebook SDK for iOS) on your own.
- Clone the repository.
- Add
FacebookSwift.xcodeprojas a sub-project to your applications' project. - Add the
FacebookCore.framework,FacebookLogin.framework, andFacebookShare.frameworkbuild products from the sub-project to your applicationsLink Frameworks and LibrariesandEmbedded Binariessections.
Don't forget to also embed/link
FBSDKCoreKit.framework,FBSDKLoginKit.framework,FBSDKShareKit.frameworkandBolts.frameworktoo!
Modules
The frameworks for the Facebook SDK in Swift are organized in the same way that the Facebook SDK for iOS is.
They also currently depend upon the Facebook SDK for iOS, although this may change at some point in the future.
FacebookCore
Depends on FBSDKCoreKit.framework and Bolts.framework.
The following types are included, with enhancements for Swift:
AccessTokenApplicationDelegateAppEventsA myriad of improvements, including type-safe built-in
AppEvents, anAppEventstruct, and more.GraphRequestYou can now implement your own type-safe
GraphRequests, including native-typed results.SDKSettingsLogging behaviors are now implemented as a type-safe set, based on Swift enums.
PermissionAre no longer stringly-typed (string-based), but separate types for read and write permissions (also includes a built-in permission list, which includes most common permissions by default).
FacebookLogin
Depends on FacebookCore.framework and FBSDKLoginKit.framework.
The following types are included, with enhancements for Swift:
LoginManagerNow uses the type-safe permissions from
FacebookCore, and has constructors withLoginBehaviorandDefaultAudience, instead of requiring manual setting of properties.LoginButtonCan no longer change permissions after creation, helping to enforce using a single login button for a given set of permissions. Note that
LoginButtonis not intended to work with interface builder or storyboards at this time. We may re-address this in the future.
FacebookShare
Depends on FacebookCore.framework and FBSDKShareKit.framework.
The following types are included, with enhancements for Swift:
LinkShareContentNow a struct, and has a proper initializer enforcing required properties.
OpenGraphShareContentNow a struct, uses type-safe
OpenGraphPropertyNameandOpenGraphPropertyValue, as well as structs forOpenGraphObjectandOpenGraphAction.PhotoShareContentNow a struct, and better type-safety for properties on it.
VideoShareContentNow a struct, and better type-safety for properties on it.
GraphSharerNow a generic type, that can handle any type of content.
ShareDialogNow a generic type, that can handle any type of content.
MessageDialogNow a generic type, that can handle any type of content.
GameRequestNow a struct, contains proper type-safe enum for
Recipient,Result.GameRequest.DialogAppGroupRequest.DialogAppInviteNow a struct, use a type-safe
Promotionproperty, instead of separatepromotionCodeandpromotionText.AppInvite.Dialog
Give Feedback
Facebook SDK in Swift is still in beta, and we would love to hear your thoughts and feedback on it.
- Have an idea or feature request? Open an issue. Tell us more about the feature or an idea and why you think it's relevant.
- Have a bug to report? Open an issue. If possible, include the version of the SDK you are using, and any technical details.
- Need help with your code? Join Facebook Developers Group on Facebook or ask questions on Stack Overflow.
Contribute
All of Facebook SDK for Swift development happens on GitHub. Contributions make for good karma and we welcome new contributors with tremendous joy. We encourage you also to read our contributing guidelines before submitting a Pull Request.
LICENSE
See the LICENSE file.