16

following situation: I want to send in app SMS. This is my code creating the MFMessageComposeViewController:

-(void) showMessageComposerWithText:(NSString*)messageText telNumber:(NSString*)telNumber composeDelegate:(id)delegate
{
    MFMessageComposeViewController *controller = [[MFMessageComposeViewController alloc] init];
    if([MFMessageComposeViewController canSendText])
    {   
        controller.body = messageText;
        controller.recipients = [NSArray arrayWithObject:telNumber];
        controller.messageComposeDelegate = delegate;

        [delegate presentModalViewController:controller animated:YES];
    }
}

So I think this is straight forward. When testing in Simulator I get following exception: Application tried to push a nil view controller on target <MFMessageComposeViewController: 0x8a4e090>. I'm also wondering myself why [MFMessageComposeViewController canSendText] returns YES when running the app in the simulator.

When running on the device, everything is working correctly.

I couldn't find anything in the docs/web concerning this strange behavior.

I'm running Xcode 4.3 on OS 10.7.3, Deployment Target is iOS 5.0.

Thanks in advance, tubtub

bhr
  • 2,279
  • 1
  • 23
  • 31

4 Answers4

23

This problem occurs when you install Messages beta on OS X Lion.

Edit: It also occurs on Mountain Lion when there is an iMessage account configured and enabled. If the account is disabled, it works correctly (canSendText returns NO).

Tip: If you use controller.modalTransitionStyle = UIModalTransitionStylePartialCurl, you can go back in Simulator by clicking on the curled "page" in the upper left corner.

Marián Černý
  • 15,096
  • 4
  • 70
  • 83
  • 2
    If Messages beta installed, `canSendText` returns `YES`, but view will become black and empty (no content). If Messages beta uninstalled, `canSendText` returns `NO`. Xcode 4.4 GM and iPhone 5.1 Simulator on Lion. – Chris Jul 15 '12 at 09:29
  • Any fix for this yet? This bug persists on Mac OS 10.8.2 with XCode 4.6.1. – Maciej Swic May 16 '13 at 14:40
4

The simulator should always return NO from the canSendText, this isn't the case for the iOS 5.0 and 5.1 simulators. With Xcode 4.2 it crashed, on Xcode 4.3 it just pushes a nil view controller.

Daniel
  • 23,129
  • 12
  • 109
  • 154
  • Im having the same issue, that a nil view is being pushed but it is even happening on my test device an iPhone 4 running iOS 5.1 – OscarTheGrouch Apr 13 '12 at 10:57
2

I'm seeing the same thing. I think it's a bug in the iOS 5 simulator with Xcode 4.3. canSendText correctly returns NO in the iOS 4.3 simulator. The same code works fine on the device.

Christopher Pickslay
  • 17,523
  • 6
  • 79
  • 92
1

With this configuration, canSendText returns correctly NO in the simulator (plus, a UIAlertView appears to say text messaging is not available):

  • Mountain Lion
  • Xcode 4.4,
  • iOS 5.1