【问题标题】:How to read pdf file from document directory with timestamp in iPhone?如何从 iPhone 中带有时间戳的文档目录中读取 pdf 文件?
【发布时间】:2013-11-04 11:21:30
【问题描述】:

我遇到了一个问题,我的 pdf 文件太多,所以我一个一个地下载 pdf 文件,

所以我把时间戳放在我的文件夹中,所以我的路径看起来像这样:

/Users/zee/Library/Application Support/iPhone Simulator/6.0/Applications/10EF6B94-0ECD-484A-

AF5A-D300D8EF55DB/Documents/myPDF.pdf1382698338.78128

但我不明白为什么它没有在带有时间戳的 UIWebView 中打开,我下面的代码是

当我不放时间戳时工作。

那么我该如何打开我的 pdf 文件,下面附上时间戳是我的代码

帮我解决这个问题

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,

 NSUserDomainMask, YES);

    NSString *documentsDirectory = [paths objectAtIndex:0];

    NSString *filePath = [documentsDirectory stringByAppendingPathComponent:@"myPDF.pdf"];

    NSURL *targetURL = [NSURL fileURLWithPath:filePath];

    NSURLRequest *request = [NSURLRequest requestWithURL:targetURL];

    [self.webView loadRequest:request];

我的文件路径是:

/Users/zee/Library/Application Support/iPhone Simulator/6.0/Applications/10EF6B94-0ECD-484A-

AF5A-D300D8EF55DB/Documents/myPDF.pdf1382698338.78128

请告诉我如何打开我的 pdf 文件

【问题讨论】:

    标签: ios pdf uiwebview nsdocumentdirectory


    【解决方案1】:

    所以我把时间戳放在我的文件夹中,所以我的路径看起来像这样:

                  /Users/zee/Library/Application Support/iPhone Simulator/6.0/Applications/10EF6B94-0ECD-484A-AF5A-D300D8EF55DB/Documents/myPDF.pdf1382698338.78128
    

    您应该尝试使用不同的方案来命名您的文件,以便扩展名保持不变,即:

      ..../myPDF<TIMESTAMP>.pdf
    

    例如

      ..../myPDF1382698338.78128.pdf
    

    【讨论】:

    • 我现在已经这样做了,我的路径是这样的 ..../myPDF1382698338.78128.pdf 那么我现在应该放什么? NSString *filePath = [documentsDirectory stringByAppendingPathComponent:@"myPDF.pdf"];
    • 你应该使用:NSString *filePath = [documentsDirectory stringByAppendingPathComponent:@"myPDF1382698338.78128.pdf"];
    • 你能看看我的另一个问题,这里是链接:“stackoverflow.com/questions/19611517/…
    • sergio 请让我知道我该怎么做,我会非常感谢你的帮助
    猜你喜欢
    • 2012-09-24
    • 1970-01-01
    • 1970-01-01
    • 2011-10-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多