QLRemotePreviewContentController

QLRemotePreviewContentController

本文介绍了< QLRemotePreviewContentController:0x7d19a000>的开始/结束外观转换的不平衡调用in UIDocumentInteraction的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在通过在phonegap应用程序中使用UIDocumentInteractionController在设备中加载文件。我已经完成了以下操作。

I am trying to load files in device by using UIDocumentInteractionController in a phonegap app. I have done by following.

#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中通过以下方式显示文件:

In Launcher.m i have done by following to show files:

    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];

通过给出错误消息的结果:
不建议在分离的视图控制器上呈现视图控制器。
QLRemotePreviewContentController的开始/结束外观转换的不平衡调用

This result by giving error message:"Presenting view controllers on detached view controllers is discouraged.Unbalanced calls to begin/end appearance transitions for QLRemotePreviewContentController"

提前感谢!

推荐答案

我已通过以下方式解决了我的问题。这可能不是最好的方式,所以请建议最好的方式。

I have solved my issue by following way. It might not be the best way, so please suggest the best way also.

@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;
}

这篇关于&lt; QLRemotePreviewContentController:0x7d19a000&gt;的开始/结束外观转换的不平衡调用in UIDocumentInteraction的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-13 22:14