2

I want to popup MFMessageCompose model on (topviewcontroller) from another NSObject class method which is executed in background.

I popup MFMessageCompose model using this code :

MFMessageComposeViewController * controller = [[MFMessageComposeViewController alloc] init];
if([MFMessageComposeViewController canSendText])
{
    controller.body = @"Check out FundooSpace for mobile.Download it now from app.fundoospace.net/FundooSpace/d";
    controller.recipients = (NSArray *)passa;
    passa = nil;
    AppDelegate * appDelegateObject1 = (AppDelegate *)[[UIApplication sharedApplication] delegate];
    controller.messageComposeDelegate = self;
    [appDelegateObject1.navigationCntr.topViewController presentModalViewController:controller animated:NO];
}

it works fine. but when i click on send or cancel button then app get crash and gives error is

wait_fences: failed to receive reply: 10004003

please suggest me.

Vedchi
  • 1,200
  • 6
  • 14
Mahesh
  • 317
  • 1
  • 3
  • 17

1 Answers1

0

I exactly checked the code what you included in your question and for me it is working nicely running on device.

1) make sure to have the delegate in your .h

@interface ViewController : UIViewController <MFMessageComposeViewControllerDelegate>

2) You have to implement the delegate method also in your .m:

- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result {
    NSLog(@"didFinishWithResult");

    // you have to deal with the result var

    switch (result) {
        case MessageComposeResultCancelled:
            NSLog(@"Cancelled");
            break;
        case MessageComposeResultFailed:
            UIAlertView *alert = [[UIAlertView alloc] 
                          initWithTitle:@"MyApp" 
                                message:@"Unknown Error"
                               delegate:self 
                      cancelButtonTitle:@”OK” 
                      otherButtonTitles:nil];
            [alert show];
            [alert release];
            break;
        case MessageComposeResultSent:

            break;
        default:
            break;
    }

    [self dismissModalViewControllerAnimated:YES];
}

3) if you are on >iOS6.0 the "old" presentModalViewController:animated is deprecated, so change to presentViewController:animated:completion: as Xcode also indicates this.

nzs
  • 3,252
  • 17
  • 22
  • As many SO article about wait_fences error, my working test also presents a wait_fence error.. If your app perfectly runs on device you can ignore this message (eg. according to this SO article: http://stackoverflow.com/a/9046838/2129209) – nzs Apr 23 '13 at 14:14
  • Also others said that some delaying could help when presenting modal view, since iOS framework might have some resource-run issue when quickly presenting modal view. So I tried for your code including this: [self performSelector:@selector(showmsg) withObject:nil afterDelay:0.5]; and making the messagecomposer show method into showmsg. Still wait_fences error is coming, but test-app works prefectly, sends sms nicely. – nzs Apr 23 '13 at 14:17