3

I have a Tweetsheet share option in my app. Just updated to iOS8.3 and now SLComposeViewController is throwing an error when I try to present the Tweetsheet:

"Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Application tried to present a nil modal view controller on target"

SLComposeViewController *tweetSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
[tweetSheet setInitialText:@"testing!"];
[self presentViewController:tweetSheet animated:YES completion:nil];

I'm checking beforehand whether Twitter is available. Anyone else have this problem now?

Alex Cio
  • 6,014
  • 5
  • 44
  • 74
user3587825
  • 121
  • 1
  • 5

2 Answers2

2

I have the same problem when using SLServiceTypeTwitter on an iPhone running iOS 8.3: Although

[SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter] 

returns YES, a subsequent call to

[SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter]

returns nil. However, it returns a view controller if I'm running the app on an iPad, or on the iPhone Simulator, or if I change the service type to SLServiceTypeFacebook.

Now I'm using this workaround: To check Twitter availability, I use

+(BOOL)twitterAvailable {
    return([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter] &&
           [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter] != nil);
}

I further add an additional check before presenting the SLComposeViewController:

if(composeViewController != nil) {
   [viewController presentViewController:composeViewController animated:YES completion:nil];
}

This should be future proof for a bug fix in iOS 8.4.

Theo
  • 3,826
  • 30
  • 59
0

Before using one of the services you always should check if the object can be accessed:

if( [SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter] ){

This is really important so

  1. your app is not crashing and
  2. you can tell the user the service is not available.

You should do the same for the other services which can be used from iOS, like for SMS or Mail:

if(![MFMessageComposeViewController canSendText]) {

OR

if( ![MFMailComposeViewController canSendMail] ){

If you want to be sure, a specific app is available on the phone, you could also try to use canOpenURL::

- (BOOL)isAppAvailable:(NSString *)appURL{
   return [[UIApplication sharedApplication]  
                canOpenURL:[NSURL URLWithString:appURL]];
}

I think the call isAvailableForServiceType:SLServiceTypeTwitter is executing something similar.

Alex Cio
  • 6,014
  • 5
  • 44
  • 74
  • 1
    Hey - yes I did check. It's still crashing. I have a feeling this is a bug because the exact same method using SLServiceTypeFacebook works and I have linked accounts to both services. It was working perfectly before I upgraded to 8.3 – user3587825 Apr 14 '15 at 16:43
  • You have to include the check I posted before calling the share functions. In my case I tried my apps where I implemented it exactly this way and everything works fine. Don't know whats exactly the problem. In case you want to be sure nothing like this happenes include a check if a specific app is available on the phone by calling the appURL – Alex Cio Apr 17 '15 at 13:58