Search code examples
iosswifttwittertwitterkit

Twitterkit 3.0 'TWTRInvalidInitializationException' error in ios


I had used fabric with no issue but since new twitterkit 3.0 update I followed all the installation document but when I use TWTRComposer I get app crash with folowing message: "'TWTRInvalidInitializationException', reason: 'Attempt made to Log in or Like a Tweet without a valid Twitter Kit URL Scheme set up in the app settings." Can't seem to figure out solution.

// Swift
    let composer = TWTRComposer()

    composer.setText("just setting up my Twitter Kit")
    composer.setImage(image.image)

    // Called from a UIViewController
    composer.show(from: self.navigationController!) { (result) in
        if (result == .done) {
        print("Successfully composed Tweet")
        } else {
        print("Cancelled composing")
        }
    }

The folowing is app delegate didFinishLaunchingWithOptions code

Twitter.sharedInstance().start(withConsumerKey:"xxxxxxxxxxxx", consumerSecret:"xxxxxxxxxxxxxxxxxxxxxxxxxxxxx")

The following is my infoPlist code

<key>CFBundleURLTypes</key>
<array>
    <dict>
        <key>CFBundleURLSchemes</key>
        <array>
            <string>twitterkit-consumentkeyxxxxxxx</string>
            <string>fbkeyxxxxxxxxxxxx</string>
            <string>xxxxxxxxx</string>
        </array>
    </dict>
</array>
<key>LSApplicationQueriesSchemes</key>
<array>
    <string>fbapi</string>
    <string>fb-messenger-api</string>
    <string>fbauth2</string>
    <string>fbshareextension</string>
    <string>twitter</string>
    <string>twitterauth</string>
</array>

Not there are no issues on app start but when I press button to share on twitter, twitter composer is call and on "composer.show" line app crashes. I needed to use twitter sdk due to change in ios11 inbuilt account feature remove


Solution

  • You need to add key separately like this:

    <key>CFBundleURLTypes</key>
        <array>
            <dict>
                <key>CFBundleTypeRole</key>
                <string>Editor</string>
                <key>CFBundleURLSchemes</key>
                <array>
                    <string>fb-fbid-</string>
                </array>
            </dict>
            <dict>
                <key>CFBundleTypeRole</key>
                <string>Editor</string>
                <key>CFBundleURLSchemes</key>
                <array>
                    <string>twitterkit-twitterKey</string>
                </array>
            </dict>
        </array>