diff --git a/README.md b/README.md index a2b723e..bfd3eef 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,10 @@ There is a special failure condition on Android, if the system doesn't have any The plugin downloads the document and provides a preview of the document using the Quick Look framework, including the corresponding actions such as copy, print, etc. +## Events (only iOS) + +* documentHandlerOnDismiss - it fires after QuickLook window is closed + ## Example usage handleDocumentWithURL( @@ -38,3 +42,11 @@ including the corresponding actions such as copy, print, etc. }, 'http://www.example.com/path/to/document.pdf' ); + + document.addEventListener( + 'documentHandlerOnDismiss', + function() { + console.log('document handler was closed'); + }, + false, + ); diff --git a/package.json b/package.json new file mode 100644 index 0000000..ff44b1a --- /dev/null +++ b/package.json @@ -0,0 +1,29 @@ +{ + "version": "0.2.2", + "name": "ch.ti8m.documenthandler", + "cordova_name": "DocumentHandler", + "description": "A phonegap plugin to handle documents (f.e. PDFs) given by URL.", + "license": "Apache 2.0", + "keywords": [ + "cordova", + "Documents", + "PDF" + ], + "engines": [], + "cordova": { + "id": "ch.ti8m.documenthandler", + "platforms": [ + "ios", + "android" + ] + }, + "repository": { + "type": "git", + "url": "git+https://github.com/onderceylan/DocumentHandler.git" + }, + "author": "Document Handler", + "bugs": { + "url": "https://github.com/onderceylan/DocumentHandler/issues" + }, + "homepage": "https://github.com/onderceylan/DocumentHandler#readme" +} diff --git a/src/ios/DocumentHandler.h b/src/ios/DocumentHandler.h index 79a1690..011f889 100644 --- a/src/ios/DocumentHandler.h +++ b/src/ios/DocumentHandler.h @@ -5,9 +5,13 @@ #import #import + @interface DocumentHandler : CDVPlugin @property (strong, nonatomic) NSURL* fileUrl; @property (readonly) NSURL* previewItemURL; ++ (NSNumber *)orientation; ++ (void) setOrientation:(NSNumber*)val; + @end \ No newline at end of file diff --git a/src/ios/DocumentHandler.m b/src/ios/DocumentHandler.m index 1bcb9bc..a306de0 100644 --- a/src/ios/DocumentHandler.m +++ b/src/ios/DocumentHandler.m @@ -3,8 +3,22 @@ @implementation DocumentHandler +static NSNumber *orientation = nil; + ++ (NSNumber*) orientation { + @synchronized(self) { return orientation; } +} ++ (void) setOrientation:(NSNumber*)val { + @synchronized(self) { orientation = val; } +} + - (void)HandleDocumentWithURL:(CDVInvokedUrlCommand*)command; { + + orientation = [NSNumber numberWithInt:[[UIDevice currentDevice] orientation]]; + NSLog(@"setting orientation to"); + NSLog(@"%@", orientation); + __weak DocumentHandler* weakSelf = self; dispatch_queue_t asyncQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); @@ -49,6 +63,32 @@ - (NSInteger) numberOfPreviewItemsInPreviewController: (QLPreviewController *) c return 1; } +- (void)previewControllerWillDismiss:(QLPreviewController *)controller { + if (orientation.intValue == 3) { + orientation = [NSNumber numberWithInt:4]; + } else if (orientation.intValue == 4) { + orientation = [NSNumber numberWithInt:4]; + } else if (orientation.intValue == 5) { + orientation = [NSNumber numberWithInt:4]; + } else if (orientation.intValue == 6) { + orientation = [NSNumber numberWithInt:3]; + } else { + orientation = [NSNumber numberWithInt:3]; + } + + NSNumber *currentOrientation = [NSNumber numberWithInt:[[UIDevice currentDevice] orientation]]; + + if (currentOrientation.intValue == 1 || currentOrientation.intValue == 2) { + [[UIDevice currentDevice] setValue:orientation forKey:@"orientation"]; + } +} + +- (void)previewControllerDidDismiss:(QLPreviewController *)controller { + NSLog(@"handler dismiss"); + NSString *pluginReadyJSCallbackCommand = [NSString stringWithFormat:@"cordova.fireDocumentEvent('documentHandlerOnDismiss');"]; + [self.commandDelegate evalJs:pluginReadyJSCallbackCommand]; +} + - (id ) previewController: (QLPreviewController *) controller previewItemAtIndex: (NSInteger) index { return self;