iOS Facebook SDK连接在iDevice上失败
问题描述:
我在iOS应用程序(ARC,在iOS 5上运行)中使用Facebook连接。它在模拟器和设备上都能正常工作,但自从今天上午它已经停止在设备上工作,它仍然可以在模拟器上工作。在设备上,我得到了名为fbDinNotLogin的方法。iOS Facebook SDK连接在iDevice上失败
现在,我知道差异是模拟器使用手机Facebook和我的应用程序使用本机iOS的Facebook应用程序,我也知道你可以调整facebook.m文件强制应用程序在别处做登录,但我不'不想这样做。
从昨天加载我以前的版本(一切工作正常)也给了我相同的结果。所以昨天运行的代码今天不运行。任何想法为什么会发生?下面是我的代理.m文件:
[EIDT]我从原生Facebook应用程序获得各种不同的行为。有时它会打开Facebook应用程序,并停留在那里不会回到我的应用程序。有时它也会快速返回到我的应用程序,而不允许Facebook应用程序询问我的许可。我很困惑。 [/编辑]
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions {
user *userClass= [[user alloc] init];
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"HasLaunchedOnce"])
{
// app already launched for the first time
}
else
{
// This is the first launch ever
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"HasLaunchedOnce"];
[[NSUserDefaults standardUserDefaults] synchronize];
[userClass CopyDbToDocumentsFolder];
}
facebook = [[Facebook alloc] initWithAppId:@"XXXXXXXXXX" 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];
}
return YES;
}
-(void)fbDidLogout
{
NSLog(@"Facebook loggedOut");
}
- (void)fbDidNotLogin:(BOOL)cancelled
{
NSLog(@"Facebook Connect Failed");
}
- (void)fbDidLogin {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:[facebook accessToken] forKey:@"FBAccessTokenKey"];
[defaults setObject:[facebook expirationDate] forKey:@"FBExpirationDateKey"];
[defaults synchronize];
}
- (void)fbSessionInvalidated
{
NSLog(@"Facebook Session Invalidated");
}
- (void)fbDidExtendToken:(NSString*)accessToken
expiresAt:(NSDate*)expiresAt
{
NSLog(@"Facebook Toekn was extended");
}
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
return [self.facebook handleOpenURL:url];
}
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication: (NSString *)sourceApplication annotation:(id)annotation {
return [self.facebook handleOpenURL:url];
}
- (void)applicationDidBecomeActive:(UIApplication *)application {
// Although the SDK attempts to refresh its access tokens when it makes API calls,
// it's a good practice to refresh the access token also when the app becomes active.
// This gives apps that seldom make api calls a higher chance of having a non expired
// access token.
[[self facebook] extendAccessTokenIfNeeded];
}
@end
答
原来的问题确实与Facebook,而不是我的应用程序!我的开发者帐户一直未能保存更改等,但现在又回到了工作状态。