Sms sending without MFMessgeViewController on ios 6

霸气de小男生 提交于 2019-12-11 01:55:15

问题


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


回答1:


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.




回答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

Hope , This will help You.



来源:https://stackoverflow.com/questions/13662105/sms-sending-without-mfmessgeviewcontroller-on-ios-6

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!