解析iOS应用程序的Facebook登录不工作
我已经添加了facebook登录按钮,如教程中所述。然而,当我尝试测试时,FB登录按钮只是显示一个加载指示器,应用程序冻结。是否有我忘记实现的其他集成 AppDelegate.m:解析iOS应用程序的Facebook登录不工作,ios,objective-c,facebook,parse-platform,Ios,Objective C,Facebook,Parse Platform,我已经添加了facebook登录按钮,如教程中所述。然而,当我尝试测试时,FB登录按钮只是显示一个加载指示器,应用程序冻结。是否有我忘记实现的其他集成 AppDelegate.m: - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation {
return [[FBSDKApplicationDelegate sharedInstance] application:application
openURL:url
sourceApplication:sourceApplication
annotation:annotation];
}
- (void)applicationDidBecomeActive:(UIApplication *)application {
[FBSDKAppEvents activateApp];
}
- (void)applicationDidBecomeActive:(UIApplication *)application {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
// Start updating locations when the app returns to the foreground.
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
DefaultSettingsViewController *defaultSettingsViewController = [storyboard instantiateViewControllerWithIdentifier:@"DefaultSettingsViewController"];
//[defaultSettingsViewController.locationManager stopUpdatingLocation];
// Clear badge when app is opened
PFInstallation *currentInstallation = [PFInstallation currentInstallation];
if (currentInstallation.badge != 0) {
currentInstallation.badge = 0;
[currentInstallation saveEventually];
}
[FBSDKAppEvents activateApp];
[FBAppCall handleDidBecomeActiveWithSession:[PFFacebookUtils session]];
}
- (void)_loginWithFacebook {
// Set permissions required from the facebook user account
NSArray *permissionsArray = @[ @"user_about_me", @"user_relationships", @"user_birthday", @"user_location"];
// Login PFUser using Facebook
[PFFacebookUtils logInInBackgroundWithReadPermissions:permissions block:^(PFUser *user, NSError *error) {
if (!user) {
NSLog(@"Uh oh. The user cancelled the Facebook login.");
} else if (user.isNew) {
NSLog(@"User signed up and logged in through Facebook!");
} else {
NSLog(@"User logged in through Facebook!");
}
}];
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
if (![PFUser currentUser]) { // No user logged in
// Create the log in view controller
PFLogInViewController *logInViewController = [[PFLogInViewController alloc] init];
[logInViewController setDelegate:self]; // Set ourselves as the delegate
[logInViewController setFacebookPermissions:[NSArray arrayWithObjects:@"friends_about_me", nil]];
[logInViewController setFields: PFLogInFieldsUsernameAndPassword | PFLogInFieldsLogInButton | PFLogInFieldsFacebook | PFLogInFieldsSignUpButton | PFLogInFieldsPasswordForgotten];
// Create the sign up view controller
PFSignUpViewController *signUpViewController = [[PFSignUpViewController alloc] init];
[signUpViewController setDelegate:self]; // Set ourselves as the delegate
// Assign our sign up controller to be displayed from the login controller
[logInViewController setSignUpController:signUpViewController];
// Present the log in view controller
[self presentViewController:logInViewController animated:YES completion:NULL];
} else {
[self performSegueWithIdentifier:@"login" sender:self];
}
}
DefaultViewController.m:
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation {
return [[FBSDKApplicationDelegate sharedInstance] application:application
openURL:url
sourceApplication:sourceApplication
annotation:annotation];
}
- (void)applicationDidBecomeActive:(UIApplication *)application {
[FBSDKAppEvents activateApp];
}
- (void)applicationDidBecomeActive:(UIApplication *)application {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
// Start updating locations when the app returns to the foreground.
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
DefaultSettingsViewController *defaultSettingsViewController = [storyboard instantiateViewControllerWithIdentifier:@"DefaultSettingsViewController"];
//[defaultSettingsViewController.locationManager stopUpdatingLocation];
// Clear badge when app is opened
PFInstallation *currentInstallation = [PFInstallation currentInstallation];
if (currentInstallation.badge != 0) {
currentInstallation.badge = 0;
[currentInstallation saveEventually];
}
[FBSDKAppEvents activateApp];
[FBAppCall handleDidBecomeActiveWithSession:[PFFacebookUtils session]];
}
- (void)_loginWithFacebook {
// Set permissions required from the facebook user account
NSArray *permissionsArray = @[ @"user_about_me", @"user_relationships", @"user_birthday", @"user_location"];
// Login PFUser using Facebook
[PFFacebookUtils logInInBackgroundWithReadPermissions:permissions block:^(PFUser *user, NSError *error) {
if (!user) {
NSLog(@"Uh oh. The user cancelled the Facebook login.");
} else if (user.isNew) {
NSLog(@"User signed up and logged in through Facebook!");
} else {
NSLog(@"User logged in through Facebook!");
}
}];
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
if (![PFUser currentUser]) { // No user logged in
// Create the log in view controller
PFLogInViewController *logInViewController = [[PFLogInViewController alloc] init];
[logInViewController setDelegate:self]; // Set ourselves as the delegate
[logInViewController setFacebookPermissions:[NSArray arrayWithObjects:@"friends_about_me", nil]];
[logInViewController setFields: PFLogInFieldsUsernameAndPassword | PFLogInFieldsLogInButton | PFLogInFieldsFacebook | PFLogInFieldsSignUpButton | PFLogInFieldsPasswordForgotten];
// Create the sign up view controller
PFSignUpViewController *signUpViewController = [[PFSignUpViewController alloc] init];
[signUpViewController setDelegate:self]; // Set ourselves as the delegate
// Assign our sign up controller to be displayed from the login controller
[logInViewController setSignUpController:signUpViewController];
// Present the log in view controller
[self presentViewController:logInViewController animated:YES completion:NULL];
} else {
[self performSegueWithIdentifier:@"login" sender:self];
}
}
你能在DefaultViewController.m的代码行上设置断点重新运行你的应用程序吗
[logInViewController setDelegate:self]; // Set ourselves as the delegate
在identity inspector中告诉我它包含哪些对象
我对解析没有太多经验,但听起来其中一个框架可能没有正确实现。(如果是这种情况,这是一个快速解决方案。您只需重新下载并将其放回应用程序中即可)我甚至无法达到这一点,因为该代码在用户登录后运行。请尝试设置异常断点(以下是您不知道如何设置的步骤)查看[Navigator],然后单击[Show the breakpoint Navigator]。请参见导航器[+]符号的底部。单击它并选择[添加异常断点]。