Twitter工具包 - 授权后的重定向无法在iOS 11测试版上运行

时间:2017-08-29 14:51:01

标签: ios twitter-oauth

登录成功后总是低于错误而没有重定向到我的app.it继续加载。

"Redirecting you back to the application.This may take a few moments."

[TwitterKit]确实遇到错误消息"无法使用系统帐户进行​​身份验证。":错误域= TWTRLogInErrorDomain代码= 0"用户拒绝访问系统帐户。" UserInfo = {NSLocalizedDescription =用户拒绝访问系统帐户。,NSLocalizedRecoverySuggestion =授予此用户访问系统Twitter帐户的权限。}

ViewController.m

     [[Twitter sharedInstance] startWithConsumerKey:@"1diEEBruGq9X5HKr0FyK3vFGF" consumerSecret:@"YIOD1rPx1tEuYJRLRYpl8ApT8YdWQpilnApJ8R67VaD3KePAU3"];
    [[Twitter sharedInstance] logInWithCompletion:^(TWTRSession *session, NSError *error) {
        if (session) {

            TWTRComposer *composer = [[TWTRComposer alloc] init];

            [composer setText:@"just setting up my Twitter Kit"];
            [composer setImage:[UIImage imageNamed:@"twitterkit"]];

            // Called from a UIViewController
            [composer showFromViewController:delegate.window.rootViewController completion:^(TWTRComposerResult result) {
                if (result == TWTRComposerResultCancelled) {
                    NSLog(@"Tweet composition cancelled");
                }
                else {
                    NSLog(@"Sending Tweet!");
                }
            }];

        } else {
            NSLog(@"error: %@", [error localizedDescription]);
        }
    }];

AppDelegate.m

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url
        options:(NSDictionary *) options
 {

[[Twitter sharedInstance] application:application openURL:url options:options];
return YES;
 }

enter image description here

2 个答案:

答案 0 :(得分:0)

从iOS 11开始,Apple已从iOS中删除了社交帐户。

您应该使用Twitter Kit 3 for iOS。

请参阅Twitter博客https://dev.twitter.com/twitterkit/ios/migrate-social-framework

<强>更新

的AppDelegate

import TwitterKit

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Intialize Twitter Kit
        Twitter.sharedInstance().start(withConsumerKey:consumer_key, consumerSecret:consumer_secret)
}

func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
        if Twitter.sharedInstance().application(app, open: url, options: options) {
            return true
        }

 return false
}

的ViewController

import TwitterKit

override func viewDidLoad() {
        super.viewDidLoad()

        Twitter.sharedInstance().logIn(with: self, completion: { (session, error) in

            if let sess = session {
                print("signed in as \(sess.userName)");
            } else {
                print("error: \(String(describing: error?.localizedDescription))");
            }
        })

    }

Info.plis

<key>CFBundleURLTypes</key>
    <array>
        <dict>
            <key>CFBundleURLSchemes</key>
            <array>
                <string>twitterkit-{your consumer key}</string>
            </array>
        </dict>
    </array>
    <key>LSApplicationQueriesSchemes</key>
    <array>
        <string>twitter</string>
        <string>twitterauth</string>
    </array>

答案 1 :(得分:0)

我知道这很旧,但这可能会对某人有所帮助,因为从iOS 13开始我们有scenedelegate文件,所以我遇到了同样的问题。对我来说,解决方案是通过下面的twitter委托方法在scenedelegate文件中管理该方法。

func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
    if let openURLContext = URLContexts.first {
        let url = openURLContext.url
        let options: [AnyHashable : Any] = [
            UIApplication.OpenURLOptionsKey.annotation : openURLContext.options.annotation as Any,
            UIApplication.OpenURLOptionsKey.sourceApplication : openURLContext.options.sourceApplication as Any,
            UIApplication.OpenURLOptionsKey.openInPlace : openURLContext.options.openInPlace
        ]
        TWTRTwitter.sharedInstance().application(UIApplication.shared, open: url, options: options)
    }
}