我正在尝试将Twitter登录添加到我的Xcode项目中。我的主要登录是Facebook但我的应用程序使用Twitter信息,因为ACAccountStore()。对于iOS 11,不推荐使用requestAccessToAccounts,我必须使用Twitter API。我安装了TwitterKit pod。我将以下内容添加到我的应用代表中:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
FirebaseApp.configure()
Database.database().isPersistenceEnabled = true
Twitter.sharedInstance().start(withConsumerKey: "the key from twitter", consumerSecret: "the secret from twitter")
return FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)
}
我的plist看起来像:
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLSchemes</key>
<array>
<string>fbxxxxxx</string>
</array>
</dict>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLSchemes</key>
<array>
<string>twitterkit-xxxxx</string>
</array>
</dict>
</array>
<key>CFBundleVersion</key>
<string>1</string>
<key>FacebookAppID</key>
<string>xxxxx</string>
<key>FacebookDisplayName</key>
<string>Smartter</string>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>fbapi</string>
<string>fb-messenger-share-api</string>
<string>fbauth2</string>
<string>fbshareextension</string>
<string>twitter</string>
<string>twitterauth</string>
</array>
现在我有一个视图控制器,我在这里添加登录按钮:
let logInButton = TWTRLogInButton(logInCompletion: { session, error in
if (session != nil) {
print("signed in as \(session?.userName)");
} else {
print("error: \(error?.localizedDescription)");
}
})
logInButton.center = self.view.center
self.view.addSubview(logInButton)
当我点击按钮时,我在控制台中收到请求失败:未授权(401)。如果我使用11.2.1在iPod上构建它,登录将打开,因为我在此设备上安装了Twitter应用程序。我包含了SafariServices.framework,我遵循了所有的Twitter指令。有什么想法吗?