我正在尝试在 a 中附加多张照片,MailComposerViewController
并且我正在使用ALAssetPickerViewController
它来挑选多张照片。我有一个NSMutableArray
,其中包含所选资产的参考。我正在实现一个for loop
枚举array
要获取NSData
的选定资产UIImage
并UIImage
使用CGImageRef
. 代码如下:
@autoreleasepool
{
NSString *emailTitle = @"Test";
NSString *messageBody = @"IOS programming is so fun!";
NSArray *toRecipents = [NSArray arrayWithObjects:@"abc@gmail.com", nil];
MFMailComposeViewController *tempmcvc = nil;
tempmcvc = [[MFMailComposeViewController alloc] init];
tempmcvc.mailComposeDelegate = self;
[tempmcvc setSubject:emailTitle];
[tempmcvc setMessageBody:messageBody isHTML:YES];
[tempmcvc setToRecipients:toRecipents];
tempmcvc.modalPresentationStyle=UIModalPresentationFullScreen;
tempmcvc.navigationBar.barStyle = UIBarStyleBlackOpaque;
for (AlAsset *assets in SelectedAssetsarray)
{
@autoreleasepool
{
UIImage *attachImagTemp = nil;
NSData *myData = nil;
CGImageRef iref = [assets.defaultRepresentation fullScreenImage];
NSString *nameOfImgTemp;
attachImagTemp = [UIImage imageWithCGImage:iref];
nameOfImgTemp = assets2.defaultRepresentation.filename;
myData = UIImageJPEGRepresentation (attachImagTemp, 1.0);
[tempmcvc addAttachmentData:myData mimeType:@"image/jpeg" fileName:nameOfImgTemp];
myData = nil;
attachImagTemp = nil;
iref = nil;
nameOfImgTemp = nil;
ALAsset *_temp = assets2;
_temp = nil;
}
}
}
dispatch_async(dispatch_get_main_queue(), ^(void) {
[self presentModalViewController:tempmcvc animated:YES]
});
我附加的每个资产几乎没有 2 MB,但内存不断减少,我无法正确释放内存;一些内存泄漏,请帮助查找泄漏。