You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

215 lines
8.5 KiB

6 years ago
  1. # Facebook SDK in Swift (Beta)
  2. [![Platforms](https://img.shields.io/cocoapods/p/FacebookCore.svg)]()
  3. [![Swift Version](https://img.shields.io/badge/Swift-4.0.x-orange.svg)]()
  4. [![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)]()
  5. [![Build Status](https://img.shields.io/travis/facebook/facebook-sdk-swift/master.svg?style=flat)](https://travis-ci.org/facebook/facebook-sdk-swift)
  6. Swift-taylored experience to integrate your app with Facebook. Including:
  7. - [Facebook Login](https://developers.facebook.com/docs/swift/login) - Authenticate people with their Facebook credentials.
  8. - [Share and Send Dialogs](https://developers.facebook.com/docs/swift/sharing) - Enable sharing content from your app to Facebook.
  9. - [App Events](https://developers.facebook.com/docs/swift/appevents) - Understand your audience and the performance of your app.
  10. - [Graph API](https://developers.facebook.com/docs/swift/graph) - Read and write directly to Facebook social graph.
  11. ## Getting Started
  12. - **[CocoaPods](https://cocoapods.org)**
  13. - Make sure you are running the latest version of CocoaPods by running:
  14. ```bash
  15. gem install cocoapods
  16. # (or if the above fails)
  17. sudo gem install cocoapods
  18. ```
  19. _We support any version of CocoaPods 1.0.1 or later._
  20. - Update your local specs repo by running:
  21. ```bash
  22. pod repo update
  23. ```
  24. _This step is optional, if you updated the specs repo recently._
  25. - Add the following lines to your Podfile:
  26. ```ruby
  27. pod 'FacebookCore'
  28. pod 'FacebookLogin'
  29. pod 'FacebookShare'
  30. ```
  31. - Run `pod install`
  32. - You are all set!
  33. You may also exclude any of these dependencies, if you do not need the features of those parts of the SDK.
  34. - **[Carthage](https://github.com/carthage/carthage)**
  35. - Make sure you are running the latest version of Carthage by running:
  36. ```bash
  37. brew update
  38. brew upgrade carthage
  39. ```
  40. _We recommend using Carthage version 0.17.2 or later._
  41. - Add the following line to your Cartfile:
  42. ```
  43. github "facebook/Facebook-SDK-Swift"
  44. ```
  45. - Run `carthage update`.
  46. _This will fetch dependencies into a `Carthage/Checkouts` folder, then build each one._
  47. - On your application targets' `General` settings tab, in the `Linked Frameworks and Libraries` section:
  48. - Drag & drop the following frameworks from `Carthage/Build` folder on disk:
  49. - At a minimum:
  50. - `FacebookCore.framework`
  51. - `FBSDKCoreKit.framework`
  52. - `Bolts.framework`
  53. - To use Login with Facebook:
  54. - `FacebookLogin.framework`
  55. - `FacebookCore.framework` (and its dependencies)
  56. - To use Share and Send Dialogs
  57. - `FacebookShare.framework`
  58. - `FacebookCore.framework` (and its dependencies)
  59. - On your application targets' `Build Phases` tab:
  60. - Click `+` icon and choose `New Run Script Phase`.
  61. - Create a script with a shell of your choice (e.g. `/bin/sh`).
  62. - Add the following to the script area below the shell:
  63. ```
  64. /usr/local/bin/carthage copy-frameworks
  65. ```
  66. - Add the paths to the frameworks you want to use under `Input Files`, for example:
  67. ```
  68. $(SRCROOT)/Carthage/Build/iOS/FacebookCore.framework
  69. $(SRCROOT)/Carthage/Build/iOS/FBSDKCoreKit.framework
  70. $(SRCROOT)/Carthage/Build/iOS/Bolts.framework
  71. ```
  72. - **Using Facebook SDK as a sub-project**
  73. While not recommended, it is entirely possible for you to build the Facebook SDK for Swift outside of any dependency management system.
  74. Note that you will have to manage updating this solution (as well as the dependencies on the Facebook SDK for iOS) on your own.
  75. - Clone the repository.
  76. - Run the following command in the root directory of the repository: `git submodule update --init --recursive`
  77. - Add `FacebookSwift.xcodeproj` as a sub-project to your applications' project.
  78. - Add the `FacebookCore.framework`, `FacebookLogin.framework`, and `FacebookShare.framework` build products from the sub-project to your applications `Link Frameworks and Libraries` and `Embedded Binaries` sections.
  79. Don't forget to also embed/link `FBSDKCoreKit.framework`, `FBSDKLoginKit.framework`, `FBSDKShareKit.framework` and `Bolts.framework` too!
  80. ## Modules
  81. The frameworks for the Facebook SDK in Swift are organized in the same way that the Facebook SDK for iOS is.
  82. They also currently depend upon the Facebook SDK for iOS, although this may change at some point in the future.
  83. ### FacebookCore
  84. [![FacebookCore on CocoaPods](https://img.shields.io/cocoapods/v/FacebookCore.svg)](https://cocoapods.org/pods/FacebookCore)
  85. Depends on `FBSDKCoreKit.framework` and `Bolts.framework`.
  86. The following types are included, with enhancements for Swift:
  87. - `AccessToken`
  88. - `ApplicationDelegate`
  89. - `AppEvents`
  90. A myriad of improvements, including type-safe built-in `AppEvent`s, an `AppEvent` struct, and more.
  91. - `GraphRequest`
  92. You can now implement your own type-safe `GraphRequest`s, including native-typed results.
  93. - `SDKSettings`
  94. Logging behaviors are now implemented as a type-safe set, based on Swift enums.
  95. - `Permission`
  96. Are 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).
  97. ### FacebookLogin
  98. [![FacebookCore on CocoaPods](https://img.shields.io/cocoapods/v/FacebookLogin.svg)](https://cocoapods.org/pods/FacebookLogin)
  99. Depends on `FacebookCore.framework` and `FBSDKLoginKit.framework`.
  100. The following types are included, with enhancements for Swift:
  101. - `LoginManager`
  102. Now uses the type-safe permissions from `FacebookCore`, and has constructors with `LoginBehavior` and `DefaultAudience`, instead of requiring manual setting of properties.
  103. - `LoginButton`
  104. Can no longer change permissions after creation, helping to enforce using a single login button for a given set of permissions.
  105. Note that `LoginButton` is not intended to work with interface builder or storyboards at this time. We may re-address this in the future.
  106. ### FacebookShare
  107. [![FacebookCore on CocoaPods](https://img.shields.io/cocoapods/v/FacebookShare.svg)](https://cocoapods.org/pods/FacebookShare)
  108. Depends on `FacebookCore.framework` and `FBSDKShareKit.framework`.
  109. The following types are included, with enhancements for Swift:
  110. - `LinkShareContent`
  111. Now a struct, and has a proper initializer enforcing required properties.
  112. - `OpenGraphShareContent`
  113. Now a struct, uses type-safe `OpenGraphPropertyName` and `OpenGraphPropertyValue`, as well as structs for `OpenGraphObject` and `OpenGraphAction`.
  114. - `PhotoShareContent`
  115. Now a struct, and better type-safety for properties on it.
  116. - `VideoShareContent`
  117. Now a struct, and better type-safety for properties on it.
  118. - `GraphSharer`
  119. Now a generic type, that can handle any type of content.
  120. - `ShareDialog`
  121. Now a generic type, that can handle any type of content.
  122. - `MessageDialog`
  123. Now a generic type, that can handle any type of content.
  124. - `GameRequest`
  125. Now a struct, contains proper type-safe enum for `Recipient`, `Result`.
  126. - `GameRequest.Dialog`
  127. - `AppGroupRequest.Dialog`
  128. - `AppInvite`
  129. Now a struct, use a type-safe `Promotion` property, instead of separate `promotionCode` and `promotionText`.
  130. - `AppInvite.Dialog`
  131. ## Give Feedback
  132. Facebook SDK in Swift is still in beta, and we would love to hear your thoughts and feedback on it.
  133. - **Have an idea or feature request?** [Open an issue](https://github.com/facebook/facebook-sdk-swift/issues/new). Tell us more about the feature or an idea and why you think it's relevant.
  134. - **Have a bug to report?** [Open an issue](https://github.com/facebook/facebook-sdk-swift/issues/new). If possible, include the version of the SDK you are using, and any technical details.
  135. - **Need help with your code?** Join [Facebook Developers Group](https://www.facebook.com/groups/fbdevelopers) on Facebook or ask questions on [Stack Overflow](https://facebook.stackoverflow.com).
  136. ## Contribute
  137. All of Facebook SDK for Swift development happens on GitHub.
  138. Contributions make for good karma and we welcome new contributors with tremendous joy.
  139. We encourage you also to read our [contributing guidelines](https://github.com/facebook/facebook-sdk-swift/blob/master/CONTRIBUTING.md) before submitting a Pull Request.
  140. ## LICENSE
  141. See the [`LICENSE`](https://github.com/facebook/facebook-sdk-swift/blob/master/LICENSE) file.