In my ViewController
- (IBAction)loginBtn:(id)sender
{
facebook = [[Facebook alloc] initWithAppId:@"231190276934148" 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]) {
NSArray *permissions = [[NSArray alloc] initWithObjects:
@"user_likes",
@"user_about_me",
@"user_photos",
@"friends_about_me",
@"friends_activities",
@"read_stream",
@"publish_stream",
nil];
[facebook authorize:permissions];
}
NSLog(@"asdoiffijd");
}
- (IBAction)btnRequest:(id)sender
{
[facebook requestWithGraphPath:@"me/friends" andDelegate:self];
}
- (void)fbDidLogin
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:[facebook accessToken] forKey:@"FBAccessTokenKey"];
[defaults setObject:[facebook expirationDate] forKey:@"FBExiprationDateKey"];
[defaults synchronize];
NSLog(@"fbDidLogin!");
}
In my appDelegate
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
return [facebook handleOpenURL:url];
}
I think - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation should be called before the fbdidLogin but I can’t complete this part [facebook handleOpenURL:url];
in stackoverflow, [[controller facebook] handleOpenURL:url]; will resolve problem,
but i can’t do this. Any solution?
In their documentation, they suggest that you need this in your app delegate.
https://developers.facebook.com/docs/mobile/ios/build/
When I first tried this, I putting it in another object that I use for interacting with Internet sources and it didn’t work. When I put it in my app delegate, it worked fine. I concluded that when they say “Modify the application delegate …”, they really mean the app delegate.