我正在添加隐私屏幕功能到混合科尔多瓦应用程序通过一个插件和跟随苹果提出的方法。
虽然在打开ASWebAuthenticationSession窗口时会导致意外的问题,但我使用它进行OAuth身份验证。发生的情况是,当系统对话出现在“您的应用程序想要使用xxx作为登录”的文本时,它会使应用程序失去焦点,而隐私屏幕出现在覆盖层后面。在我选择“是”之后,应用程序会重新获得焦点,删除隐私屏幕的代码也会触发,同样的代码也会关闭新打开的ASWebAuthenticationSession窗口。
PrivayScreenPlugin.m中的代码:
UIViewController *blankViewController;
@interface PrivacyScreenPlugin ()
@end
@implementation PrivacyScreenPlugin
- (void)pluginInitialize
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onAppDidBecomeActive:) name:UIApplicationDidBecomeActiveNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onPageDidLoad) name:CDVPageDidLoadNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onAppWillResignActive:) name:UIApplicationWillResignActiveNotification object:nil];
}
-(UIViewController *)createViewWithGradient {
UIViewController *viewController;
viewController = [UIViewController new];
viewController.modalPresentationStyle = UIModalPresentationOverFullScreen;
return viewController;
}
-(void) applyPrivacyScreen
{
if (blankViewController == NULL) {
blankViewController = [self createViewWithGradient];
}
blankViewController.view.window.hidden = NO;
[self.viewController.view.window.rootViewController presentViewController:blankViewController animated:NO completion:NULL];
}
#pragma mark - Explicit Commands
- (void) hidePrivacyScreen:(CDVInvokedUrlCommand*)command
{
[self removePrivacyScreen];
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}
- (void) showPrivacyScreen:(CDVInvokedUrlCommand*)command
{
[self applyPrivacyScreen];
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}
#pragma mark - Triggered functions
- (void) onPageDidLoad
{
[self removePrivacyScreen];
}
- (void)onAppDidBecomeActive:(UIApplication *)application
{
[self removePrivacyScreen];
}
- (void)onAppWillResignActive:(UIApplication *)application
{
[self applyPrivacyScreen];
}
#pragma mark - Helper functions
-(void) removePrivacyScreen
{
[self.viewController dismissViewControllerAnimated:NO completion:nil];
}
@end到目前为止,我发现这个问题与视图被取消的方式有关,即dismissViewControllerAnimated,它取消了模态窗口的堆栈:
[self.viewController dismissViewControllerAnimated:NO completion:nil];它能被帮助或工作吗?也许它可以被隐藏起来,而不是移除安全屏幕?还是有不同的方法来绘制覆盖,这是没有问题的?
我试着听UIApplicationDidEnterBackgroundNotification的节目,但这不是我想要的。我希望应用程序屏幕一旦被发送到应用程序列表(通过双击主页按钮或长滑动)就被覆盖了。
发布于 2019-10-10 10:05:35
为此,需要将隐私屏幕呈现在子视图中,而不是模式视图中。它允许隐藏/显示隐私屏幕视图,而不是添加/删除它:
-(void) removePrivacyScreen
{
blankViewController.view.hidden=YES;
}
-(void) applyPrivacyScreen
{
if (blankViewController == NULL) {
blankViewController = [self createViewWithGradient];
}
blankViewController.view.hidden = NO;
[self.viewController.view.window addSubview:blankViewController.view];
}https://stackoverflow.com/questions/57373872
复制相似问题