我正在生成一個PDF文件,並試圖預覽它,如下所示,但URL通常返回NIL,儘管我的格式(這似乎解決了這個常見問題的其他人的問題)。我一定會錯過更多的東西。有任何想法嗎?NSURL總是爲零編碼
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];
}