0

I have the concept of sharing to contacts in my App and used MFMessageComposeViewController.

-(IBAction)btnAddClicked:(id)sender {

    @try {

        selections = [[NSMutableArray alloc] init];
        for(NSIndexPath *indexPath in arSelectedRows) {
            NSMutableDictionary *searchable = [[NSMutableDictionary alloc
                                                ]init];

            [searchable setObject:[[contactsArray objectAtIndex:indexPath.row]objectForKey:@"Phone"]forKey:@"Phone"];
            [selections addObject:searchable];
        }
        if([selections count]>0)
        {
            NSString *temp1=@"";
            for(int i=0;i<[selections count];i++)
            {

                toRecepients=[[selections objectAtIndex:i]objectForKey:@"Phone"];

                temp1=[temp1 stringByAppendingString:toRecepients];
                temp1=[temp1 stringByAppendingString:@","];

            }

            temp1 = [temp1 substringToIndex:[temp1 length]-1];


            if(![MFMessageComposeViewController canSendText]) {
                UIAlertView *warningAlert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Your device doesn't support SMS!" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
                [warningAlert show];
                return;


            }

            NSArray *recipents = [temp1 componentsSeparatedByString:@","];

          MFMessageComposeViewController *messageController = [[MFMessageComposeViewController alloc] init];
            messageController.messageComposeDelegate = self;
            messageController.navigationBar.topItem.leftBarButtonItem.title = @"Cancel";
            [messageController setRecipients:recipents];
            [messageController setBody:self.message];

            [self presentModalViewController:messageController animated:YES];
        }

        else{
            UIAlertView *warningAlert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Select the contacts you would like to share to" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
            [warningAlert show];
            return;



        }

    }

        @catch (NSException *exception) {
            if (UI_USER_INTERFACE_IDIOM()==UIUserInterfaceIdiomPhone)
            {
                ErrorView *errorView=[[ErrorView alloc]initWithNibName:@"ErrorView" bundle:nil];
                if([[[UIDevice currentDevice]systemVersion]floatValue]<5.0)
                {
                    [self presentModalViewController:errorView animated:YES];
                }
                else
                {
                    [self presentViewController:errorView animated:YES completion:nil];
                }
                [errorView release];

            }
            if (UI_USER_INTERFACE_IDIOM()==UIUserInterfaceIdiomPad) {
                ErrorView *errorView=[[ErrorView alloc]initWithNibName:@"ErrorView~iPad" bundle:nil];
                if([[[UIDevice currentDevice]systemVersion]floatValue]<5.0)
                {
                    [self presentModalViewController:errorView animated:YES];
                }
                else
                {
                    [self presentViewController:errorView animated:YES completion:nil];
                }
                [errorView release];

            }
        }    }

    - (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult) result {
        switch (result) {
            case MessageComposeResultCancelled:
            {
                UIAlertView *warningAlert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Failed to send SMS!" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
                [warningAlert show];
                break;
            }

            case MessageComposeResultFailed:
            {
                UIAlertView *warningAlert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Failed to send SMS!" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
                [warningAlert show];
                break;
            }

            case MessageComposeResultSent:
            {
                NSString *messa=[NSString stringWithFormat:@"Shared to %lu contact(s)",(unsigned long)[selections count]];
                UIAlertView *warningAlert = [[UIAlertView alloc] initWithTitle:@"Succesful" message:messa delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
                [warningAlert show];
                break;
            }

            default:
                break;
        }

        [self dismissViewControllerAnimated:YES completion:nil]; 
}

This is the code Im using, which crashes sometimes and displays the error

Assertion failed: (result == KERN_SUCCESS), function +[XPCMachSendRight wrapSendRight:], file /SourceCache/XPCObjects/XPCObjects-46/XPCMachSendRight.m, line 27.

I have put breakpoint to debug, but xcode doesn't showup where the error is produced.

Any ideas/ suggestions would be appreciable..

Marco
  • 6,692
  • 2
  • 27
  • 38
Honey
  • 2,840
  • 11
  • 37
  • 71
  • This: `if([[[UIDevice currentDevice]systemVersion]floatValue]<5.0)` is not the correct way to checking if a method is available, you should be using: `if([self respondsToSelector:@selector(presentViewController:animated:completion:)])` – rckoenes Feb 03 '14 at 08:48
  • Also there is no need to check for the iPad in your code. iOS will load the `~ipad` automatically on an iPad. – rckoenes Feb 03 '14 at 08:55

1 Answers1

0

Enable zombie Objects to find out the line of actual crash. You can enable Zombie by following steps:

1.Select you project scheme and chose edit scheme.
2.A window will appear, now select diagnostics.
3.Select check mark for enable Zombie objects.

Now run your project.

Aman Aggarwal
  • 3,754
  • 1
  • 19
  • 26