Twitter登录出现TWTRInvalidInitializationException错误

3

当我尝试使用Twitter登录时,我的应用程序会崩溃,并显示以下错误消息:

尝试在应用程序设置中没有设置有效的Twitter Kit URL方案的情况下登录或点赞推文。请参见https://dev.twitter.com/twitterkit/ios/installation了解更多信息。

我使用fabric应用了twitter登录。但是在将代码从Swift 2.3转换为Swift 3后,它开始崩溃。我已经更新了我的pods并重新应用了注册步骤,而不使用fabric登录,因为fabric现在不再显示twitter选项。但仍然发生崩溃。

2个回答

10

如果我理解正确,您使用了带有 Fabric 的 Twitter,因此我假设您在您的 AppDelegate 中有类似以下的内容:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    Fabric.with([Twitter.self])    
    return true
}

请注意,自从谷歌收购了Fabric,您应该使用:

Twitter.sharedInstance().start(withConsumerKey:"yourAppKey", consumerSecret:"yourAppSecret")
你还需要配置Info.plist文件以包括TwitterKit的URL Scheme,如下所示:
  1. 在CFBundleURLSchemes中,你应该有一个字符串键并设置为"twitterkit-yourAppKey"
  2. 在LSApplicationQueriesSchemes中,你应该添加这些:"twitter" 和 "twitterauth"
参考链接:https://dev.twitter.com/twitterkit/ios/installation 注意:确保在CFBundleURLSchemes中"twitterkit-yourAppKey"是Item 0,当前版本(3.0.3)存在一些奇怪的bug,如果不是第一项就会崩溃。

最后一部分(确保 twitterkit-{yourAppKey} 是第0项)对我很有帮助,谢谢! - mclaughj
Twitter.sharedInstance().start(...)给你的代码不能被复制粘贴。你必须手动输入你的密钥。我刚刚复制粘贴了它,没有查看,他们在代码示例中设置了一个虚假的密钥和秘密。 - brycejl

0

就像上面的答案所写,我正在做这个,但它崩溃了:

<key>CFBundleURLTypes</key>
<array>
    <dict>
        <key>CFBundleURLSchemes</key>
        <array>
            <string>fbmykey</string>
            <string>twitterkit-mykey</string>
        </array>
    </dict>
</array>

然后改成这样就可以了:

<key>CFBundleURLTypes</key>
<array>
    <dict>
        <key>CFBundleURLSchemes</key>
        <array>
            <string>twitterkit-mykey</string>
            <string>fbmykey</string>
        </array>
    </dict>
</array>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接