MFMailComposeViewController の起動と終了後に iPhone アプリケーションに遅延が発生する
-
19-09-2019 - |
質問
テーブルビューコントローラーを使用していくつかの項目を表示するアプリケーションがあります。それらの項目のいずれかをクリックした後、この項目を電子メールで送信することを選択できます。それが起こったら、Apple の "MailComposer" が提供するコードを使用してメールを送信します。ただし、この後、テーブル ビューのスクロールは以前ほどスムーズではなくなります。
「リーク」で確認したところ、コードにリークはありませんでしたが、MFMailComposeViewController のモーダル ビュー コントローラーのときに大量のオブジェクト割り当てがあり、コントローラーを閉じると、オブジェクト割り当てがすべてまだそこにあります。オブジェクトの割り当てをすべて削除するにはどうすればよいですか?ご協力をよろしくお願いいたします。ありがとう。
-オスカー
アップデート:
遅延が発生するのは、[宛先] をクリックした場合のみであることがわかりました。MFMailComposeViewController のテキスト フィールドに何かを入力すると、メモリ リークが発生し、アプリケーションが遅くなります。これと全く同じことが Apple の Mail Composer でも起こります。シミュレーターを使用しているのですが、これが原因でしょうか?他に同じような経験をした人はいますか?
コントローラーを押す方法は次のとおりです。
-(void)displayComposerSheet
{
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
NSString *mailSubject = appDelegate.mailTitle;
NSString *mailBody = appDelegate.mailLink;
NSString *formattedString = [NSString stringWithFormat:@"<a href='%@'>%@</a>", mailBody, mailBody];
[picker setSubject:mailSubject];
// Set up recipients
//NSArray *toRecipients = [NSArray arrayWithObject:@"somemail@hotmail.com"];
//NSArray *ccRecipients = [NSArray arrayWithObjects:@"second@example.com", @"third@example.com", nil];
//NSArray *bccRecipients = [NSArray arrayWithObject:@"fourth@example.com"];
//[picker setToRecipients:toRecipients];
//[picker setCcRecipients:ccRecipients];
//[picker setBccRecipients:bccRecipients];
// Attach an image to the email (Warning this causes a memory leak aknowledged by Apple)
//NSString *path = [[NSBundle mainBundle] pathForResource:@"news_icon" ofType:@"png"];
//NSData *myData = [NSData dataWithContentsOfFile:path];
//[picker addAttachmentData:myData mimeType:@"image/png" fileName:@"rainy"];
// Fill out the email body text
[picker setMessageBody:formattedString isHTML:YES];
[self presentModalViewController:picker animated:YES];
[picker release];
}
そしてここでそれを却下します:
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
....
[self dismissModalViewControllerAnimated:YES];
}
解決
これは既知のメモリ リークです MFMailComposeViewController
クラス (iOS 4.2 SDK 以降)。漏れは、 メールコンポーザ Apple によるサンプルプロジェクト。割り当てインストゥルメントを使用してアプリを実行してみて、キャンセルをクリックしてコンポーザーを再度表示するたびに、全体のバイト数が増加していることに注意してください。
同様の議論については以下を参照してください。
他のヒント
必ず使用してください。
controller.mailComposeDelegate = self;
とない
controller.delegate = self;