首页 > 解决方案 > Twitter Kit 不能在 Swift 应用程序中重定向

问题描述

TwitterKit 不能在我的应用程序中重定向。 在 TwitterKit 中不能在我的应用程序中重定向,并且我添加了所有重要的代码

1. Info.Plist 新增行

<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>

2. 应用委托

import TwitterKit
application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

    Twitter.sharedInstance().start(withConsumerKey:consumer_key, consumerSecret:consumer_secret)
}

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

3.登录界面

func twitter(){
    TWTRTwitter.sharedInstance().logIn(with: self, completion: { (session, error) in
          --
    }) 
}

谁能告诉我哪里出错了?

标签: iosswiftredirecttwitter

解决方案


这是一个回调问题所以请在 AppDelegate 中评论

func application(_ application: UIApplication, configurationForConnecting connectedSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration { } func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set) { } 并添加 didFinishlaunchWithOption 函数

self.window = UIWindow(frame: UIScreen.main.bounds) 让 vc = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "GoThrough") as!UINavigationController self.window?.rootViewController = vc self.window?.makeKeyAndVisible()


推荐阅读