Watch Kit Asynchronus data - ios

I am creating a simple watch kit app that shows me the local bus schedule. To get the schedules I have to make a request to the bus company's website and parse the HTML. (They have no public api....)
Alamofire is used to make a request and then parsing the HTML with SwiftySoup. The data is then saved into an array with structs and the table is created. Then the array is saved to a JSON file. So when the app is force closed and starts again, the app checks if the current time is past the first bus time, if true the app request the website again to get the next schedules otherwise it just creates the table with the number of schedules.
Since Alamofire is doing an asynchronous request, the app finishes "starting" even if it does not have any data. How can I "force" the app to wait for the request and parsing to be finished before displaying the UI?

As Josh Caswell mentioned it is not possible. So created UI for the loading state.
If the app did not have any schedules cached or the cached data was old, the app pushed the loading interfacecontroller. When the loading was finished the interfacecontroller poped itself and the main interfacecontroller initilized with the corred UI.

Related

Alamofire, push a new request ahead of others queued

I have an app that is firing a lot of initial Alamofire GET Requests to an API to eventually collect the data. However there are buttons on the app screen which also fire off POST requests to save etc. Though when i tap on the buttons, the alamofire requests take a long time to fire off due to the fact all the other GET Requests are still running.
Is it possible to make it so I can push the POST request ahead of the queue?
There is no way to do this using Alamofire or the underlying URLSession APIs. What you'd want to do is build your own request queue that lets you keep perhaps half a dozen requests in flight at any time. You would enqueue all of your GETs and then push your POSTs to the front of the line when needed.

iOS, best time to call Core Data queries on app start

My app has Background App Refresh when it receives a Push Notification where it fetches data from the server and stores using Core Data, now I need to process the data when the App is becomes active again. So, I tried the fetch query when -(void)applicationDidBecomeActive:(UIApplication *)application is called to get the data.
But, if I directly query the tables immediately, the query returns 0 objects if the App is in stopped state. I guess the Core Data connectors are not prepared by the time I call the query. I am sure that the data is saved in the tables as if I make the query using dispatch_after 2 secs , I get the complete data.
I do not want to make the Query on viewDidLoad/viewDidAppear cause, it is not necessary that these will be called when the app goes becomes active from non active state.

ios - Bulding an app that have push notification appear on a specific time interval

I'm building my first application.
I'm making app where I'm doing some fetching from rss feed of web site and loading it to a TableView. What I want is next:
-to inform a user when new feed arrive, when my app is closed (user can set the time interval of update frequency in app settings page) - with Local Notification
I'm using NSURLSession for downloading data, storing it with Core Data, and want the Deployment Target to be iOS 7.1.
Just want to know is it possible and steps that I need to do to implement it correctly.
What you want is called Background Fetch. Background fetch can fetch data from your servers even when the app is not running.
Local notifications would be of no help here. Even when a local notification has been fired, user will have to click on it to fetch data.
Look it up. There is a pretty decent tutorial here.

HTTP Request as background task with local notifications in iOS

If you aren't that into Android, there's something called a "background-service" for the applications in that OS. Which basically gives the developer a opportunity to make some background tasks without forcing the application to be in foreground.
So are there something like this in iOS? (Version 5 and newer) What I basically want to do is to call a API and fetch some JSON data every minute, then parse the result and then present a local notification banner to the user depending on the result that were fetched from the HTTP request. I hardly believe that this shouldn't be possible in iOS, but I haven't found anything like this yet.
Call the API once every minute and fetch some JSON data.
Parse the JSON data into and add some logic to handle the data.
If a local notification should be presented or not, depends on the result from the request.
This can only be done in a very limited manner. Pure background processes are only allowed in special forms (for example media players, VOIP or location based services). You can start limited background tasks with beginBackgroundTaskWithExpirationHandler:, but they won't run forever.
More information can be found here: Run app for more than 10 minutes in background

ASINetworkQueue Correct Usage and Storage

I have an app that submits data using ASIFormDataRequest to a remote web site. I want to allow the user to store them for upload later if they are offline (eg: iPod touch or out of cell coverage, etc). Is ASINetworkQueue the appropriate tool to use? I imagine I would store the request in a queue belonging to the app delegate and, whenever a new submission was added or the app launched, reachability would be tested and, if good, would complete each request in the queue.
Is that logic correct? (I know it is bad practice to check reachability immediately on app launch, but I would tweak that to a good time.)
If so, my next question is, how do I get a ASINetworkQueue to persist between launches, both cold and from background? I imagine it would involve writing it to NSData and writing that to NSUserDefaults or even to file.
Thanks for any help!
If you are going to upload data asynchronously but handle offline usage, I would recommend writing the data to a local database or file and then having some sort of "uploaded at" timestamp for a status. When your app starts up you can query your local database for any objects that have not been uploaded. I don't know what your app is doing but you may find this method less error prone and better for giving proper feedback to your user through the UI.

Resources