短信在ios 6上没有MFMessgeViewController发送

时间:2012-12-01 17:58:05

标签: iphone objective-c ios6

任何人都不能在iOS6中以编程方式发送短信。之前我使用核心电话方法发送短信。它正常工作到iOS5但在iOS6我的代码无效。 我使用以下代码:

BOOL success = [[CTMessageCenter sharedMessageCenter] sendSMSWithText:@“Message”serviceCenter:nil toAddress:@“8800781656”];

我做错了什么?

提前致谢

2 个答案:

答案 0 :(得分:0)

我会做出有根据的猜测,Apple已经关闭了他们的API中的循环漏洞。他们不希望应用程序在没有用户知识的情况下在后台发送SMS消息。在某些移动网络上,每条SMS消息都要花钱。

答案 1 :(得分:0)

// in .m file
-(void)textClicked

{


 controller = [[MFMessageComposeViewController alloc] init];

 if([MFMessageComposeViewController canSendText])

    {


       controller.body = @"Whatever you want";

   controller.recipients = [NSArray arrayWithObjects:@"", nil];

       controller.messageComposeDelegate = self;

       [self presentViewController:controller animated:YES completion:nil];
      }


   }

  - (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result

  {

  UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"MyApp" message:@"Unknown Error"
                                               delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];

switch (result) {
    case MessageComposeResultCancelled:
        NSLog(@"Cancelled");
        [alert show];
        break;
    case MessageComposeResultFailed:
        [alert show];

        break;
    case MessageComposeResultSent:

        break;
    default:
        break;
  }

[self dismissViewControllerAnimated:YES completion:nil];
    }



// in .h file

 import MessageUI/MessageUI.h
 and delegate for Sending Message is  MFMessageComposeViewControllerDelegate

希望,这对你有帮助。