0

以下のようにしているのですが、ログを取ると必ず画像が添付できなかったと返ってきます。ここで何が問題なのですか?

- (void)showInvitation {

if (![MFMessageComposeViewController canSendText]) {

    UIAlertView *warningAlert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Your device doesn't support SMS!" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [warningAlert show];
    return;
}

NSString *message = [NSString stringWithFormat:@"Download this game!"];
MFMessageComposeViewController *messageController = [[MFMessageComposeViewController alloc] init];
messageController.messageComposeDelegate = self;
[messageController setBody:message];

if ([MFMessageComposeViewController canSendAttachments]) {
    NSLog(@"Attachments Can Be Sent.");
    NSData *imgData = [NSData dataWithContentsOfFile:@"water"];
    BOOL didAttachImage = [messageController addAttachmentData:imgData typeIdentifier:(NSString *)kUTTypePNG filename:@"image.png"];

    if (didAttachImage) {
        NSLog(@"Image Attached.");

    } else {
        NSLog(@"Image Could Not Be Attached.");
    }
}

[self presentViewController:messageController animated:YES completion:nil];
}
4

2 に答える 2

0

このコードを試してください。それは私にとってはうまくいっています。

 if (MFMessageComposeViewController.canSendText()) {


            let controller = MFMessageComposeViewController()

controller.body = "Solution of broken image in composer while sending through MFMessageComposserViewController "


            controller.messageComposeDelegate = self

            if image.imageAsset != nil {

                let imageData = UIImageJPEGRepresentation(self.fixOrientation(img: image), 1)  //! as NSData
                controller.addAttachmentData(imageData! , typeIdentifier: "image/.jpeg", filename: "image.jpeg")

            }

            self.present(controller, animated: true, completion: {
                completion(true)
            })


        }
        }
于 2017-11-03T06:33:28.770 に答える