问题
In iOS there is an LaunchScreen before you're app is ready. Can you add things to do (Code) to this?
I want to execute a JSON request on LaunchScreen but have no idea where to put the code.
Thanks In Advance, Kaaseter
回答1:
As you wrote, LaunchScreen is there before your app is ready and it implies that you can't execute your code in this time.
To achieve something similar, copy & paste content of your LaunchScreen into your initial view controller in your Main storyboard (or whatever you do use) and launch your request in initial view controller and then transition to any other view controller.
User is not going to notice LaunchScreen -> Main transition.
Purpose of LaunchScreen is to just replace splash images with something better where you can use auto layout for example, ... In other words, to minimize your work, so, you're not forced to create splash screen for every device screen size, etc. But you are not allowed to run any logic in LaunchScreen.
回答2:
You can just place all your 'JSON code' inside your AppDelegate.swift under function 'didFinishLaunchingWithOptions'.
来源:https://stackoverflow.com/questions/29623812/swift-execute-code-on-launchscreen