简体   繁体   中英

Unable to implement facebook integration in iphone app

I am working on iphone facebook application. I am going through facebook connect tutorial on developer.facebbok.com. I did perfectly what mentioned in tutorial. But as per the tutorial there are log in and cancel button showing and in my application only "Okay" button showing on the right side of top bar. What is wrong happening here? Flow is like this. 1. Tap on tableview cell 2. Open facebookcontroller. 3. In view did load method of facebookcontroller I added tutorial code.

MyConnectViewController.m

- (void)viewDidLoad
{
    [super viewDidLoad];

        facebook = [[Facebook alloc]initWithAppId:@"353076241375240" andDelegate:self];
        NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
        if ([defaults objectForKey:@"FBAccessTokenKey"] 
        && [defaults objectForKey:@"FBExpirationDateKey"]) {
        facebook.accessToken = [defaults objectForKey:@"FBAccessTokenKey"];
        facebook.expirationDate = [defaults objectForKey:@"FBExpirationDateKey"];
        }
        if (![facebook isSessionValid])
        {
        [facebook authorize:nil];


        }


    // Do any additional setup after loading the view, typically from a nib.
}
- (void) fbDidLogout {
    // Remove saved authorization information if it exists
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    if ([defaults objectForKey:@"FBAccessTokenKey"]) {
        [defaults removeObjectForKey:@"FBAccessTokenKey"];
        [defaults removeObjectForKey:@"FBExpirationDateKey"];
        [defaults synchronize];
    }
}
- (void)fbDidLogin {
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    [defaults setObject:[facebook accessToken] forKey:@"FBAccessTokenKey"];
    [defaults setObject:[facebook expirationDate] forKey:@"FBExpirationDateKey"];
    [defaults synchronize];

}

MyConnectAppDelegate.m

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

I want to start from login screen of facebook.

Use sharekit and make your life a lot easier :-)

happy coding!!

The Okay button appears when you are logged in but not authorised. Try resetting the simulator or logging out Facebook then try again.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM