Swift - Execute code on LaunchScreen [duplicate]

半腔热情 提交于 2020-05-29 04:50:08

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!