2012-10-05 69 views
7

在我的新iOS項目中,我希望最終用戶能夠在UIButton操作中使用MMS text and/or images(來自TextField)。我已經看到類似的應用程序具有此功能(文本,還沒有看到有圖像)。如何從iPhone應用程序發送彩信

我在谷歌搜索,但沒有找到如何做到這一點,任何幫助非常感謝

回答

18

這將正常工作

MFMessageComposeViewController *picker = [[MFMessageComposeViewController alloc] init]; 

UIPasteboard *pasteboard = [UIPasteboard generalPasteboard]; 
pasteboard.persistent = YES; 
pasteboard.image = [UIImage imageNamed:@"PDF_File.png"]; 

NSString *phoneToCall = @"sms:"; 
NSString *phoneToCallEncoded = [phoneToCall stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding]; 
NSURL *url = [[NSURL alloc] initWithString:phoneToCallEncoded]; 
[[UIApplication sharedApplication] openURL:url];  

if([MFMessageComposeViewController canSendText]) { 
    NSMutableString *emailBody = [[NSMutableString alloc] initWithString:@"Your Email Body"]; 
    picker.messageComposeDelegate = self; 
    picker.recipients = [NSArray arrayWithObject:@"123456789"]; 
    [picker setBody:emailBody];// your recipient number or self for testing 
    picker.body = emailBody; 
    NSLog(@"Picker -- %@",picker.body); 
    [self presentModalViewController:picker animated:YES]; 
    NSLog(@"SMS fired"); 
} 
+0

在你的文本框,點擊文本框,並將其粘貼 –

+0

把你的圖片你想發送。 –

+0

非常感謝。我期待測試這個代碼。我感謝您的幫助。 –