2

任何人都不能以编程方式发送短信。iOS6早些时候我使用核心电话方法发送短信。它工作正常,iOS5iOS6我的代码不起作用。我使用以下代码:

BOOL 成功 = [[CTMessageCenter sharedMessageCenter] sendSMSWithText:@"Message" serviceCenter:nil toAddress:@"8800781656"];

我究竟做错了什么?

提前致谢

4

2 回答 2

0

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

于 2012-12-01T18:50:17.000 回答
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

希望对你有帮助。

于 2012-12-05T11:16:34.663 回答