Twitter使用TWTRInvalidInitializationException登录崩溃

当我尝试使用twitter登录时,我的应用程序崩溃,并显示错误消息

在应用程序设置中未设置有效的Twitter工具包URL计划的情况下尝试登录或使用推文。 有关详细信息,请参阅https://dev.twitter.com/twitterkit/ios/installation 。

我已经使用fabric应用了twitter登录。但是在将我的代码从swift 2.3转换为swift 3之后,它开始崩溃。我已经更新了我的pod并重新应用了没有结构再次登录的步骤,因为结构现在没有显示twitter选项。 但仍然崩溃仍然存在。

如果我理解正确你使用Twitter与Fabric,所以我假设你在AppDelegate中有这样的东西:

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

请注意,自Google收购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

PS:确保你的CFBundleURLSchemes中的“twitterkit-yourAppKey”是第0项,当前版本(3.0.3)中有一些奇怪的错误,如果它不是第一个崩溃的项目。

就像上面写的答案一样,我这样做并且崩溃了:

 CFBundleURLTypes   CFBundleURLSchemes  fbmykey twitterkit-mykey    

然后改为这个并且它有效:

 CFBundleURLTypes   CFBundleURLSchemes  twitterkit-mykey fbmykey