88
99#import " OLFacebookImagePickerController.h"
1010#import " OLAlbumViewController.h"
11- #import < Bolts/Bolts.h>
1211#import < FBSDKCoreKit/FBSDKCoreKit.h>
13- #import < FBSDKLoginKit/FBSDKLoginKit.h>
12+ // #import <FBSDKLoginKit/FBSDKLoginKit.h>
1413
1514@interface OLFacebookImagePickerController () <OLAlbumViewControllerDelegate>
1615@property (nonatomic , strong ) OLAlbumViewController *albumVC;
16+ @property (assign , nonatomic ) BOOL haveSeenViewDidAppear;
1717@end
1818
1919@implementation OLFacebookImagePickerController
@@ -36,22 +36,45 @@ - (void)cancelButtonClicked{
3636}
3737
3838- (void )viewDidAppear : (BOOL )animated {
39- if (![FBSDKAccessToken currentAccessToken ]){
40- FBSDKLoginManager *login = [[FBSDKLoginManager alloc ] init ];
41- [login
42- logInWithReadPermissions: @[@" public_profile" ] fromViewController: self
43- handler: ^(FBSDKLoginManagerLoginResult *result, NSError *error) {
44- if (error) {
45- [self .delegate facebookImagePicker: self didFailWithError: error];
46- } else if (result.isCancelled ) {
47- [self .delegate facebookImagePicker: self didFinishPickingImages: @[]];
48- } else {
49- OLAlbumViewController *albumController = [[OLAlbumViewController alloc ] init ];
50- self.albumVC = albumController;
51- self.albumVC .delegate = self;
52- self.viewControllers = @[albumController];
53- }
54- }];
39+ if (![FBSDKAccessToken currentAccessToken ] && !self.haveSeenViewDidAppear ){
40+ self.haveSeenViewDidAppear = YES ;
41+
42+ // Workaround so that we dont include FBSDKLoginKit
43+ NSArray *permissions = [NSArray arrayWithObject: @" public_profile" ];
44+ Class FBSDKLoginManagerClass = NSClassFromString (@" FBSDKLoginManager" );
45+ id login = [[FBSDKLoginManagerClass alloc ] init ];
46+
47+ SEL aSelector = NSSelectorFromString (@" logInWithReadPermissions:fromViewController:handler:" );
48+
49+ if ([login respondsToSelector: aSelector]) {
50+ IMP imp = [login methodForSelector: aSelector];
51+ id (*func)(id , SEL , id , id , id ) = (void *)imp;
52+ func (login, aSelector, permissions, self, ^(id result, NSError *error) {
53+ if (error) {
54+ [self .delegate facebookImagePicker: self didFailWithError: error];
55+ } else if ([result isCancelled ]) {
56+ [self .delegate facebookImagePicker: self didFinishPickingImages: @[]];
57+ } else {
58+ OLAlbumViewController *albumController = [[OLAlbumViewController alloc ] init ];
59+ self.albumVC = albumController;
60+ self.albumVC .delegate = self;
61+ self.viewControllers = @[albumController];
62+ }
63+ });
64+ }
65+ // [login logInWithReadPermissions: @[@"public_profile"] fromViewController:self
66+ // handler:^(id result, NSError *error) {
67+ // if (error) {
68+ // [self.delegate facebookImagePicker:self didFailWithError:error];
69+ // } else if ([result isCancelled]) {
70+ // [self.delegate facebookImagePicker:self didFinishPickingImages:@[]];
71+ // } else {
72+ // OLAlbumViewController *albumController = [[OLAlbumViewController alloc] init];
73+ // self.albumVC = albumController;
74+ // self.albumVC.delegate = self;
75+ // self.viewControllers = @[albumController];
76+ // }
77+ // }];
5578 }
5679}
5780
0 commit comments