Ich habe viele Fragen über die Facebook-Login gelesen, aber bis ich nicht gelang es mein Problem zu lösen. Ich habe bisher ein paar Apps gemacht, aber bisher habe ich noch nie mit der AppDelegate zu tun gehabt.facebook fbDidLogin außerhalb appdelegate
Die Sache ist, dass ich die fbDidLogin-Methode, die in meiner Klasse anders als Delegate ist, aufrufen möchte.
Bis jetzt wird fbDidLogin in der AppDelegate aufgerufen, aber ich möchte in der Lage sein, die Ansicht zu ändern und nach der Anmeldung nach Benutzerinformationen zu fragen.
Mein Code so weit: AppDelegate:
- (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];
}
Meine eigene Klasse mit der Schaltfläche Facebook Login:
- (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];
}
mir leid, wenn dies nicht klar ist, wenn Sie mehr Informationen benötigen, lassen Sie mich kennt.
Super ... gute Idee .. !! –