2011-11-03 3 views
2

이메일 첨부 파일을 저장할 수있는 iPhone 앱을 만들고 있습니다. 응용 프로그램 내부에서 파일을 볼 수 있기를 원합니다. 최대한 많은 종류의 파일 (.txt, .pdf, .png, .jpeg, .doc, .xls 등)을 볼 수 있어야합니다.iPhone 앱에서 파일을 보는 방법은 무엇입니까?

파일은 내 응용 프로그램의 문서 폴더 내에 있습니다. . 이것에 가장 적합한 솔루션은 무엇입니까? 내 첫 번째 생각은 내 파일 경로를 URL로 변환하고 UIWebView에서로드하는 것이지만 이것이 최선의 방법인지 또는 모든 파일 형식을 처리할지 여부는 확실하지 않습니다. 이견있는 사람?

답변

2

Apple 고유의 Mail 앱이하는 일은 QuickLook 프레임 워크를 사용하는 것입니다. 너도 똑같이하는 것이 좋을거야. QLPreviewController는 당신에게 힘든 일을합니다. UIDocumentInteractionController를 사용할 수도 있습니다. 이것은 여전히 ​​미리보기를 생성하기 위해 장면 뒤에서 QuickLook을 사용하고 있습니다.

+0

감사합니다. 나는이 기회를 주었지만 컨트롤러가 시작될 때 아무 것도 안보이 경고를 받았다 : "경고 : /Developer/Platforms/iPhoneOS.platform/DeviceSupport/5.0 (9A334)/Symbols/System/Library에 대한 기호를 읽을 수 없다. /Frameworks/QuickLook.framework/DisplayBundles/Image.qldisplay/Image (파일을 찾을 수 없습니다.) 경고 : 원격 장치의 메모리에서 읽는 Image.qldisplay/Image의 복사본이 없습니다. 디버그 세션 속도가 느려질 수 있습니다. " 어떤 제안? – user1007895

+0

@user : https://github.com/mattneub/Programming-iOS-4-Book-Examples/tree/master/p736p754fileHandoff에서의 작업 예제 – matt

+0

@matt 링크가 이동 했으므로 이제 올바른 링크 : [https ://github.com/mattneub/Programming-iOS-Book-Examples](https://github.com/mattneub/Programming-iOS-Book-Examples). – zaph

2

UIWebView는 이러한 종류의 파일을 표시하는 가장 좋은 방법입니다.

또는이 코드와 함께 다른 응용 프로그램에서 문서를 읽으려고 시도 할 수 있습니다 제안에 대한

 UIDocumentInteractionController *interactionController = [[UIDocumentInteractionController interactionControllerWithURL:document.documentURL] retain]; 
     interactionController.delegate = self; 
     BOOL canOpenDocument = [interactionController presentOpenInMenuFromRect:CGRectMake(365, 200, 300, 400) inView:self.view animated:YES]; 

     if(!canOpenDocument) { 
      UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"" message:@"Your phone can't read this kind of file, please install an app from appstore for that" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil]; 
      [alert show]; 
      [alert release]; 
     } 
+0

그가 원하는 것은 미리보기를 보여주는 것입니다. QuickLook이 이미 문서를 표시하는 방법을 알고 있다면 문서를 다른 응용 프로그램에 넘겨주는 것은 어리석은 일입니다. UIDocumentInteractionController를 사용하여 문서를 다른 응용 프로그램으로 전달하는 대신 UIDocumentInteractionController를 사용하여 자신이있는 위치에 머무르고 미리보기를 표시해야합니다! 사실 QLPreviewController를 사용하는 것과 같습니다. – matt

관련 문제