Skip to content

Commit

Permalink
Avoid importing FBSDKLoginKit
Browse files Browse the repository at this point in the history
  • Loading branch information
Kostas Karayannis committed Sep 16, 2015
1 parent 7b2b22d commit 04d5457
Showing 1 changed file with 41 additions and 18 deletions.
59 changes: 41 additions & 18 deletions FacebookImagePicker/OLFacebookImagePickerController.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@

#import "OLFacebookImagePickerController.h"
#import "OLAlbumViewController.h"
#import <Bolts/Bolts.h>
#import <FBSDKCoreKit/FBSDKCoreKit.h>
#import <FBSDKLoginKit/FBSDKLoginKit.h>
//#import <FBSDKLoginKit/FBSDKLoginKit.h>

@interface OLFacebookImagePickerController () <OLAlbumViewControllerDelegate>
@property (nonatomic, strong) OLAlbumViewController *albumVC;
@property (assign, nonatomic) BOOL haveSeenViewDidAppear;
@end

@implementation OLFacebookImagePickerController
Expand All @@ -36,22 +36,45 @@ - (void)cancelButtonClicked{
}

- (void)viewDidAppear:(BOOL)animated{
if (![FBSDKAccessToken currentAccessToken]){
FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
[login
logInWithReadPermissions: @[@"public_profile"] fromViewController:self
handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
if (error) {
[self.delegate facebookImagePicker:self didFailWithError:error];
} else if (result.isCancelled) {
[self.delegate facebookImagePicker:self didFinishPickingImages:@[]];
} else {
OLAlbumViewController *albumController = [[OLAlbumViewController alloc] init];
self.albumVC = albumController;
self.albumVC.delegate = self;
self.viewControllers = @[albumController];
}
}];
if (![FBSDKAccessToken currentAccessToken] && !self.haveSeenViewDidAppear){
self.haveSeenViewDidAppear = YES;

//Workaround so that we dont include FBSDKLoginKit
NSArray *permissions = [NSArray arrayWithObject:@"public_profile"];
Class FBSDKLoginManagerClass = NSClassFromString (@"FBSDKLoginManager");
id login = [[FBSDKLoginManagerClass alloc] init];

SEL aSelector = NSSelectorFromString(@"logInWithReadPermissions:fromViewController:handler:");

if([login respondsToSelector:aSelector]) {
IMP imp = [login methodForSelector:aSelector];
id (*func)(id, SEL, id, id, id) = (void *)imp;
func(login, aSelector, permissions, self, ^(id result, NSError *error) {
if (error) {
[self.delegate facebookImagePicker:self didFailWithError:error];
} else if ([result isCancelled]) {
[self.delegate facebookImagePicker:self didFinishPickingImages:@[]];
} else {
OLAlbumViewController *albumController = [[OLAlbumViewController alloc] init];
self.albumVC = albumController;
self.albumVC.delegate = self;
self.viewControllers = @[albumController];
}
});
}
// [login logInWithReadPermissions: @[@"public_profile"] fromViewController:self
// handler:^(id result, NSError *error) {
// if (error) {
// [self.delegate facebookImagePicker:self didFailWithError:error];
// } else if ([result isCancelled]) {
// [self.delegate facebookImagePicker:self didFinishPickingImages:@[]];
// } else {
// OLAlbumViewController *albumController = [[OLAlbumViewController alloc] init];
// self.albumVC = albumController;
// self.albumVC.delegate = self;
// self.viewControllers = @[albumController];
// }
// }];
}
}

Expand Down

0 comments on commit 04d5457

Please sign in to comment.