我試圖通過Xcode以編程方式發送消息,但是當我單擊發送按鈕時,它會打開消息發送框。但是我想直接發送消息而不打開消息框。 這是可能的iOS Xcode或不?請幫幫我。 以編程方式通過Xcode發送消息
但不想打開發送消息框。
代碼
- (IBAction)sendSMS:(id)sender
{
MFMessageComposeViewController *controller = [[MFMessageComposeViewController alloc] init];
if([MFMessageComposeViewController canSendText])
{
controller.body = @"Hello this is anup";
controller.recipients = [NSArray arrayWithObjects:@"7026144009", nil];
controller.messageComposeDelegate = self;
[self presentModalViewController:controller animated:YES];
}
}
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
{
switch (result)
{
case MessageComposeResultCancelled:
NSLog(@"Cancelled");
break;
case MessageComposeResultFailed:
{
NSLog(@"faild");
UIAlertController *alrt=[UIAlertController alertControllerWithTitle:@"my apps" message:@"unknown error" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action){
//do something when click button
}];
[alrt addAction:okAction];
break;
}
case MessageComposeResultSent:
break;
default:
break;
}
[self dismissModalViewControllerAnimated:YES];
}
你有沒有這樣過發送的短信.. [UIApplication的sharedApplication]的OpenURL:[NSURL URLWithString:@ 「短信:919999999999」]] –
然後創建一個擁有自己的視圖並獲取所有用戶詳細信息,最後將詳細信息發送到後端服務器,後端服務器將短信觸發到特定的號碼。 –
可能重複[如何以編程方式在iPhone上發送短信?](http://stackoverflow.com/questions/10848/how-to-programmatically-send-sms-on-the-iphone) – Avi