简体   繁体   English

在Twitter登录成功后,从Twitter本机应用程序重定向到iOS应用程序

[英]Redirect from twitter native app to iOS app after twitter login success

I have to login to my iOS app using Twitter account. 我必须使用Twitter帐户登录我的iOS应用程序。
CASE 1: If Twitter app is present in iPhone I need to login to twitter app and after login success , i need to redirect back to my app. 案例1:如果iPhone中存在Twitter应用程序,我需要登录到Twitter应用程序,登录成功后,我需要重定向回我的应用程序。
CASE 2: If twitter app is not present in iPhone , then I need to login to twitter app through the default browser. 情况2:如果iPhone中没有Twitter应用程序,那么我需要通过默认浏览器登录Twitter应用程序。

I am using STTwitter framework. 我正在使用STTwitter框架。 Case 2 is working fine for me. 案例2对我来说很好。
The below code is used for opening twitter app in browser 以下代码用于在浏览器中打开Twitter应用程序

self.twitter = [STTwitterAPI twitterAPIWithOAuthConsumerKey:kCONSUMER_KEY
                                             consumerSecret:kCONSUMER_SECREAT];



[_twitter postTokenRequest:^(NSURL *url, NSString *oauthToken) {
    NSLog(@"-- url: %@", url);
    NSLog(@"-- oauthToken: %@", oauthToken);

    [[UIApplication sharedApplication] openURL:url];

} authenticateInsteadOfAuthorize:NO
                forceLogin:@(YES)
                screenName:nil
             oauthCallback:@"testapp://twitter_access_tokens/"
                errorBlock:^(NSError *error) {
                    NSLog(@"-- error: %@", error);

                }];

To open twitter app, the below code can be used 要打开Twitter应用程序,可以使用以下代码

    NSURL *twitterURL = [NSURL URLWithString:@"twitter://"];

    if ([[UIApplication sharedApplication] canOpenURL:twitterURL]) {
        [[UIApplication sharedApplication] openURL:twitterURL];
    }

If twitter app is present in iPhone , the above lines of code can open the twitter app, but how to redirect back to my app after login success in twitter. 如果iPhone中存在twitter应用程序,上面的代码行可以打开twitter应用程序,但是如何在Twitter上登录成功后重定向回我的应用程序。

Please anyone help me out. 请有人帮帮我。

Once control passes out of your app, there is no way to programmatically bring the user back. 一旦控件从您的应用程序中消失,就无法以编程方式将用户带回来。 They would need to manually come back. 他们需要手动回来。 That being said, look through the Twitter api that apple provides since the iPhone can log into Twitter without their app. 话虽这么说,看看苹果提供的Twitter api,因为iPhone可以在没有他们的应用程序的情况下登录Twitter。 You should be able to accomplish what you want without them leaving your app to get into the Twitter app or site. 如果没有他们离开你的应用程序进入Twitter应用程序或网站,你应该能够完成你想要的。

Twitter.app uses the Twitter accounts defined in iOS Settings. Twitter.app使用iOS设置中定义的Twitter帐户。

Also, accounts can be defined in iOS Settings even if Twitter.app is not installed. 此外,即使未安装Twitter.app,也可以在iOS设置中定义帐户。

So, I think that in case 1 you don't need to open Twitter.app. 所以,我认为在案例1中你不需要打开Twitter.app。

You can simply instantiate STTwitterAPI with the first account available: 您可以使用第一个可用帐户简单地实例化STTwitterAPI

+ (instancetype)twitterAPIOSWithFirstAccount;

or provide a specific account if you prefer to: 或者,如果您愿意,请提供特定帐户:

+ (instancetype)twitterAPIOSWithAccount:(ACAccount *)account;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM