2014-02-03 1 views
0

У меня есть концепция обмена контактами в моем приложении и используется MFMessageComposeViewController.Ошибка MFMessageController иногда

-(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 *[email protected]""; 
      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]; 
} 

Это код Im используя, который врезается иногда и отображает ошибку

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

Я положил точку останова для отладки, но Xcode не showup, где производится ошибка.

Любые идеи/предложения будут заметны ..

+0

Это: 'if ([[[[UIDevice currentDevice] systemVersion] floatValue] <5.0)' не является правильным способом проверить, доступен ли метод, вы должны использовать: 'if ([self responsesToSelector: @selector (presentViewController: анимированный: завершение :)]) ' – rckoenes

+0

Также нет необходимости проверять iPad в вашем коде. iOS автоматически загрузит '~ ipad' на iPad. – rckoenes

ответ

0

Включить зомби объектов, чтобы выяснить линию фактического краха. Вы можете включить зомби~d с помощью следующих шагов:

1.Select проецирование схемы и выбрал схему редактирования.
2. Появится окно, теперь выберите диагностику.
3.Выберите галочку для включения объектов зомби.

Теперь запустите проект.

+0

Чтобы проверить использование Zombie, мы не можем проверить симулятор для MFMessageController.So Im не удалось сделать это также – Honey

+0

Запустите проект на устройстве. –

+0

Да, я запустил его на устройстве, но он не показывает мне точку исключения. Я просто получаю эту ошибку и прекращаю работу – Honey

Смежные вопросы