0
我在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