background thread for ios

This commit is contained in:
orlando-antonino 2015-05-14 10:57:52 +02:00
parent 4c86a0d8c6
commit f3d451c72c

View File

@ -27,61 +27,67 @@ SOFTWARE.
-(void)screenOrientation:(CDVInvokedUrlCommand *)command -(void)screenOrientation:(CDVInvokedUrlCommand *)command
{ {
NSArray* arguments = command.arguments; [self.commandDelegate runInBackground:^{
NSString* orientationIn = [arguments objectAtIndex:1];
// grab the device orientation so we can pass it back to the js side. NSArray* arguments = command.arguments;
NSString *orientation; NSString* orientationIn = [arguments objectAtIndex:1];
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"]) { // grab the device orientation so we can pass it back to the js side.
orientationIn = orientation; 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;
}
// we send the result prior to the view controller presentation so that the JS side if ([orientationIn isEqual: @"unlocked"]) {
// is ready for the unlock call. orientationIn = orientation;
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 // we send the result prior to the view controller presentation so that the JS side
// HACK: Force rotate by changing the view hierarchy. Present modal view then dismiss it immediately // is ready for the unlock call.
// This has been changed substantially since iOS8 broke it... CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK
ForcedViewController *vc = [[ForcedViewController alloc] init]; messageAsDictionary:@{@"device":orientation}];
vc.calledWith = orientationIn; [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
// backgound should be transparent as it is briefly visible // SEE https://github.com/Adlotto/cordova-plugin-recheck-screen-orientation
// prior to closing. // HACK: Force rotate by changing the view hierarchy. Present modal view then dismiss it immediately
vc.view.backgroundColor = [UIColor clearColor]; // This has been changed substantially since iOS8 broke it...
// vc.view.alpha = 0.0; ForcedViewController *vc = [[ForcedViewController alloc] init];
vc.view.opaque = YES; vc.calledWith = orientationIn;
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 80000 // backgound should be transparent as it is briefly visible
// This stops us getting the black application background flash, iOS8 // prior to closing.
vc.modalPresentationStyle = UIModalPresentationOverFullScreen; vc.view.backgroundColor = [UIColor clearColor];
#endif // vc.view.alpha = 0.0;
vc.view.opaque = YES;
[self.viewController presentViewController:vc animated:NO completion:^{ #if __IPHONE_OS_VERSION_MAX_ALLOWED >= 80000
// added to support iOS8 beta 5, @see issue #19 // This stops us getting the black application background flash, iOS8
dispatch_after(0, dispatch_get_main_queue(), ^{ vc.modalPresentationStyle = UIModalPresentationOverFullScreen;
[self.viewController dismissViewControllerAnimated:NO completion:nil]; #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];
});
}];
}); });
}]; }];
} }