2012-04-13 58 views
0

在此先感谢我每次调用应用程序短信我收到以下错误创建...iPhone的iOS 5 SDK中的应用程序短信错误

应用程序尝试对目标推零视图控制器。

这是我在OS 4 SDK工作的代码...

MFMailComposeViewController *MailController; 
MFMessageComposeViewController *SMScontroller; 
NSError *error; 
NSString *EmailMessage; 
NSString *SubjectMessage; 

-(IBAction)sendInAppSMS 
{ 

    if([MFMessageComposeViewController canSendText]) 
    { 
     SMScontroller = [[MFMessageComposeViewController alloc] init]; 
     SMScontroller.messageComposeDelegate = self; 

     NSString *MessageString = @"Hello"; 

     SMScontroller.body = MessageString; 

     SMScontroller.navigationBar.tintColor = [UIColor blackColor]; 

     [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackOpaque]; 

     [self presentModalViewController:SMScontroller animated:YES]; 

     [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackOpaque]; 
    } 
    else{ 
     // alertView to tell user to setup a mail account. 
     NSString *message = [[NSString alloc] initWithFormat:@"To use this feature, you need to have an iPhone with SMS abilities."]; 
     UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"SMS Account Not Detected" message:message delegate:nil cancelButtonTitle:@"Understood" otherButtonTitles:nil]; 
     [alert show]; 
    } 

} 

- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result 
{ 
    switch (result) { 
     case MessageComposeResultCancelled: 
     { 
      UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"I Like It" message:@"User cancelled sending the SMS" 
                  delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil]; 
      [alert show]; 
     } 
      break; 
     case MessageComposeResultFailed: 
     { 
      UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"I Like It" message:@"Error occured while sending the SMS" 
                  delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil]; 
      [alert show]; 
     } 
      break; 
     case MessageComposeResultSent: 
     { 
      UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"I Like It" message:@"SMS sent successfully..!" 
                  delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil]; 
      [alert show]; 
     } 
      break; 
     default: 
      break; 
    } 

    [self dismissModalViewControllerAnimated:YES]; 
} 

回答

1

我相信,如果你是在模拟器中运行这个,因为它不具备短信,你会得到错误。我在模拟器中得到相同的错误,但如果我连接到我的手机它工作正常。