I am working on iOS application in swift. I need to parse two web api(XML) at application launch time and during this period, I need to show launch screen. So I sent a synchronous request to parse the data from server.
If net connection is good then application working fine but due to slow net connection or it takes more then 20 seconds to load data from server it can quit automatic.
How to fix this issue. Please suggest it.
You should never send synchronous requests in main thread!
Add new VC on load. There you can load your data async. When data is ready, pass it the next VC.
Related
I'm getting this error (not all the time but several times) while getting response -which may contain large amount of data- from database in my ios app. Here is the case
I opened the menu that i will parse data, while response data is being downloaded, i put my app to background and opened Facebook app and then i went back to my app and got this error. (I have SSL Pinning in my app.)
Does iOS stop secure connection and start another in the same time, or maintain current and start another?
Is there any advice that I should follow?
I have an app that lets the user send messages with images. A user might hit send, then immediately close their phone or switch to another app.
We were running into an issue that if there's temporarily a bad network connection the message would fail to send. We switched to using NSURLSession backgroundConfigurationWithIdentifier so that backgrounding the app doesn't immediately time out the running request. We switched to using this for all our api requests, thinking that it wouldn't hurt for every request to able to continue in the background if the app were closed at the wrong time.
Fast forward a couple weeks we're noticing all requests seem slow. Using wireshark I just discovered that this background session seems to use a new http connection per request, meaning it requires setting up a TCP connection and new TLS handshake for every request, which was adding a ~500ms latency on every request in our app. This is a pretty big deal but I can't find this behavior documented anywhere, including the link above or Apple's background transfer considerations.
So my question is, is this behavior expected, or am I doing something wrong somewhere? Is there an easy way with NSURLSession to make an HTTP request that will use an existing keep-alive connection if there is one, but can fall back to the backgroundConfiguration if the app gets moved to the background?
NSURLSession is the recommended way to fulfill your use case. Have you tried setting backgroundSessionConfig.discretionary = true
iOS Reference
A Boolean value that determines whether background tasks can be
scheduled at the discretion of the system for optimal performance.
If that doesn't help, I recommend filing a bug with iOS.
If a basic call to post some data to a server using NSURLSession (in this case using Alamofire) a call is started with the app in foreground, while the call is in progress the app is move to the background and is suspended. When the app comes back to the foreground, what happens to the call that was in progress? Does it timeout (App is using default 60 seconds ephemeralSessionConfiguration) or will it receive some other error? If the timeout has not yet been reached is the call still waiting or has the OS terminated it? I have the default background mode and have no requested no background time. Trying to debug an issue that happened in the field.
Your network requests are suspended when your app is suspended. So basically the answer is that it depends on whether the server gives up on you while your app is in the background, and on whether the socket in the kernel gives up on your app while it is suspended.
As a rule, if you need to move data while your app is in the background, you should be using a background session and a download or upload task. That way, the actual data transfer happens in a separate process (that doesn't get suspended) and your app will get the data.
With that said, using a background session is fundamentally in conflict with using an ephemeral configuration, because it involves storing data on disk. So if you really need an ephemeral configuration for some reason, your app's requests are likely to just fail a few seconds after the user hits the home button, and there's not much you can do about it as long as you're making requests ephemerally.
iOS 7+, 8 (last one not released yet, however targeting on it).
The app.
As a user I start the app and switch to other apps (mail, safari, etc.), leaving the app running but not a foreground one.
The app establishes HTTP connection to server via Internet and starts periodically sending GPS location data to the server (with some interval).
Is it possible while the app is not on the foreground? I mean is it possible to get geolocation data and periodically send it from the app to the server via HTTP POST while using other apps?
If the answer is "YES", please help me with references. I will investigate it further.
Yes, and the method you want to research is performFetchWithCompletionHandler:
Implement this method if your app supports the fetch background mode.
When an opportunity arises to download data, the system calls this
method to give your app a chance to download any data it needs. Your
implementation of this method should download the data, prepare that
data for use, and call the block in the completionHandler parameter.
When this method is called, your app has up to 30 seconds of
wall-clock time to perform the download operation and call the
specified completion handler block. In practice, your app should call
the completion handler block as soon as possible after downloading the
needed data. If you do not call the completion handler in time, your
app is terminated. More importantly, the system uses the elapsed time
to calculate power usage and data costs for your app’s background
downloads. If your app takes a long time to call the completion
handler, it may be given fewer future opportunities to fetch data in
the future. For more information about supporting background fetch
operations, see “App States and Multitasking” in iOS App Programming
Guide.
https://developer.apple.com/library/ios/documentation/uikit/reference/uiapplicationdelegate_protocol/Reference/Reference.html#//apple_ref/occ/intfm/UIApplicationDelegate/application:performFetchWithCompletionHandler:
Just as Mike mentioned, you should look into background fetch. For more details, checkout this objc.io post.
The information you need should be in the Background Fetch section.
I have a Windows phone 7.1 App, and I'm trying to implement som UI tests using Expensify's WP7Test framework and SpecFlow's Gherkin-feature.
I'm having real trouble testing whether my application is started correctly when run for the first time, because i prompt the user with MessageBox'es about access for GPS and Internet before the main screen is shown.
Firstly this code was (rather crudely) in the "App" Class constructor - i tried moving it to the "OnNavigatedTo" method of the MainPage, same result.
Trace:->Command timed out waiting for send
Trace:->Command timed out waiting for send
Trace:->Command timed out waiting for send
Trace:->Command timed out waiting for send
Trace:->Command timed out waiting for send
Trace:->Command timed out waiting for send
Trace:->Command timed out waiting for send
-> error: App is not yet alive
It work's perfectly when i comment the messagebox'es out, but i really want to test them as well - my MainPage renders accordingly to the answers of those prompts!
I have tried a lot of diffrent Steps in the Scenario for starting the application:
Given my app is clean installed and running /
Given my app is running within 20 seconds /
Then my app is running /
Because the test framework interacts with ui elements it has to use the ui thread - so I guess you messagebox is somehow blocking the ui message pump here.
Perhaps this case is caused here because this is your first page... but I'd need to do some testing to check.
One simple workaround could be to use the asynchronous message box methods for your functionality - but this would require you to reorganise your page init functionality a little.
If this is a serious issue for you, please do log an issue and a sample test in github.