在我的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!");
}
在我的appDelegate
中- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
return [facebook handleOpenURL:url];
}
我认为- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
应该在fbdidLogin
之前调用,但我无法完成此部分[facebook handleOpenURL:url];
,[[controller facebook] handleOpenURL:url];
将解决问题,
但我不能这样做。任何解决方案?
答案 0 :(得分:0)
在他们的文档中,他们建议您在应用代理中需要此功能。
https://developers.facebook.com/docs/mobile/ios/build/
当我第一次尝试这个时,我将它放在另一个用于与Internet源交互的对象中,但它无效。当我把它放在我的应用代表中时,它工作正常。我总结说,当他们说“修改应用程序委托...”时,他们真的意味着应用代表。