0

私は PDF ファイルを生成しており、以下に示すようにプレビューしようとしていますが、フォーマットにもかかわらず、URL は定期的に NIL を返します (これは、この一般的な問題に関する他のすべての問題を解決するようです)。もっと何かが欠けているに違いない。何か案は?

    NSArray *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);    
NSString *docDirectory = [path objectAtIndex:0];

    docDirectory = [docDirectory stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

    NSURL *URL = [[NSBundle mainBundle] URLForResource:docDirectory withExtension:@"pdf"];
if (URL) {
    // Initialize Document Interaction Controller
    self->documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL:URL];
    // Configure Document Interaction Controller
    [self->documentInteractionController setDelegate:self];
    // Preview PDF
    [self->documentInteractionController presentPreviewAnimated:YES];
}
4

2 に答える 2

1

あなたのパスの作成は、まったくうまくいかないようです。次のようなことを試してください:

NSArray *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);    
NSString *docDirectory = [path objectAtIndex:0];
NSString *filename = @"myfile.pdf"; // replace with the actual filename you used
NSString *fullPath = [docDirectory stringByAppendingPathComponent:filename];
NSURL *fullURL = [NSURL fileURLWithPath:fullPath];

投稿したコードでは、ファイル名を指定していません。Documents ディレクトリと pdf 拡張子があります。この場合、URL を「パーセント エスケープ」する必要はありません。

于 2013-04-16T17:51:22.590 に答える
0

おそらく、ファイルへのパスを取得する方法について混乱しているでしょう: NSSearchPathForDirectoriesInDomains(たとえば) ドキュメント ディレクトリへの絶対パスを取得するために使用されます。一方、 はアプリ ラッパーを検索して、指定された名前のファイルを探しますNSBundleURLForResource:withExtension:

2つを混ぜても何の役にも立ちません。おそらくドキュメントディレクトリを調べてください。

于 2013-04-16T17:51:13.493 に答える