2015-09-10 25 views
0
我有UIDocumentInteractionController問題

文件擴展名,這裏是我的代碼:Objective-C的UIDocumentInteractionController無法發出路徑

NSURL *URL = [NSURL fileURLWithPath:@"http://www.domain.com/pdf/35.pdf"]; 

     //NSURL *URL = [[NSBundle mainBundle] URLForResource:@"35" 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]; 
     } 

我的控制檯日誌中這樣說:

無法發出文件擴展路徑:/http:/www.domain.com/pdf/35.pdf

,並在我的應用程序會顯示一個灰色的背景,並說35.pdf可移植文檔格式(PDF)

我做錯了什麼?

回答

1

http URL不是文件URL。

此:

NSURL *URL = [NSURL fileURLWithPath:@"http://www.domain.com/pdf/35.pdf"]; 

需求是:

NSURL *URL = [NSURL URLWithString:@"http://www.domain.com/pdf/35.pdf"]; 

但請注意,UIDocumentInteractionController需要一個URL到本地的資源,而不是一個互聯網網址。所以你根本不能使用上面的URL。

您需要首先在本地下載並保存PDF文件,然後爲本地文件創建適當的文件URL。