https://github.com/edurd/facebooktestswift
Using Facebook API to login and logout in Swift
https://github.com/edurd/facebooktestswift
Last synced: 2 months ago
JSON representation
Using Facebook API to login and logout in Swift
- Host: GitHub
- URL: https://github.com/edurd/facebooktestswift
- Owner: edurd
- Created: 2017-11-09T16:35:41.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2020-09-26T18:16:51.000Z (over 4 years ago)
- Last Synced: 2025-02-08T04:29:47.936Z (4 months ago)
- Language: Swift
- Size: 15.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# How to integrate Facebook API on Swift
Using Facebook API to login and logout in Swift#### Instalation
Run `pod install` after you clone the repo, then follow pods instructions like opening .xcworkspace from now on.
#### Facebook Configuration project
Open [Facebook Start guide](https://developers.facebook.com/docs/ios/getting-started/), This is the main guide to use the Facebook API.As the guide says, open [Facebook Project platform](https://developers.facebook.com/apps)
Create your project and a secret key, as the instructions say.
Follow the guide and configure your plist file, with the xml the Facebook gives you, according to your app id.
Once finish.
#### Code in your project
Add the following code on your viewDidLoad function on the ViewController class. This will make a button appear when you run your project.
```
override func viewDidLoad() {
super.viewDidLoad()
let loginButton = LoginButton(readPermissions: [ .publicProfile ])
loginButton.center = view.center
view.addSubview(loginButton)
}
```
Add the following code to AppDelegate file after adding the `import FacebookCore` at the top of the file
```
func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
let sourceApplication: String? = options[UIApplicationOpenURLOptionsKey.sourceApplication] as? String
return SDKApplicationDelegate.shared.application(app, open: url, sourceApplication: sourceApplication, annotation: options[UIApplicationOpenURLOptionsKey.annotation])
}
```
Modify your application didFinishLaunchingWithOptions function adding this line.
```
SDKApplicationDelegate.shared.application(application, didFinishLaunchingWithOptions: launchOptions)
```Run the project and you'll have the login working.