3

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?

Mo Abdul-Hameed
  • 6,030
  • 2
  • 23
  • 36
Michael Rowe
  • 870
  • 2
  • 11
  • 27
  • How did you add it in your Podfile? – Mo Abdul-Hameed Dec 17 '17 at 19:17
  • Here's my pod file: # Uncomment the next line to define a global platform for your project platform :ios, '11.2' target 'APPNAME' do # Comment the next line if you're not using Swift and don't want to use dynamic frameworks use_frameworks! pod 'TwitterKit' end – Michael Rowe Dec 17 '17 at 19:19
  • Ok found the first issue, the BridgeHeader was duplicated in the original file and I had added to the wrong one. Removed the duplicate and updated bridge header with the line #include . This gives me a File not found error. – Michael Rowe Dec 17 '17 at 19:46
  • Also added Pods/** to my User Search Path... Still no good. – Michael Rowe Dec 17 '17 at 19:52
  • well there must be an obvious answer, but I've not gotten this working yet... – Michael Rowe Dec 19 '17 at 21:06
  • looks like there's an issue with the initialiser... – Andy Piper Dec 20 '17 at 17:58

2 Answers2

5

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!

Andy Piper
  • 11,422
  • 2
  • 26
  • 49
  • 1
    Is this issue fixed? I cannot use Twitterkit with Swift 4. When changed to TWTRTwitter, there is issue and crash on line Fabric.with([TWTRTwitter.self]) saying cannot initialize TWTRTwitter as it is not valid. – user2094867 Jan 17 '18 at 07:40
  • Twitter Kit is not part of Fabric anymore. – Andy Piper Jan 17 '18 at 07:50
4

Thank you, Andy Piper, I fixed the issue as following:

  1. Updated pod so that TwitterCore 3.1.0 and TwitterKit 3.3.0

  2. In Bridging-Header.h file

imported as TwitterKit/TWTRKit.h instead of TwitterKit/TwitterKit.h

  1. 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])

user2094867
  • 299
  • 2
  • 7