私は iOS 開発に飛び込んでおり、添付ファイル付きの電子メールを送信するための MFMailComposeViewController クラスに慣れるために遊んでいます。添付しようとしているデータは、実行時に収集され、NSDictionary に保存され、NSData にシリアル化された情報ですが、電子メールが送信されるたびに添付ファイルの兆候はありません。私のコードでは、最初に受信者の電子メール、本文、および件名が既に入力された MFMailComposeViewController ビューを表示します。次に、匿名データを収集できるかどうかをユーザーに尋ねる警告ボックスを表示します。ユーザーが [はい] をクリックすると、アラート ビューのコールバック メソッドがデータをコンパイルし、MFMailComposeViewController にアタッチします。デバッガーでステップ実行すると、すべてのデータが正しく表示されますが、添付されたデータが電子メールで届きません。これが私のコードです...
-(void)displayComposerSheet
{
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
[picker setSubject:@"Temp Subject Line"];
NSArray *toRecipients = [NSArray arrayWithObjects:@"support@tempaddress.com", nil];
[picker setToRecipients:toRecipients];
NSString *emailBody = @"Temporary email body";
[picker setMessageBody:emailBody isHTML:NO];
[self setMailViewController:picker];
[self presentModalViewController:picker animated:YES];
UIAlertView* uiav= [[UIAlertView alloc] initWithTitle: @"May we collect data from you?"
message: @"May we collect some data form you?"
delegate: self cancelButtonTitle: @"No" otherButtonTitles: nil];
[uiav addButtonWithTitle:@"Yes"];
[uiav setDelegate:self];
[uiav show];
[uiav release];
[picker release];
}
- (void) alertView:(UIAlertView*)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if(buttonIndex == 1)
{
NSMutableDictionary *appData = [[[NSMutableDictionary alloc] init] autorelease];
.
. //Compile the application data to attach to email
.
NSString *errorString = [[[NSString alloc] init] autorelease];
NSData *attachData = [NSPropertyListSerialization dataFromPropertyList:appData format:NSPropertyListXMLFormat_v1_0 errorDescription:&errorString];
[[self mailViewController] addAttachmentData:attachData mimeType:@"text/xml" fileName:@"app data"];
}
}
}
何か案は?MFMailComposeViewController をロードした後にデータを添付しようとしているという事実と関係がありますか?
あなたの知恵に感謝します!