OceanLabs / FacebookImagePicker-iOS

A Facebook image picker providing a simple UI for a user to pick photos from a users Facebook account. It provides an image picker interface that matches the iOS SDK's UIImagePickerController.
https://www.kite.ly
MIT License
103 stars 56 forks source link

Swift 2.0 and XCode 7: Use of undeclared type 'OLFacebookImagePickerControllerDelegate' #12

Closed 25matt12 closed 8 years ago

25matt12 commented 8 years ago

Hi,

I tried to implement your library in my project using swift 2.0 and XCode 7 but when I try to compile I get the following error message: "Use of undeclared type 'OLFacebookImagePickerControllerDelegate'".

I double checked my bridging header but everything seems to look fine, I use other libraries that are included in this header and to be sure I included every .h that I found:

#import <FacebookImagePicker/OLFacebookImagePickerController.h>
#import <FacebookImagePicker/OLFacebookAlbumRequest.h>
#import <FacebookImagePicker/OLFacebookPhotosForAlbumRequest.h>
#import <FacebookImagePicker/OLFacebookAlbum.h>
#import <FacebookImagePicker/OLFacebookImage.h>
#import <FacebookImagePicker/OLFacebookImagePickerController.h>

I included the library using cocapod (0.39.0.beta.4) using "use_frameworks!" flag and targeted iOS 8.0. I tried to compile the application under the iPhone 6s simulator on iOS 8.0.

When I use "import FacebookImagePicker" it looks like everything is working but when the controller loads it shows me nothing except a black screen with a navigationBar titled "Photos" and a "done" button.

If I try to touch the button nothing happens ...

I specified that the controller that launch the pickerViewController has inherited from the OLFacebookImagePickerControllerDelegate and UINavigationControllerDelegate protocols and is set delegate of the pickerViewController.

I tried to print something in all the protocol's methods I could implement but nothing has showed up despite the fact that my user is logged in the app with facebook SDK 4.6.0

Do you have any idea of what is happening ? Did I make a mistake including the library ?

Thank you.

mlequeux commented 8 years ago

Hi, I had the same problems, here is what you need to make it work :

In your bridging header you only need to add :

#import <FacebookImagePicker/OLFacebookImagePickerController.h>

Then your Swift class needs to conforms to the following protocols :

OLFacebookImagePickerControllerDelegate, UINavigationControllerDelegate 

To make the done (and the cancel button working), you need to dismiss yourself the imagePicker :

    func facebookImagePicker(imagePicker: OLFacebookImagePickerController!, didFinishPickingImages images: [AnyObject]!) {
        ...
        self.imagePicker.dismissViewControllerAnimated(true, completion: nil)
    }

    func facebookImagePickerDidCancelPickingImages(imagePicker: OLFacebookImagePickerController!) {
        ...
        self.imagePicker.dismissViewControllerAnimated(true, completion: nil)
    }

Finally you need a bit of checking due to swift code generation if you want to limit the number of selectable images (This is for one image max):

    func facebookImagePicker(imagePicker: OLFacebookImagePickerController!, shouldSelectImage image: OLFacebookImage!) -> Bool {
        if imagePicker.selected == nil {
            return true;
        } else if imagePicker.selected.count == 0 {
            return true;
        } else {
            return false;
        }
    }

Also, if nothing is displayed, try to check on the FB Graph Explorer for the following query using your Facebook token :

me/albums?limit=100&fields=id,name,count,cover_photo

If the resulting array is empty, that's probably because you forgot to add the user_photos permission at the time of login in your app.

25matt12 commented 8 years ago

Okay, so I finally found the origin of the issue and it was because there was a bug when using the library in swift with cocoapods and the "use frameworks!" flag.

The owner has committed an update and now everything is working properly ! :)

Thanks.