PFFacebookUtils立即调用阻止

时间:2015-04-27 07:48:00

标签: ios parse-platform facebook-login

我正在制作一个使用Facebook登录的iOS应用程序,并使用解析。我想使用ParseUI进行登录,并完成所有设置,但委托方法永远不会被调用。我做了一些挖掘,并认为PFFacebookUtils有问题,或者至少我是如何设置它的。

当我测试PFFacebookUtils logInInBackgroundWithReadPermissions方法时,立即调用块,PFUser为null,NSError为null。 Facebook似乎仍然通过它的正常登录流程,但从未实际登录到我的应用程序。

我已经能够使用Facebook sdk成功登录Facebook(但不能解析)。

以下是我的代码:

#import "AppDelegate.h"
#import "LoginViewController.h"
#import <Parse/Parse.h>
#import <ParseFacebookUtilsV4/PFFacebookUtils.h>
#import <ParseUI/ParseUI.h>
#import <FBSDKCoreKit/FBSDKCoreKit.h>

@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    [Parse setApplicationId:@"censored"
              clientKey:@"censored"];
    [PFAnalytics trackAppOpenedWithLaunchOptions:launchOptions];
    [PFFacebookUtils initializeFacebookWithApplicationLaunchOptions:launchOptions];

    [PFFacebookUtils logInInBackgroundWithReadPermissions:@[@"email"] block:^(PFUser *user, NSError *error){
        NSLog(@"Callback");
        NSLog(@"User: %@, error: %@", user, error);
    }];

    return [[FBSDKApplicationDelegate sharedInstance] application:application
                                didFinishLaunchingWithOptions:launchOptions];
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    [FBSDKAppEvents activateApp];
}

- (BOOL)application:(UIApplication *)application
        openURL:(NSURL *)url
        sourceApplication:(NSString *)sourceApplication
     annotation:(id)annotation {

    return [[FBSDKApplicationDelegate sharedInstance] application:application
                                                      openURL:url
                                            sourceApplication:sourceApplication
                                                   annotation:annotation];
}

我还试过从视图控制器调用:

#import "ViewController.h"
#import <Parse/Parse.h>
#import <ParseFacebookUtilsV4/PFFacebookUtils.h>

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    super viewDidLoad];
    [PFFacebookUtils logInInBackgroundWithReadPermissions:@[@"email"] block:^(PFUser *user, NSError *error){
        NSLog(@"Callback");
        NSLog(@"User: %@, error: %@", user, error);
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

@end

我也试过从全局线程调度它,并且在主线程上,没有运气。

这就是我单独使用Facebook SDK登录的方式:

#import "ViewController.h"
#import <Parse/Parse.h>
#import <ParseFacebookUtilsV4/PFFacebookUtils.h>
#import <FBSDKCoreKit/FBSDKCoreKit.h>

@interface ViewController ()
- (IBAction)button:(id)sender;
@property (weak, nonatomic) IBOutlet FBSDKLoginButton *loginButton;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.loginButton.delegate = self;
}

- (IBAction)button:(id)sender {
    NSLog(@"User id: %@", [FBSDKAccessToken currentAccessToken].userID);
}

- (void) loginButton:   (FBSDKLoginButton *)loginButton didCompleteWithResult:  (FBSDKLoginManagerLoginResult *)result
           error:   (NSError *)error{
    if( result.isCancelled ){
        NSLog(@"Cancelled login");
    } else {
        NSLog(@"Login successful");
        NSLog(@"User id: %@", [FBSDKAccessToken currentAccessToken].userID);

    }
}

- (void) loginButtonDidLogOut:(FBSDKLoginButton *)loginButton{
    NSLog(@"Logout button");
}
@end

0 个答案:

没有答案