You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by to...@apache.org on 2016/05/23 13:42:18 UTC

[20/50] cordova-plugin-screen-orientation git commit: background thread for ios

background thread for ios


Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-screen-orientation/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-screen-orientation/commit/f3d451c7
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-screen-orientation/tree/f3d451c7
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-screen-orientation/diff/f3d451c7

Branch: refs/heads/master
Commit: f3d451c72cd56cb471ad6db5641ea59eca6fcd03
Parents: 4c86a0d
Author: orlando-antonino <or...@gmail.com>
Authored: Thu May 14 10:57:52 2015 +0200
Committer: orlando-antonino <or...@gmail.com>
Committed: Thu May 14 10:57:52 2015 +0200

----------------------------------------------------------------------
 src/ios/YoikScreenOrientation.m | 114 ++++++++++++++++++-----------------
 1 file changed, 60 insertions(+), 54 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-screen-orientation/blob/f3d451c7/src/ios/YoikScreenOrientation.m
----------------------------------------------------------------------
diff --git a/src/ios/YoikScreenOrientation.m b/src/ios/YoikScreenOrientation.m
index 4dd77c3..06d1316 100644
--- a/src/ios/YoikScreenOrientation.m
+++ b/src/ios/YoikScreenOrientation.m
@@ -27,61 +27,67 @@ SOFTWARE.
 
 -(void)screenOrientation:(CDVInvokedUrlCommand *)command
 {
-    NSArray* arguments = command.arguments;
-    NSString* orientationIn = [arguments objectAtIndex:1];
-
-    // grab the device orientation so we can pass it back to the js side.
-    NSString *orientation;
-    switch ([[UIDevice currentDevice] orientation]) {
-        case UIDeviceOrientationLandscapeLeft:
-            orientation = @"landscape-secondary";
-            break;
-        case UIDeviceOrientationLandscapeRight:
-            orientation = @"landscape-primary";
-            break;
-        case UIDeviceOrientationPortrait:
-            orientation = @"portrait-primary";
-            break;
-        case UIDeviceOrientationPortraitUpsideDown:
-            orientation = @"portrait-secondary";
-            break;
-        default:
-            orientation = @"portait";
-            break;
-    }
-
-    if ([orientationIn isEqual: @"unlocked"]) {
-        orientationIn = orientation;
-    }
-
-    // we send the result prior to the view controller presentation so that the JS side
-    // is ready for the unlock call.
-    CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK
-        messageAsDictionary:@{@"device":orientation}];
-    [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
-
-    // SEE https://github.com/Adlotto/cordova-plugin-recheck-screen-orientation
-    // HACK: Force rotate by changing the view hierarchy. Present modal view then dismiss it immediately
-    // This has been changed substantially since iOS8 broke it...
-    ForcedViewController *vc = [[ForcedViewController alloc] init];
-    vc.calledWith = orientationIn;
-
-    // backgound should be transparent as it is briefly visible
-    // prior to closing.
-    vc.view.backgroundColor = [UIColor clearColor];
-    // vc.view.alpha = 0.0;
-    vc.view.opaque = YES;
-
-#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 80000
-    // This stops us getting the black application background flash, iOS8
-    vc.modalPresentationStyle = UIModalPresentationOverFullScreen;
-#endif
-
-    [self.viewController presentViewController:vc animated:NO completion:^{
-        // added to support iOS8 beta 5, @see issue #19
-        dispatch_after(0, dispatch_get_main_queue(), ^{
-            [self.viewController dismissViewControllerAnimated:NO completion:nil];
+    [self.commandDelegate runInBackground:^{
+
+        NSArray* arguments = command.arguments;
+        NSString* orientationIn = [arguments objectAtIndex:1];
+
+        // grab the device orientation so we can pass it back to the js side.
+        NSString *orientation;
+        switch ([[UIDevice currentDevice] orientation]) {
+            case UIDeviceOrientationLandscapeLeft:
+                orientation = @"landscape-secondary";
+                break;
+            case UIDeviceOrientationLandscapeRight:
+                orientation = @"landscape-primary";
+                break;
+            case UIDeviceOrientationPortrait:
+                orientation = @"portrait-primary";
+                break;
+            case UIDeviceOrientationPortraitUpsideDown:
+                orientation = @"portrait-secondary";
+                break;
+            default:
+                orientation = @"portait";
+                break;
+        }
+
+        if ([orientationIn isEqual: @"unlocked"]) {
+            orientationIn = orientation;
+        }
+
+        // we send the result prior to the view controller presentation so that the JS side
+        // is ready for the unlock call.
+        CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK
+            messageAsDictionary:@{@"device":orientation}];
+        [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
+
+        // SEE https://github.com/Adlotto/cordova-plugin-recheck-screen-orientation
+        // HACK: Force rotate by changing the view hierarchy. Present modal view then dismiss it immediately
+        // This has been changed substantially since iOS8 broke it...
+        ForcedViewController *vc = [[ForcedViewController alloc] init];
+        vc.calledWith = orientationIn;
+
+        // backgound should be transparent as it is briefly visible
+        // prior to closing.
+        vc.view.backgroundColor = [UIColor clearColor];
+        // vc.view.alpha = 0.0;
+        vc.view.opaque = YES;
+        
+    #if __IPHONE_OS_VERSION_MAX_ALLOWED >= 80000
+        // This stops us getting the black application background flash, iOS8
+        vc.modalPresentationStyle = UIModalPresentationOverFullScreen;
+    #endif
+    
+        dispatch_async(dispatch_get_main_queue(), ^{
+            [self.viewController presentViewController:vc animated:NO completion:^{
+                // added to support iOS8 beta 5, @see issue #19
+                dispatch_after(0, dispatch_get_main_queue(), ^{
+                    [self.viewController dismissViewControllerAnimated:NO completion:nil];
+                });
+            }];
         });
+
     }];
 }
 


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org