I want to load some data from web at the starting of my app launch. I have set a splash screen and in didFinishLaunchingWithOptions I have set the sleep(10). Now I want that in this time interval my app call the web service and load the data but I am not able to do this. Please help me out or give any suggestion to do it.
相关问题
- CALayer - backgroundColor flipped?
- Core Data lightweight migration crashes after App
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- State preservation and restoration strategies with
相关文章
- 现在使用swift开发ios应用好还是swift?
- UITableView dragging distance with UIRefreshContro
- Could I create “Call” button in HTML 5 IPhone appl
- TCC __TCCAccessRequest_block_invoke
- Where does a host app handle NSExtensionContext#co
- xcode 4 garbage collection removed?
- Xcode: Is there a way to change line spacing (UI L
- Unable to process app at this time due to a genera
During sleep, the thread (in this case, the main thread) is unable to do anything.
I would recommend you simply show the splash screen, start loading the data and hide the splash screen once all the data has been loaded.
Please see here: https://github.com/k06a/LaunchScreenViewController.
Display splash view controller right before the app's first view controller appears. When you are done loading data from web or initializing, dismiss the splash view controller.
Sleeping or performing a selector after a specific time are not the correct approaches because you never know how much to wait depending upon poor internet connectivity.
hey mate see bellow code..
i hope this help you...
:)
Sleeping the main thread and showing the splash screen for long time is not a good idea. You can achieve the same thing by following a simple trick. I think in your case service is being called from the very first view controller after hiding splash screen. So you can create a modal view containing the same image like splash screen. And display like following :
When you are done with service calling / long loading event just dismiss the modal view.
Big Question!
First of all, don't make the Main thread sleep, nothing would work there, so it is just wasting time.
Instead, Setup something like an Updating Page with constantly running UIScrollView, Which would disappear only when your data has been fetched.
Use the delegate for the webservice, through which you would call a function in AppDelegate to remove the Loader View and add HOMEPAGE, when data has been fetched.
Something like,
this is just an example...
Hope this helps! :)