に複数の写真を添付しようとしていますが、複数の写真を選択するため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 ですが、メモリは常に減少しています。メモリを適切に解放できません。一部のメモリがリークしています。リークを見つけるのを手伝ってください。