简体   繁体   English

在应用程序从通用链接进入前景之前,iOS会显示启动屏幕

[英]iOS show splash screen before app enter foreground from universal link

I'm new to iOS development and I'm currently facing an issue I can't find the answer. 我是iOS开发的新手,目前遇到无法找到答案的问题。

I'm implementing deeplink in our app using Branch.io. 我正在使用Branch.io在我们的应用程序中实现Deeplink。 Everything works fine except one thing I'm trying to achieve. 一切正常,除了我要实现的一件事。 When the app is resumed to foreground it shows briefly the last screen it was before going to background (through some research I believe the iOS takes a snapshot of the app screen right before entering background). 当应用恢复到前台时,它会短暂显示进入背景之前的最后一个屏幕(通过一些研究,我相信iOS会在进入背景之前对应用屏幕进行快照)。

What I tried 我尝试了什么

The universal link is received by the method application:continueUserActivity:restorationHandler: in AppDelegate. 通用链接由AppDelegate中的application:continueUserActivity:restorationHandler:方法接收。 So there I added the splash screen, but when that method is called the last screen was already visible. 因此,我添加了初始屏幕,但是当调用该方法时,最后一个屏幕已经可见。 So the transition was like last screen -> splash screen -> destination screen . 所以过渡就像last screen -> splash screen -> destination screen Not the desired solution. 不是理想的解决方案。

Then I tried, in the method applicationDidEnterBackground: also in AppDelegate, to add the splash screen to the window so the snapshot would be that and it worked, but not the way a really wanted. 然后,我尝试在AppDelegate中的applicationDidEnterBackground:方法中,将初始屏幕添加到窗口中,以便快照即能正常运行,但不是真正想要的方式。 The app-switcher would use that snapshot too, and also whenever the app come to foreground (wanted just in deeplink case). 应用程序切换器也将使用该快照,并且每当应用程序出现在前台时(仅在Deeplink情况下才需要)。

The great question 伟大的问题

Can I, somehow, show the splash screen when the app come to foreground (and not using the snapshot method) through deeplink call only or is it not possible? 当应用程序仅通过Deeplink调用进入前台(而不使用快照方法)时,是否可以以某种方式显示启动屏幕?

In your applicationDidBecomeActive method use this code. 在您的applicationDidBecomeActive方法中使用此代码。 You can use any Image you want to show. 您可以使用任何要显示的图像。 I am using background color to show the change. 我正在使用背景色来显示更改。

- (void)applicationWillResignActive:(UIApplication *)application {

UIImageView *imgView = [[UIImageView alloc] init];
imgView.frame = [UIApplication sharedApplication].keyWindow.frame;
imgView.backgroundColor = [UIColor redColor];
[[UIApplication sharedApplication].keyWindow addSubview:imgView];

}

And to remove the Image: 并删除图像:

   - (void)applicationDidBecomeActive:(UIApplication *)application {

for(UIView *view in [UIApplication sharedApplication].keyWindow.subviews)
    if([view isKindOfClass:[UIImageView class]])
        [view removeFromSuperview];

  }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM