0

I'm new to iOS development and I'm currently facing an issue I can't find the answer.

I'm implementing deeplink in our app using Branch.io. 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).

What I tried

The universal link is received by the method application:continueUserActivity:restorationHandler: in AppDelegate. 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. 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. The app-switcher would use that snapshot too, and also whenever the app come to foreground (wanted just in deeplink case).

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?

Fewl
  • 11
  • 1
  • 4
  • did u try this: https://stackoverflow.com/questions/24257920/hide-ui-after-resigning-application – Teja Nandamuri May 30 '17 at 15:03
  • Yeah I tried. But I didn't want to use that way because the app-switcher would also display the splash screen. I want to only show the splash screen in the moment the app slides in because of a deeplink. – Fewl May 30 '17 at 16:25

1 Answers1

0

In your applicationDidBecomeActive method use this code. 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];

  }
Rahul
  • 5,594
  • 7
  • 38
  • 92
  • Did not work the way I wanted because the app-switcher showed only the splash screen. I want to show the splash screen only when the app is resumed to foreground (in the slide in transition). But I don't know if that can be achieved. – Fewl May 30 '17 at 19:10
  • @Fewl please explain me your problem I think i am not getting it right. suppose I open your app and pressed home button now your app is in background. Now i double tapped home button and ap switcher came. 1. do you want here to show the splas or wanted to shoe default snampshot which iOS takes. 2. I selected your app from app switcher your app came. do you only want to show splash when I select your app from app switcher – Rahul May 30 '17 at 19:15
  • ok here it goes: in app-switcher I want to always show the default snapshot that iOS takes, and the splash I would like to show only when the the app is resumed from a deeplink (or if this is not possible at all I would be glad with showing it in any way it's resumed, but not in the app-switcher). – Fewl May 30 '17 at 19:26
  • Your first part: show only when came from deep link: Their is a method called openUrl it is fired when the app is launched from any custom url you can give it a try you can implement this method in appdelegate. and if it doesnt work then in my code where I am removing the image add your spalsh image and remove it after some desired delay. – Rahul May 30 '17 at 19:29
  • @Fewl Your first part: show only when came from deep link: Their is a method called openUrl it is fired when the app is launched from any custom url you can give it a try you can implement this method in appdelegate. and if it doesnt work then in my code where I am removing the image add your spalsh image and remove it after some desired delay. – Rahul May 30 '17 at 19:59
  • Ok I tried what you said. In both methods `application:continueUserActivity:restorationHandler:`, that is fired in case of universal links, and in `applicationDidBecomeActive:` iOS already presents that snapshot taken when the app went to background. So just adding the splash in those methods looks like when app is resumed `snapshot -> splash screen -> destination screen`. – Fewl May 30 '17 at 20:07