Story link flow using SSO facebook - openURL not being called

后端 未结 1 1295
后悔当初
后悔当初 2021-01-21 06:03

I have implemented Single-Sign-On in my iOS 4.3 app successfully. Now I want to publish a link to the users facebook wall so that when his/her friends that also own the app clic

相关标签:
1条回答
  • 2021-01-21 07:00

    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];
    
    0 讨论(0)
提交回复
热议问题