[英]pdf not added to email in objective-c in IOS 5
我正在嘗試將電子郵件添加為郵件的附件。 我是這樣的
-(IBAction)mailPDF:(id)sender{
MFMailComposeViewController* controller = [[MFMailComposeViewController alloc] init];
controller.mailComposeDelegate = self;
NSLog(@"myData is %@",myData);
[controller setSubject:@"Geselecteerde favorieten van Genk on Stage"];
[controller setMessageBody:@"<p>Hallo muziekliefhebber <br /> In bijlage vind je jouw favorieten. Volg en praat met ons mee op facebook.com/genkonstage of @genkonstage!<br /> Veel plezier op Genk on stage! </p>" isHTML:YES];
if (controller){
[self presentModalViewController:controller animated:YES];
[controller addAttachmentData:myData mimeType:@"application/pdf" fileName:@"favorite.pdf"];
}else{
NSLog(@"nothing to show");
}
}
這就是我設置myData的方式
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *filePath = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"favorite.pdf"];
myData = [NSData dataWithContentsOfFile: filePath];
當我查看日志myData
(這是我的pdf)時,它不是空的。 同樣,當我在查找程序中瀏覽到simulator
文件文件夾時,我看到我有一個PDF。
有人可以告訴我為什么我的PDF文件沒有添加到我的郵件中嗎?
謝謝!
編輯似乎上述代碼僅在IOS6中有效。 現在的問題是。 為什么它在IOS 5中不起作用
首先要顯示視圖控制器,然后再附加文件。 更改操作順序:
也就是說,在您的代碼行中:
[self presentModalViewController:controller animated:YES];
[controller addAttachmentData:myData mimeType:@"application/pdf" fileName:@"favorite.pdf"];
將它們修改為:
[controller addAttachmentData:myData mimeType:@"application/pdf" fileName:@"favorite.pdf"];
[self presentModalViewController:controller animated:YES];
希望它能解決問題:)
嘗試這個,
-(IBAction)mailPDF:(id)sender{
MFMailComposeViewController* controller = [[MFMailComposeViewController alloc] init];
controller.mailComposeDelegate = self;
NSLog(@"myData is %@",myData);
[controller setSubject:@"Geselecteerde favorieten van Genk on Stage"];
[controller setMessageBody:@"<p>Hallo muziekliefhebber <br /> In bijlage vind je jouw favorieten. Volg en praat met ons mee op facebook.com/genkonstage of @genkonstage!<br /> Veel plezier op Genk on stage! </p>" isHTML:YES];
if (controller)
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *filePath = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"favorite.pdf"];
NSData *myData = [NSData dataWithContentsOfFile:filePath];
[controller addAttachmentData:myData mimeType:@"application/pdf" fileName:@"favorite.pdf"];
[self presentModalViewController:controller animated:YES];
}
else{
NSLog(@"nothing to show");
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.