我正在将我的iOS应用程序与Parse和Facebook集成.它在我的iPhone 4s上工作正常 - 运行iOS 6 - 但是当我在我的xCode 5模拟器上尝试测试帐户时它失败了.
当我用facebook按钮登录时,我会看到一个屏幕说:你已经授权Test999(我的应用程序名称.)当我打电话给这一行时,就会发生这种情况:
[PFFacebookUtils logInWithPermissions:permissionsArray block:^(PFUser *user, NSError *error)
我按OK.它将我发送到"您必须先登录"屏幕.我输入了我的用户名和密码,然后按下登录状态 - 我将被发送回您已经授权的Test999.我按OK - 我看到一个空白视图,左上方有一个x来关闭它.没有别的事可做,所以我推它,我被送回"你必须先登录"屏幕.
因此,无法使用模拟器登录.我试图"重置内容和设置",但它没有帮助.
关于类似问题的答案后,我尝试添加一个reconnectWithFb方法(下面),我还将我的Facebook sdk更新到版本3.9.什么都没有帮助.
这是我用facebook方法登录的:
[PFFacebookUtils logInWithPermissions:permissionsArray block:^(PFUser *user, NSError *error) { if (!user) { if (!error) { NSLog(@"Uh oh. The user cancelled the Facebook login."); UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"User cancelled facebook login" message:@"Uh oh. The user cancelled the Facebook login." delegate:nil cancelButtonTitle:nil otherButtonTitles:@"Dismiss", nil]; [alert show]; } else { NSLog(@"welcome screen loginWithFB: Uh oh. An error occurred: %@", error); [self performSelector:@selector(reconnectWithFB) withObject:nil afterDelay:0.5]; } } else if (user.isNew) { NSLog(@"New user with facebook signed up and logged in!"); } else { NSLog(@"User with facebook logged in!"); FBRequest *request = [FBRequest requestForMe]; [request startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) { if (!error) { NSString *facebookUsername = [result objectForKey:@"name"]; [PFUser currentUser].username = facebookUsername; [[PFUser currentUser] setObject:[result objectForKey:@"id"] forKey:@"facebookid"]; [[PFUser currentUser] saveEventually]; [[NSNotificationCenter defaultCenter] postNotificationName:kUsersToWatchNotification object:result]; } else { NSLog(@"Error getting the FB username %@", [error description]); } }]; }
和我的reconnectWithFB(在模拟器上总是有一个空的fbAccounts数组:)
-(void) reconnectWithFB { NSLog(@"reconnectWithFB called"); ACAccountStore *accountStore; ACAccountType *accountTypeFB; if ((accountStore = [[ACAccountStore alloc] init]) && (accountTypeFB = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook] ) ){ NSArray *fbAccounts = [accountStore accountsWithAccountType:accountTypeFB]; NSLog(@"fbAccounts %@", fbAccounts); id account; if (fbAccounts && [fbAccounts count] > 0 && (account = [fbAccounts objectAtIndex:0])){ [accountStore renewCredentialsForAccount:account completion:^(ACAccountCredentialRenewResult renewResult, NSError *error) { //we don't actually need to inspect renewResult or error. if (error){ NSLog(@"error in reconnectWithFB %@", error); } }]; } } }
任何有关这方面的帮助将不胜感激.
看起来解决方案是将open url方法添加到我的App Delegate:
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url { return [PFFacebookUtils handleOpenURL:url]; }
和
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation { return [PFFacebookUtils handleOpenURL:url]; }