0

phonegap 응용 프로그램에서 UIDocumentInteractionController를 사용하여 장치에서 파일을로드하려고합니다. 나는 따라 다녔다.UIDocumentInteraction의 <QLRemotePreviewContentController : 0x7d19a000>에 대한 모양 전환의 시작/종료 균형이 불균형

CDVViewController* mainController = (CDVViewController*)[ super viewController ]; 
     UIDocumentInteractionController *documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:fileLocation]]; 
     FileViewer *vController = [[FileViewer alloc]init]; 
     [mainController addChildViewController:vController]; 
     documentInteractionController.delegate = vController; 
     [documentInteractionController presentPreviewAnimated:YES]; 

오류 메시지 제공함으로써이 결과 : "분리 된 뷰 컨트롤러에 뷰 컨트롤러를 제시는 권장하지 않습니다

#import <Foundation/Foundation.h> 
#import <QuickLook/QuickLook.h> 

@interface FileViewer : UIViewController <UIDocumentInteractionControllerDelegate> 

@end 

@implementation FileViewer 

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 
{ 
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 
    if (self) { 
     // Custom initialization 
    } 
    return self; 
} 

- (UIViewController *) documentInteractionControllerViewControllerForPreview:(UIDocumentInteractionController *)controller { 
    return self; 
} 

- (void)viewDidLoad 
{ 
    [self viewDidLoad]; 
    // Do any additional setup after loading the view. 
} 

- (void)didReceiveMemoryWarning 
{ 
    [super didReceiveMemoryWarning]; 
    // Dispose of any resources that can be recreated. 
} 

@end은

Launcher.mi에서

이 파일을 표시하려면 다음을 수행했다 QLRemotePreviewContentController에 대한 시작/종료 모양 전환의 불균형 호출 "

미리 감사드립니다 !!

답변

0

다음과 같은 방법으로 문제를 해결했습니다. 최선의 방법이 아닐 수도 있으므로 최선의 방법을 제안하십시오.

@interface Launcher : CDVPlugin<UIDocumentInteractionControllerDelegate> 
@property (strong, nonatomic)UIViewController *navigatorController; 
@property (strong, nonatomic)Launcher *launcher; 
@property (strong, nonatomic)NSString *callbackId; 
-(void)openFile:(CDVInvokedUrlCommand*)command; 

@end 

#import "Launcher.h" 
#import "FileViewer.h" 
#import<QuickLook/QuickLook.h> 
#import <MobileCoreServices/MobileCoreServices.h> 

@implementation Launcher 

-(void)openFile:(CDVInvokedUrlCommand*)command{ 
    CDVPluginResult *pluginResult = nil; 
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
    NSString *documentsDirectory = [paths objectAtIndex:0]; 
    NSDictionary *params = [command.arguments objectAtIndex:0]; 
    NSString *file = [params objectForKey:@"message"]; 
    NSString *fileLocation = [documentsDirectory stringByAppendingFormat:@"/%@",file]; 

    if (![fileLocation isEqual:[NSNull null]]) { 
     @try { 
      self.launcher = self; 
      CDVViewController *viewController = [CDVViewController new]; 
      viewController.wwwFolderName = @"www"; 
      viewController.startPage = @"main.html"; // page contains listview showing name of files 
      self.navigatorController = viewController; 
      UIDocumentInteractionController *documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:fileLocation]]; 
      [[UIApplication sharedApplication].keyWindow setRootViewController:self.navigatorController]; 
      documentInteractionController.delegate = self; 
      [documentInteractionController presentPreviewAnimated:YES];  
     } 
     @catch (NSException *exception) { 
      NSLog(@"dd : %@",[exception reason]); 
     } 

    } 
    pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK]; 
    [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; 
} 
- (UIViewController *)documentInteractionControllerViewControllerForPreview: (UIDocumentInteractionController *)controller 
{ 
    return self.navigatorController; 
} 

- (void)documentInteractionControllerDidEndPreview:(UIDocumentInteractionController *)controller 
{ 
    [[UIApplication sharedApplication].keyWindow setRootViewController:self.navigatorController]; 
    self.launcher = nil; 
}