【问题标题】:Upgrading App to Swift 4 and iOS 11 - TwitterKit Issues将应用程序升级到 Swift 4 和 iOS 11 - TwitterKit 问题
【发布时间】:2018-05-31 05:03:58
【问题描述】:

我正在尝试将我的应用升级到最新的 iOS 支持。我已经通过 CocoaPods 添加了 TwitterKit,并将标题放在我的 Bridge Header 中。然而;我收到一条错误消息:

使用未解决的已识别“Twitter” - 您的意思是“TWTRTTwitter”吗?

func application(_ application: UIApplication, didFinishLaunchingWithOptions lauunchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    Twitter.sharedInstance().start(withConsumerKey:"MYKEY", consumerSecret:"MYSECRET")
    return true
}

这是推特推荐的代码。我也在:

func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {

    let handled:Bool = true

    Twitter.sharedInstance().application(app, open: url, options: options)

    return handled
}

任何指针?

【问题讨论】:

  • 你是如何将它添加到你的 Podfile 中的?
  • 这是我的 pod 文件: # 取消注释下一行,为您的项目平台定义一个全局平台 :ios, '11.2' target 'APPNAME' do # 如果你不使用 Swift,请注释下一行并且不想使用动态框架use_frameworks! pod 'TwitterKit' 结束
  • 好的,找到第一个问题,BridgeHeader 在原始文件中重复,我添加到错误的文件中。使用 #include 行删除了重复和更新的桥头。这给了我一个 File not found 错误。
  • 还在我的用户搜索路径中添加了 Pods/**... 还是不行。
  • 嗯,肯定有一个明显的答案,但我还没有得到这个工作......

标签: swift4 twitterkit ios11.2


【解决方案1】:

谢谢你,Andy Piper,我已将问题解决如下:

  1. 更新了 pod,以便 TwitterCore 3.1.0 和 TwitterKit 3.3.0

  2. 在 Bridging-Header.h 文件中

导入为 TwitterKit/TWTRKit.h 而不是 TwitterKit/TwitterKit.h

  1. 在 didFinishLaunchingWithOptions 中,

    • 修改了 Twitter.sharedInstance().start(withConsumerKey: ”你的消费者密钥”, consumerSecret:”你的消费者密码”)

TWTRTwitter.sharedInstance().start(withConsumerKey: ”你的消费者密钥”, consumerSecret:”你的消费者密码”)

即在使用它的地方用 TWTRTwitter 替换 Twiter。

  • 不需要用fabric初始化,所以去掉这行或者去掉

Fabric.with([Twitter.self]) 或 Fabric.with([TWTRTwitter.self])

【讨论】:

  • 我得到 "'TwitterKit/TWTRKit.h' 文件未找到" :(
  • 通过桥接 #import "TwitterKit/TwitterKit.h" 我可以使用 Twitter.sharedInstance() 我猜 TwitterKit 已更新。
【解决方案2】:

最新的 Twitter Kit 版本对代码进行了一些更改。我们更改了Twitter -> TWTRTwitter - 但还添加了一个宏,以便您仍然可以使用[Twitter sharedInstance]。不幸的是,这目前不适用于 Swift - 所以请按照建议尝试使用 TWTRTwitter。我们将在文档中解决这个问题!对不起!

【讨论】:

  • 这个问题解决了吗?我无法将 Twitterkit 与 Swift 4 一起使用。当更改为 TWTRTwitter 时,Fabric.with([TWTRTwitter.self]) 线上出现问题并崩溃,说无法初始化 TWTRTwitter,因为它无效。
  • Twitter Kit 不再是 Fabric 的一部分。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-09-06
  • 1970-01-01
  • 2013-12-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多