发送带有短信的图像

时间:2017-01-20 09:33:49

标签: ios objective-c mfmessagecomposeview

我想用我的短信发送图片。我使用过MFMessageComposeViewController。这是我所做的代码:

MFMessageComposeViewController *messageController = [[MFMessageComposeViewController alloc] init];
messageController.messageComposeDelegate = self;
NSArray *recipents = @[[arr_promoterDetaildata valueForKey:@"phone_number"], @"72345524"];

UIImage *img = [UIImage imageNamed:@"ic_dummy_img"];
NSData *imgData = UIImagePNGRepresentation(img);
BOOL didAttachImage = [messageController addAttachmentData:imgData typeIdentifier:(NSString *)kUTTypePNG filename:@"image.png"];

NSString *message = [NSString stringWithFormat:@"Sending SMS"];

[messageController setRecipients:recipents];
[messageController setBody:message];
if (didAttachImage)
{
    // Present message view controller on screen
    [self presentViewController:messageController animated:YES completion:nil];
}
else 
{
    UIAlertView *warningAlert = [[UIAlertView alloc] initWithTitle:@"Error"
                                                           message:@"Failed to attach image"
                                                          delegate:nil
                                                 cancelButtonTitle:@"OK"
                                                 otherButtonTitles:nil];
    [warningAlert show];
    return;
}

我尝试了很多方法,但它没有在我的消息屏幕中附加图像。有人可以帮忙吗?

0 个答案:

没有答案