Story link flow using SSO facebook - openURL not being called

落花浮王杯 提交于 2019-12-01 21:27:49

You need to have your facebook instace in AppDelegate for example:

@interface FacebookAppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;

@property (strong, nonatomic) UINavigationController *navigationController; 
@property (nonatomic, strong) Facebook *facebook;

@end

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary     *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    self.viewController = [[FacebookViewController alloc] initWithNibName:@"FacebookViewController" bundle:nil];

    self.facebook = [[Facebook alloc] initWithAppId:kAppId andDelegate:(id)self.viewController];

    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    if ([defaults objectForKey:@"FBAccessTokenKey"] && [defaults objectForKey:@"FBExpirationDateKey"]) {
        self.facebook.accessToken = [defaults objectForKey:@"FBAccessTokenKey"];
        self.facebook.expirationDate = [defaults objectForKey:@"FBExpirationDateKey"];
    }

    self.window.rootViewController = self.viewController;
    [self.window makeKeyAndVisible];
    return YES;
}

And inside AppDelegate you have to implement:

- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
    return [self.facebook handleOpenURL:url];
}

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
    return [self.facebook handleOpenURL:url];
}

And if you want to implement protocol in your own class you have to call facebook on this:

FacebookAppDelegate *fbAppDelegate = (FacebookAppDelegate *)[[UIApplication sharedApplication] delegate]; 
NSArray *permissions = [[NSArray alloc] initWithObjects:@"publish_stream",@"create_event",@"offline_access", nil];

[[fbAppDelegate facebook] authorize:permissions];
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!