Objective c facebook FBD在appdelegate外部登录
我已经读过很多关于facebook登录的问题,但在此之前,我没有成功地解决我的问题。到目前为止,我已经制作了一些应用程序,但我以前从未弄乱过appDelegate 问题是,我想调用我的类中的fbDidLogin方法,而不是delegate 到目前为止,appDelegate中正在调用fbdilogin,但我希望能够在登录后更改视图并请求用户信息 到目前为止,我的代码是: AppDelegate:Objective c facebook FBD在appdelegate外部登录,objective-c,facebook,facebook-graph-api,login,delegates,Objective C,Facebook,Facebook Graph Api,Login,Delegates,我已经读过很多关于facebook登录的问题,但在此之前,我没有成功地解决我的问题。到目前为止,我已经制作了一些应用程序,但我以前从未弄乱过appDelegate 问题是,我想调用我的类中的fbDidLogin方法,而不是delegate 到目前为止,appDelegate中正在调用fbdilogin,但我希望能够在登录后更改视图并请求用户信息 到目前为止,我的代码是: AppDelegate: - (BOOL)application:(UIApplication *)application d
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
facebook = [[Facebook alloc] initWithAppId:SHKCONFIG(facebookAppId) andDelegate:self];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
if ([defaults objectForKey:@"FBAccessTokenKey"]
&& [defaults objectForKey:@"FBExpirationDateKey"]) {
facebook.accessToken = [defaults objectForKey:@"FBAccessTokenKey"];
facebook.expirationDate = [defaults objectForKey:@"FBExpirationDateKey"];
}
return YES;
}
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
return [facebook handleOpenURL:url];
}
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
{
return [facebook handleOpenURL:url];
}
// This one is called correctly
- (void)fbDidLogin {
NSLog(@"[DELEGATE] Deu login!");
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:[facebook accessToken] forKey:@"FBAccessTokenKey"];
[defaults setObject:[facebook expirationDate] forKey:@"FBExpirationDateKey"];
[defaults synchronize];
}
我自己的类与facebook登录按钮:
- (void)loginFacebook {
if (![facebook isSessionValid]) {
NSLog(@"[LOGIN] Facebook session invalid");
NSArray * permissions = [[NSArray alloc] initWithObjects:
@"email",
@"user_birthday",
nil];
[facebook authorize:permissions];
[permissions release];
} else {
NSLog(@"[LOGIN] Facebook session valid");
[facebook requestWithGraphPath:@"me" andDelegate:self];
}
}
// I want this one to work so I can ask for user info at the end of it
- (void)fbDidLogin {
NSLog(@"[LOGIN][FB] Deu login!");
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:[facebook accessToken] forKey:@"FBAccessTokenKey"];
[defaults setObject:[facebook expirationDate] forKey:@"FBExpirationDateKey"];
[defaults synchronize];
[facebook requestWithGraphPath:@"me" andDelegate:self];
}
如果这不清楚,我很抱歉,如果您需要更多信息,请告诉我。您可以发布来自应用程序代表的通知,如下所示:
- (void)fbDidLogin {
[[NSNotificationCenter defaultCenter] postNotificationName:@"FBDidLoginCalled" object:nil];
}
然后在你的另一节课上:
- (void)loginFacebook {
if (![facebook isSessionValid]) {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(fbDidLoginNotificationFired) name:@"FBDidLoginCalled" object:nil]
NSLog(@"[LOGIN] Facebook session invalid");
NSArray * permissions = [[NSArray alloc] initWithObjects:
@"email",
@"user_birthday",
nil];
[facebook authorize:permissions];
[permissions release];
} else {
NSLog(@"[LOGIN] Facebook session valid");
[facebook requestWithGraphPath:@"me" andDelegate:self];
}
}
// I want this one to work so I can ask for user info at the end of it
- (void)fbDidLoginNotificationFired {
[[NSNotificationCenter defaultCenter] removeObserver:self name:@"FBDidLoginCalled" object:nil];
NSLog(@"[LOGIN][FB] Deu login!");
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:[facebook accessToken] forKey:@"FBAccessTokenKey"];
[defaults setObject:[facebook expirationDate] forKey:@"FBExpirationDateKey"];
[defaults synchronize];
[facebook requestWithGraphPath:@"me" andDelegate:self];
}
您可以发布来自应用程序代理的通知,如下所示:
- (void)fbDidLogin {
[[NSNotificationCenter defaultCenter] postNotificationName:@"FBDidLoginCalled" object:nil];
}
然后在你的另一节课上:
- (void)loginFacebook {
if (![facebook isSessionValid]) {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(fbDidLoginNotificationFired) name:@"FBDidLoginCalled" object:nil]
NSLog(@"[LOGIN] Facebook session invalid");
NSArray * permissions = [[NSArray alloc] initWithObjects:
@"email",
@"user_birthday",
nil];
[facebook authorize:permissions];
[permissions release];
} else {
NSLog(@"[LOGIN] Facebook session valid");
[facebook requestWithGraphPath:@"me" andDelegate:self];
}
}
// I want this one to work so I can ask for user info at the end of it
- (void)fbDidLoginNotificationFired {
[[NSNotificationCenter defaultCenter] removeObserver:self name:@"FBDidLoginCalled" object:nil];
NSLog(@"[LOGIN][FB] Deu login!");
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:[facebook accessToken] forKey:@"FBAccessTokenKey"];
[defaults setObject:[facebook expirationDate] forKey:@"FBExpirationDateKey"];
[defaults synchronize];
[facebook requestWithGraphPath:@"me" andDelegate:self];
}
我通过在-loginFacebook上添加以下代码来管理它:
myIphoneAppDelegate * MyAppDelegate = (myIphoneAppDelegate*)[[UIApplication sharedApplication] delegate];
MyAppDelegate.loginController = self;
然后,我在appDelegate上创建了登录控制器的属性,然后调用控制器-fbdilogin:
- (void)fbDidLogin {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:[facebook accessToken] forKey:@"FBAccessTokenKey"];
[defaults setObject:[facebook expirationDate] forKey:@"FBExpirationDateKey"];
[defaults synchronize];
[self.loginController fbDidLogin];
}
我通过在-loginFacebook上添加以下代码来管理它:
myIphoneAppDelegate * MyAppDelegate = (myIphoneAppDelegate*)[[UIApplication sharedApplication] delegate];
MyAppDelegate.loginController = self;
然后,我在appDelegate上创建了登录控制器的属性,然后调用控制器-fbdilogin:
- (void)fbDidLogin {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:[facebook accessToken] forKey:@"FBAccessTokenKey"];
[defaults setObject:[facebook expirationDate] forKey:@"FBExpirationDateKey"];
[defaults synchronize];
[self.loginController fbDidLogin];
}