ios - Xcode : Add attachment using picker to email
<p><p>我开发了一个应用程序,允许用户从照片库中选择一个视频并将其作为电子邮件的附件发送。我可以从图库中选择一个视频并继续发送电子邮件,但该视频没有随电子邮件附上。控制台中没有错误。 </p>
<p>ViewController.h:</p>
<pre><code>#import <UIKit/UIKit.h>
#import <MobileCoreServices/MobileCoreServices.h>
#import <MessageUI/MessageUI.h>
@interface ViewController : UIViewController<UIImagePickerControllerDelegate, UINavigationControllerDelegate,MFMailComposeViewControllerDelegate>
@property (strong, nonatomic) IBOutlet UIImageView *imageView;
- (IBAction)choose:(id)sender;
@end
</code></pre>
<p>ViewController.m:</p>
<pre><code>#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
;
// Do any additional setup after loading the view, typically from a nib.
if (!) {
UIAlertController *myAlertController = [UIAlertControlleralertControllerWithTitle:@"MyTitle"
message: @"MyMessage"
preferredStyle:UIAlertControllerStyleAlert ];
;
}
}
- (void)didReceiveMemoryWarning {
;
// Dispose of any resources that can be recreated.
}
- (IBAction)choose:(id)sender {
UIImagePickerController *picker = [ init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
picker.mediaTypes = [ initWithObjects:(NSString *)kUTTypeMovie, nil];
;
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *chosenImage = info;
;
;
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
;
}
- (void)email:(UIImage *)choosenImage{
NSString *iOSVersion = [ systemVersion];
NSString *model = [ model];
NSString *version = @"1.0";
NSString *build = @"100";
MFMailComposeViewController *mailComposer = [ init];
mailComposer.mailComposeDelegate = self;
];
];
NSString *supportText = ;
supportText = ;
;
NSData *data = UIImagePNGRepresentation(choosenImage);
;
;
}
- (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
{
;
}
@end
</code></pre>
<p>任何建议/帮助将不胜感激。谢谢。</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>您提到您正在尝试附加视频,并且您已将 UIImagePickerController 配置为将 mediaTypes 限制为仅视频。那么问题是您在“didFinishPickingMediaWithInfo”方法中要求“编辑图像”:</p>
<pre><code>UIImage *chosenImage = info;
</code></pre>
<p>用户没有选择图片 - 他们选择了视频。你需要改用这个:</p>
<pre><code>NSURL *chosenVideoUrl = info;
NSData *videoData = ;
</code></pre>
<p>然后您可以将 videoData 传递给您的电子邮件方法并附加到电子邮件中。请务必将 mimeType 从“image/png”更新为“video/mp4”。</p></p>
<p style="font-size: 20px;">关于ios - Xcode : Add attachment using picker to email,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/33748073/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/33748073/
</a>
</p>
页:
[1]