【问题标题】:Sms sending without MFMessgeViewController on ios 6在 ios 6 上发送没有 MFMessgeViewController 的短信
【发布时间】:2012-12-01 17:58:05
【问题描述】:

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

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

我做错了什么?

提前致谢

【问题讨论】:

  • 如何导入 CTMessageCenter 头文件。

标签: iphone objective-c ios6


【解决方案1】:

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

【讨论】:

  • 没关系 Black 但是我开发了应用程序,我只是卡在 ios 6 上。如果可能,请建议或提供代码。
  • 同意@Black Frog。不知道你的业务逻辑,但是如果你可以使用第三方短信服务(通常要花钱;)),它只是对第三方API的调用(通常是一个Web API,意味着一个HTTP请求)
【解决方案2】:
// 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

希望对你有帮助。

【讨论】:

  • 我不想使用消息视图控制器。我想在应用程序后台发送短信。
  • 在后台发送短信已被 Apple 限制。如果您想通过您的应用发送短信,这是唯一的方法。
  • 一定有办法做到这一点——越狱iOS设备的biteSMS应用程序在iOS 6中发送SMS(和iMessages)......这只是弄清楚/询问如何执行发送的问题.
猜你喜欢
  • 2013-01-26
  • 2012-04-30
  • 2016-11-27
  • 1970-01-01
  • 1970-01-01
  • 2019-07-14
  • 2023-03-16
  • 2012-02-18
  • 2015-10-26
相关资源
最近更新 更多