Sms sending without MFMessgeViewController on ios

2019-07-23 16:10发布

Anybody no to send sms programmatically in iOS6.Earlier I was using core telephony method to send SMS.It's working fine up to iOS5 but on iOS6 my code is not working. I using following code:

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

What am I doing wrong?

Thanks in advance

2条回答
forever°为你锁心
2楼-- · 2019-07-23 16:36

I would make an educated guess that Apple has closed a loop hole in their API. They do not want applications to send SMS message in the background without the user knowledge. On some mobile network each SMS message cost money.

查看更多
做个烂人
3楼-- · 2019-07-23 16:48
// 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

Hope , This will help You.

查看更多
登录 后发表回答