mirror of
https://github.com/apache/cordova-plugin-screen-orientation.git
synced 2025-05-04 17:32:12 +08:00
background thread for ios
This commit is contained in:
parent
4c86a0d8c6
commit
f3d451c72c
@ -27,61 +27,67 @@ SOFTWARE.
|
||||
|
||||
-(void)screenOrientation:(CDVInvokedUrlCommand *)command
|
||||
{
|
||||
NSArray* arguments = command.arguments;
|
||||
NSString* orientationIn = [arguments objectAtIndex:1];
|
||||
[self.commandDelegate runInBackground:^{
|
||||
|
||||
// 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;
|
||||
}
|
||||
NSArray* arguments = command.arguments;
|
||||
NSString* orientationIn = [arguments objectAtIndex:1];
|
||||
|
||||
if ([orientationIn isEqual: @"unlocked"]) {
|
||||
orientationIn = orientation;
|
||||
}
|
||||
// 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;
|
||||
}
|
||||
|
||||
// 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];
|
||||
if ([orientationIn isEqual: @"unlocked"]) {
|
||||
orientationIn = orientation;
|
||||
}
|
||||
|
||||
// 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;
|
||||
// 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];
|
||||
|
||||
// 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;
|
||||
// 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;
|
||||
|
||||
#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];
|
||||
// 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];
|
||||
});
|
||||
}];
|
||||
});
|
||||
|
||||
}];
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user