0

我的应用程序允许典型的注册(电子邮件、用户名、密码等),但也可以通过 Parse 启用 Facebook/Twitter 注册/唱歌。如果可能的话,如果用户使用 Facebook 或 Twitter 登录,我想避免强制用户登录两次。目前,我添加了“Scringo”的程序化注册功能,让用户使用与我的应用程序相同的凭据登录“scringo”;然而。如果他们在 Facebook 上注册怎么办?用户使用 Facebook 登录,然后滑过一个栏,然后访问消息传递组件以强制再次使用 Facebook 登录,这似乎非常令人困惑。

这是我目前所拥有的,是否有链接 Facebook/Twitter 登录过程,以便 Parse 与 Scringo 一起获取信息,只需按下一个按钮?

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

[Parse setApplicationId:@"...gzPI7Omoxc..."
              clientKey:@"...s22ZqIbM7n..."];

[PFTwitterUtils
 initializeWithConsumerKey:@"...W4XjjpHz..."
            consumerSecret:@"...Czjtht7v5..."];

[PFAnalytics trackAppOpenedWithLaunchOptions:launchOptions];
[PFFacebookUtils initializeFacebook];

[self configureNavigationBar];

[Scringo initWithAppId:@"...N2cCMhW1Bv..." completion:^{
    [Scringo addSidebar:self.window toLeft:YES];
     PFUser *currentUser = [PFUser currentUser];
    if (! [ScringoUser currentUser].isAuthenticated) {
        [ScringoUser signUpWithEmail:currentUser.email userName:currentUser.username password:@"notforyou" completion:^(ScringoUser *aUser, BOOL isSuccess) {
            if (isSuccess) {
                [currentUser setObject:aUser.userId forKey:@"ScringoUserId"];
                [currentUser saveInBackground];
            }
        }];
    }
     }];

return YES;
}
4

1 回答 1

0

原来SDK中有一个方法(我只是忽略了它)

[Scringo connectFacebook]

如果应用程序已经成功登录到 facebook,调用它也会验证 Scringo。

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

[Parse setApplicationId:@"gzPI7OmoxcSYqQGWASjzVd8lP5q8FVJqh2ZLsXnp"
              clientKey:@"s22ZqIbM7n8SN1End57vmTmmeL55YnIen7dmMhIR"];

[PFTwitterUtils
 initializeWithConsumerKey:@"W4XjjpHzG03bWK8R0iPvs27Yy"
            consumerSecret:@"Czjtht7v58yfZ00QV5Gkumfdy8RauCyPllYh5SPm00I3M6fkPP"];

[PFAnalytics trackAppOpenedWithLaunchOptions:launchOptions];
[PFFacebookUtils initializeFacebook];

[self configureNavigationBar];

[Scringo initWithAppId:@"cvOV3lLwQN2cCMhW1BvnW2eWnyoiLNgA" completion:^{
    [Scringo addSidebar:self.window toLeft:YES];
     PFUser *currentUser = [PFUser currentUser];
    if (! [ScringoUser currentUser].isAuthenticated) {
        if (currentUser) {
            if (currentUser.email) [Scringo connectFacebook];
        else
        [ScringoUser signUpWithEmail:currentUser.email userName:currentUser.username password:@"notforyou" completion:^(ScringoUser *aUser, BOOL isSuccess) {
            if (isSuccess) {
                [currentUser setObject:aUser.userId forKey:@"ScringoUserId"];
                [currentUser saveInBackground];
            }
        }];
        }
    }
     }];

return YES;
}

假设 PFUser 已经存在,所以我还为第一次使用 facebook 登录的用户在登录页面添加了相同的调用

- (void)logInViewController:(PFLogInViewController *)logInController didLogInUser:(PFUser *)user {
[self dismissViewControllerAnimated:YES completion:^{
    if (!self.currentUser.email) [Scringo connectFacebook];
}];
}

测试和工作。

于 2014-05-20T15:21:19.090 回答