我已将https://github.com/vfr/Reader PDF 阅读器添加到 ChildBrowser。效果超级棒!
当前组件版本:Cordova 2.2.0 的子浏览器
编辑 ChildBrowserCommand.h:
#import <Cordova/CDVPlugin.h>
#import "ChildBrowserViewController.h"
#import "ReaderDemoController.h"
#import "ReaderViewController.h"
@interface ChildBrowserCommand : CDVPlugin <ChildBrowserDelegate, ReaderViewControllerDelegate>{}
@property (nonatomic, strong) ChildBrowserViewController* childBrowser;
@property (nonatomic, strong) ReaderDemoController* reader;
- (void)showWebPage:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options;
- (void)onChildLocationChange:(NSString*)newLoc;
@end
在 .M 文件中 1)@synthesize reader;
2)
- (void)showWebPage:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options
{
NSString* url = (NSString*)[arguments objectAtIndex:0];
if([url hasSuffix:@".pdf"])
{
NSString *phrase = nil; // Document password (for unlocking most encrypted PDF files)
ReaderDocument *document = [ReaderDocument withDocumentFilePath:url password:phrase];
ReaderViewController *readerViewController = [[ReaderViewController alloc] initWithReaderDocument:document];'
readerViewController.delegate = self; // Set the ReaderViewController delegate to self
readerViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
readerViewController.modalPresentationStyle = UIModalPresentationFullScreen;
[self.viewController presentModalViewController:readerViewController animated:YES];
}
else
{
if (self.childBrowser == nil) {
#if __has_feature(objc_arc)
self.childBrowser = [[ChildBrowserViewController alloc] initWithScale:NO];
NSLog(@"HAS ARC");
#else
self.childBrowser = [[[ChildBrowserViewController alloc] initWithScale:NO] autorelease];
NSLog(@"NO ARC");
#endif
self.childBrowser.delegate = self;
self.childBrowser.orientationDelegate = self.viewController;
}
[self.viewController presentModalViewController:childBrowser animated:YES];
[self.childBrowser loadURL:url];
}
}
3)
-(void)dismissReaderViewController:(ReaderViewController *)viewController{
NSLog(@"The delegate to dismiss pdf reader was called");
[self.viewController dismissModalViewControllerAnimated:YES];}
4) 将阅读器中的所有内容复制到我们的项目中,添加所需的所有框架
享受。不要忘记打开阅读器的 ARC