Get data from server in iOS - ios

I have a script that takes hours and outputs if it is open or closed and I want to run this on my server, and then from my iOS app get if a certain place is open or closed. And I was wondering how I could do this without generating an JSON file and then parsing that as I would to frequently re-generate the file as the things change from open to closed and such. So is there a way I could make a call to the server and just get the data that I want?

Im not entirely sure whether you are asking specifically for an iOS framework for requests and responses or server side. So I figure I will try to answer both. Here are some swift projects you might be interested in. I'm not incredibly familiar with objective c yet but these resources might prove useful.
Alamofire
This will help you send and receive http requests.
Swifty JSON
This will help with JSON parsing
However if your question is more regarding server side issues. You could look into a REST api and that way you could only request certain entities that you are interested in instead of just sending back the entire batch of information with all of your data, and searching through it on the iOS device.
Hopefully this is somewhat helpful.

If you are only planning on GET-ing some content from the web you can use the NSURL class. NSURL *lru = [NSURL URLWithString:#"http:mywebserver.com"] and then create a new string object from the url with [NSString stringWithContentsOfURL:lru], or any data you would like. If you are trying to hold a session or having more control over the request, I would suggest looking into the NSURLSession class.

Related

GetStream feeds without enrichment

Because of some requirements, we don't want to use the enrichment system where stream gets from its own collection the data objects.
In fact, we want to do it as the backend would do, using our own database, but directly from the client (because we don't use any database)
However, when retrieving the activities, we get the following: (iOS)
JSON decoding error: The data couldn’t be read because it isn’t in the correct format..
We create activities in the way that, actor is User:UserID, Object is Object:PostID, Verb:ActionEnum.
That's all we do.. but one more time, we are facing issues on iOS SDK..
Why?
To anyone having this issue, it was coming from the iOS SDK itself... It turned out that, using the REST API from our client solved the issue, but we had to use the "extra" field part of Go to deliver our required data :)
Hope it helps

Check if resource at NSURL exists BEFORE downloading

I want to pull down new images from a website that is updated regularly. However, there is no API for that site, so I'm trying to fetch it by url, as the images are numbered. The way I've decided to do this is have the app query the website on first launch and loop through the URLs until I get a 404. Then I store that URL and on next launch loop through till I get another 404, etc. Now I know that is less than ideal, but I'm just building a prototype. Anyway…
Since these are images we're talking about, I can't just download them all on first launch. Waste of bandwidth, could take minutes or even hours… So I just need a way using NSURLSession or whatever to get the http status code for any given image without actually downloading it.
You can do this by getting the "HTTP Headers".
This answer will help, if you're comfortable porting Objective-C to help. I can help you with it if required.

How to parse GTFS data on iOS using swift?

I am using http://datamine.mta.info/list-of-feeds api to get GTFS data for United States transportation.
When you call http://datamine.mta.info/mta_esi.php?key=<key>&feed_id=1 api you get one "gtfs" file which contains data that I need to parse in iOS so that I can display.
Once I get the file, how do I parse it? So far I haven't found a way to do so. Anyone can help me on this?
Thanks,
Pratik
The MTA requires that you serve the realtime data from your own server, so you might as well parse the Protocol Buffers server-side, and then make your data available to your iOS app from your server. If you do it that way, then you can use e.g., a Python or C++ library to parse the PB into JSON or whatever and structure it in an optimal way for your app for download.

How to send request to external server in Swift for stats purposes

I am building my first iOS game. Now I would like to know how many people have played the game, and how many games in total have been played. As far as I know Apple does not show these kind of stats, so I figured the best way to do this is to ping a hidden URL to my webserver every time a users plays a round of the game.
The game I am making is written in Swift. I have tried to find some sample code to ping external URL's, but so far I have not found anything.
Could anyone point me in the right direction?
In my opinion the best thing to do is to use google analytics.
It will give you a lot of statistics (like how many times each screen has been seen etc)
https://developers.google.com/analytics/solutions/mobile?hl=fr
But if you want to do it on your own you can easily call an URL on your web service. Personally I love AlamoFire (https://github.com/Alamofire/Alamofire)
there is a lot of sample on their github page.
You need to configure an external API to connect your swift app with a db running on a server.
In swift, to make pretty request to external services, you can use alamofire. It's a pretty library of the same creator of afnetworking. In a simple way, you can make http networking in Swift. Alamofire only runs for IOS 8 or later.
You need to install alamofire, call the library in your viewcontroler (import Alamofire) and make your request. Read the library documentation, it's clear.
If you are simply trying to hit a url on your website, without passing any data, you can do it very simply by.
let url = NSURL(string: "http://mywebserver.com/secret_end_point")
let session = NSURLSession.sharedSession()
let task = session.dataTaskWithURL(url!)
task.resume()

Storing data in Iphone

I have a web site. This is a drupal site using PostgreSQL database.In this web site we can get direction data from one city to another by going to direction tab and giving start and end location.go to this URL and check that. http://www.zoomsrilanka.com/pathfinder .
direction data is loaded to dashboard. I want export that direction data to a iPhone so that this data can be used another application in the iPhone. If I tell in another words I want to send that data and need to store in a iPhone so that it can be used for another task. I want to know that how to store data in iPhone?
If you have control for the website you mentioned, You can create one webservice which will give you the required data in XML format by accepting parameters from iPhone.
i.e. you can call webservice from iPhone passing parameters and your webservice will provide response to that request in the form of XML and on receiving XML you can parse that and use according to your requirement.
It's not possible to share data between different IPhone applications. Each application has it's own "storage".
You can create API if you have access of server which you mentioned, API should give XML/JSON in response, so iPhone can take this response and parse accordingly, and store structure in sqlite local database.

Resources