开发者

PDF File / URL in local filesystem

开发者 https://www.devze.com 2023-01-27 19:21 出处:网络
Hy! I had generate a PDF File on my iPhone App. Now I want to send it via EMail - i use the MailViewController and have to add my attachment, but now the question...

Hy!

I had generate a PDF File on my iPhone App. Now I want to send it via EMail - i use the MailViewController and have to add my attachment, but now the question...

Whick URL shou开发者_如何学Gold I write when I only written the filename.pdf at the PDFContext?


To send a pdf file that is included as a resource in your app:

NSString *path = [[NSBundle mainBundle] pathForResource:@"filename" ofType:@"pdf"];

To send a pdf file that you've GENERATED in your app:

  1. write to disk.
  2. use the path to attach it to the email.

For a detailed discussion of temp directories, read this: http://cocoawithlove.com/2009/07/temporary-files-and-folders-in-cocoa.html But in short:

NSString *filePath = [NSTemporaryDirectory() stringByAppendingPathComponent:@"filename.pdf"];
if ([fileData writeToFile:filePath atomically:YES]) {
    NSLog(@"success!");
} else {
    NSLog(@"fail");
}

the path you use to create a PDFContext should be in either the documents directory, or the temp directory, depending on how long you want the file to persist. "filename.pdf" is not a valid path to be creating a pdf context with.

0

精彩评论

暂无评论...
验证码 换一张
取 消