From 66628168e8492c8e3bacce74e2407856d2d7e936 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96nder=20Ceylan?= Date: Tue, 18 Oct 2016 11:05:09 +0200 Subject: [PATCH 1/4] Fixed broken view after orientation switch --- src/ios/DocumentHandler.h | 4 ++++ src/ios/DocumentHandler.m | 29 +++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) 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..dd71132 100644 --- a/src/ios/DocumentHandler.m +++ b/src/ios/DocumentHandler.m @@ -3,8 +3,20 @@ @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]]; + __weak DocumentHandler* weakSelf = self; dispatch_queue_t asyncQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); @@ -49,6 +61,23 @@ - (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]; + } + + [[UIDevice currentDevice] setValue:orientation forKey:@"orientation"]; +} + - (id ) previewController: (QLPreviewController *) controller previewItemAtIndex: (NSInteger) index { return self; From 1cf8a8fa0233c4043eaac413f3b9b1a7419df4b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96nder=20Ceylan?= Date: Wed, 19 Oct 2016 09:32:01 +0200 Subject: [PATCH 2/4] Fixed 360 rotate issue for landscape views --- src/ios/DocumentHandler.m | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/ios/DocumentHandler.m b/src/ios/DocumentHandler.m index dd71132..f2f53a3 100644 --- a/src/ios/DocumentHandler.m +++ b/src/ios/DocumentHandler.m @@ -16,6 +16,8 @@ - (void)HandleDocumentWithURL:(CDVInvokedUrlCommand*)command; { orientation = [NSNumber numberWithInt:[[UIDevice currentDevice] orientation]]; + NSLog(@"setting orientation to"); + NSLog(@"%@", orientation); __weak DocumentHandler* weakSelf = self; @@ -62,7 +64,6 @@ - (NSInteger) numberOfPreviewItemsInPreviewController: (QLPreviewController *) c } - (void)previewControllerWillDismiss:(QLPreviewController *)controller { - if (orientation.intValue == 3) { orientation = [NSNumber numberWithInt:4]; } else if (orientation.intValue == 4) { @@ -75,7 +76,11 @@ - (void)previewControllerWillDismiss:(QLPreviewController *)controller { orientation = [NSNumber numberWithInt:3]; } - [[UIDevice currentDevice] setValue:orientation forKey:@"orientation"]; + NSNumber *currentOrientation = [NSNumber numberWithInt:[[UIDevice currentDevice] orientation]]; + + if (currentOrientation.intValue == 1 || currentOrientation.intValue == 2) { + [[UIDevice currentDevice] setValue:orientation forKey:@"orientation"]; + } } - (id ) previewController: (QLPreviewController *) controller previewItemAtIndex: (NSInteger) index From 9ce7776171cab3f0abca5469480bdd71e585f398 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96nder=20Ceylan?= Date: Wed, 21 Jun 2017 09:55:30 +0200 Subject: [PATCH 3/4] Create package.json --- package.json | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 package.json 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" +} From 83e7ffc5bd4aa46a28903ab7a87b402f3bf9536b Mon Sep 17 00:00:00 2001 From: Andrew Date: Mon, 25 Sep 2017 12:43:07 +0200 Subject: [PATCH 4/4] iOS: add event documentHandlerOnDismiss firing --- README.md | 12 ++++++++++++ src/ios/DocumentHandler.m | 6 ++++++ 2 files changed, 18 insertions(+) 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/src/ios/DocumentHandler.m b/src/ios/DocumentHandler.m index f2f53a3..a306de0 100644 --- a/src/ios/DocumentHandler.m +++ b/src/ios/DocumentHandler.m @@ -83,6 +83,12 @@ - (void)previewControllerWillDismiss:(QLPreviewController *)controller { } } +- (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;