Problem setting up URL scheme in iOS plist file

ios
login

#1

I’m getting the error: Terminating app due to uncaught exception ‘TWTRInvalidInitializationException’, reason: ‘Attempt made to Log in or Like a Tweet without a valid Twitter Kit URL Scheme set up in the app settings. Please see https://dev.twitter.com/twitterkit/ios/installation for more info.’

The problem is that i’ve got CFBundleURLSchemes setup already… correctly, I think.

        <key>CFBundleURLTypes</key>
        <array>
                <dict>
                        <key>CFBundleTypeRole</key>
                        <string>Twitter</string>
                        <key>CFBundleURLSchemes</key>
                        <array>
                                <string>twitterkit-redactedblahblah</string>
                        </array>
                </dict>
               <dict>
                        <key>CFBundleTypeRole</key>
                        <string>Facebook</string>
                        <key>CFBundleURLSchemes</key>
                        <array>
                                <string>fb12345678redacted</string>
                        </array>
                </dict>
        </array>

I read another post about a similar (if not identical) problem and the solution was to use separate roles for the schemes… but that isn’t helping me this time. This is on iOS 10.3 and TwitterKit 3.0.4. The exception is thrown when clicking the twitter login button in my view controller.

Any thoughts?


#2

I’ve seen other posts saying that the only valid values for this key are: None, Viewer or Editor. So I set both to ‘Viewer’ and it has the same issue.


#3

Could you try setting it to ‘Editor’?


#4

Hi @katejaiheelee - I tried setting both roles to Editor as well … no luck. Same result.


#5

Hi @sjwoodr, Can you make sure that the consumer key in

    [[Twitter sharedInstance] startWithConsumerKey:@"<consumerKey>" consumerSecret:@"<consumerSecret>"];

matches the consumer key in your Info.plist file?


#6

Oops… embarrasing. Looks like it was mistyped there.

Now it does not crash, but I do get an error after authenticating with Twitter in safari:

2017-08-04 14:49:41.737 cocorahs[22593:29558916] TWTRLogInButton was created with no completionBlock set

But there is a completion block…

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.fbLoginButton = [[FBSDKLoginButton alloc] init];
    self.twitterLoginButton = [TWTRLogInButton buttonWithLogInCompletion:^(TWTRSession *session, NSError *error) {
        if (session) {
            NSLog(@"Twitter user signed in as %@", [session userName]);
        } else {
            NSLog(@"Twitter error: %@", [error localizedDescription]);
        }
    }];
}

#7

Could you send me some additional information to help me reproduce the error on my end?


#8

Hmm… anything specific I can send to you to help ?

in AppDelegate.m i have:

    [[Twitter sharedInstance] startWithConsumerKey:@"xxx" consumerSecret:@"yyy"];

In SharingViewController.m I have:

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.fbLoginButton = [[FBSDKLoginButton alloc] init];
    self.twitterLoginButton = [TWTRLogInButton buttonWithLogInCompletion:^(TWTRSession *session, NSError *error) {
        if (session) {
            NSLog(@"Twitter user signed in as %@", [session userName]);
        } else {
            NSLog(@"Twitter error: %@", [error localizedDescription]);
        }
    }];
}

The button is functional… an IBOutlet for this exists in SharingViewController.h and its wired up via the storyboard. Clicking the button launches Safari (this is run in iphone 7 simulator) where I enter credentials and authorize the app. It then returns to my application and I get the error in the log:

2017-08-04 14:49:41.737 cocorahs[22593:29558916] TWTRLogInButton was created with no completionBlock set

The twitter login button remains “Log In With Twitter” …

Thanks!


#9

Any ideas @RajulArora or @katejaiheelee ?


#10

Hi @sjwoodr

So I was able to reproduce your issue. It seems like it’s due to the fact you are creating a UIButton in storyboard and re-initializing the button in code. I need to do some more research as to exactly why this is happening, but as a workaround for TwitterKit 3.0.4, I would recommend removing the IBOutlet for the button and just creating it manually in the view controller and adding your constraints/layout code there.

Hope that helps!


#11

Another option is that you can manually set the loginCompletion parameter in viewDidLoad rather than using [TWTRLogInButton buttonWithLogInCompletion:] so you can preserve the button’s constraints in storyboard.


#12

I was getting the same crash when twitterkit-foo wasn’t the first URL. That would seem to be a Twitter bug to me.


#13

Thank you @RajulArora - i’ll try this out!


#14

@JosephLordUK that is a separate issue which will be resolved in the next TwitterKit release This post describes the problem well for reference :slight_smile:


#15

I thought it was useful information to have here for those searching and who like me hadn’t found that thread.

Good to know a fix is in hand. It would be really useful if you could update the instructions at https://dev.twitter.com/twitterkit/ios/installation to be explicit that it must be the first item in the list until that version is out.

Thanks.


#16

@JosephLordUK the newest version is out!


#17

@RajulArora - just getting back to this now… I kept the UIButton in the storyboard and added this to viewDidLoad:

    [self.twitterLoginButton setLogInCompletion:^(TWTRSession *session, NSError *error) {
        if (session) {
            NSLog(@"Twitter user signed in as %@", [session userName]);
        } else {
            NSLog(@"Twitter error: %@", [error localizedDescription]);
        }
    }];

But it crashes with ‘NSInvalidArgumentException’, reason: ‘-[UIButton setLogInCompletion:]: unrecognized selector sent to instance 0x7fb66cf17090’

What am I missing here… ?

Thanks!


#18

You have incorrectly set up your UIButton in storyboard. If you set a breakpoint before setLoginCompletion is called, you will likely see that self.twitterLoginButton is nil.

I would recommend you check the IBOutlet reference and make sure it’s still referencing the correct thing.


#19

Hi @RajulArora … I set the breakpoint and see this:

The button itself is not nil but many of its properties are. If the button is set in the storyboard and the IBOutlet is linked to the button in the class, why would this not work – I must be missing something. :slight_smile:

Thanks!


#20

Of course I can just do it in code but I was hoping to do it via the storyboard.

    self.twitterLoginButton = [TWTRLogInButton buttonWithLogInCompletion:^(TWTRSession *session, NSError *error) {
                if (session) {
                    NSLog(@"Twitter user signed in as %@", [session userName]);
                } else {
                    NSLog(@"Twitter error: %@", [error localizedDescription]);
                }
    }];
    
    self.twitterLoginButton.center = CGPointMake(150, 350);
    [self.view addSubview:self.twitterLoginButton];

That works fine. And I’ll go with that for now I guess. :confused: