A simple image picker for Facebook written in Swift. Looks and works very similar to the native UIImagePickerController, except it uses a completion block instead of a delegate protocol.
- Xcode 9
- iOS 8.0+ target deployment
- FBSDKCoreKit, FBSDKLoginKit (>= 4.0)
- Swift 4 project
Add the following line to your Podfile:
pod "MBFacebookImagePicker"
Download the project or clone the repo. Import the MBImagePicker
folder into your project. Make sure you have the FBSDKCoreKit
, FBSDKCoreKit
, and Bolts
frameworks imported.
Enter the following line in your terminal:
pod try MBFacebookImagePicker
If you instead chose to download or clone the project directly, you must first run pod install
from the Example directory to install all dependencies.
Also make sure to replace FacebookAppID
under URL types
and FacebookAppID
in info.plist
.
Make sure that your application has been setup with the Facebook SDK.
Import the library:
import MBFacebookImagePicker
Show the picker:
let imagePicker = MBFacebookImagePickerController()
imagePicker.finishedCompletion = { [weak self] (result) in
self?.dismiss(animated: true, completion: nil)
switch result {
case .completed(let image): self?.imageView.image = image
case .failed(let error): print("failed with error: \(error)")
case .cancelled: print("Cancelled!")
}
}
present(imagePicker, animated: true, completion: nil)
Note that the app needs to have been authenticated with Facebook and given permission to access user_photos
before showing the image picker.
MBImagePicker uses the following translation keys:
"MBIMAGEPICKER_NO_ALBUMS_FOUND" = "No albums found";
"MBIMAGEPICKER_ALBUMS" = "Albums";
"MBIMAGEPICKER_ERROR_ALERT_TITLE" = "Ooops...";
"MBIMAGEPICKER_NETWORK_ERROR" = "Network unavailable, please try again";
"MBIMAGEPICKER_UNKNOWN_ERROR" = "Something went wrong, please try again";
"MBIMAGEPICKER_NO_PICTURES_FOUND" = "Could not find any pictures\nin your photo album";
"MBIMAGEPICKER_CANCEL" = "Cancel";
"MBIMAGEPICKER_OK" = "OK";
Add the keys to your localizable.strings
and modify the strings for you respective language(s).
MBFacebookImagePicker is available under the MIT license. See the LICENSE file for more info.