问题
I'm trying to upgrade my app to latest iOS support. I've added TwitterKit via CocoaPods, and placed header in my Bridge Header. However; I am getting an error saying:
Use of unresolved identified 'Twitter' - did you mean 'TWTRTTwitter'.
func application(_ application: UIApplication, didFinishLaunchingWithOptions lauunchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
Twitter.sharedInstance().start(withConsumerKey:"MYKEY", consumerSecret:"MYSECRET")
return true
}
This right out of the Twitter recommended code. I also get it at:
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
}
Any pointers?
回答1:
Thank you, Andy Piper, I fixed the issue as following:
Updated pod so that TwitterCore 3.1.0 and TwitterKit 3.3.0
In Bridging-Header.h file
imported as TwitterKit/TWTRKit.h instead of TwitterKit/TwitterKit.h
In didFinishLaunchingWithOptions,
- Modified Twitter.sharedInstance().start(withConsumerKey: ”your consumer key”, consumerSecret:”your consumer secret”)
TWTRTwitter.sharedInstance().start(withConsumerKey: ”your consumer key”, consumerSecret:”your consumer secret”)
i.e replace Twiter with TWTRTwitter where it is used.
- No need to initialize with fabric, so removed this line or removed
Fabric.with([Twitter.self]) or Fabric.with([TWTRTwitter.self])
回答2:
There’s a bit of a code change with the latest Twitter Kit release. We changed Twitter
-> TWTRTwitter
- but also added a macro so that you should still be able to use [Twitter sharedInstance]
. Unfortunately, this currently does not work with Swift - so have a try with TWTRTwitter
as suggested. We'll get this sorted out in the docs! sorry!
来源:https://stackoverflow.com/questions/47858555/upgrading-app-to-swift-4-and-ios-11-twitterkit-issues