What is best practice to constantly receive coordinates - ios

I am kind of new to programming and wanted to know what would be the best way to get data from server? To be more specific my app receives GPS coordinates from server (currently using Alamofire) and then shows them on the map.
Now, I don't know how keep those coordinates updated on device. Should I make loop, where app downloads coordinates from server, let's say, every 5 seconds and shows them on the map? Should loop interval be longer? Ideally I would like if an app could show live location - that is get updates from server every second.
Maybe there is library for my specific problem? Where could I read more about this?
And I could upload some of my code, but now it simply get data inviewDidLoad using Alamofire and show it on map.
EDIT: Why do I keep getting down votes? Seriuosly, I would like to know what I did wrong.

Best way is to use socket programming and listen particular socket where coordinates will be pushed from server. Rather than pulling periodically this will be push mechanism where server will push from it's side whenever it has new coordinate available ...
Here is the Apple's guide line for the same
https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/NetworkingTopics/Articles/UsingSocketsandSocketStreams.html#//apple_ref/doc/uid/CH73-SW4
If this seems like too much you can use pubnub library for ios which is free for 100 devices
Here is the link
https://www.pubnub.com/

Related

Access Blackberry switch on/off and data usage logs

Not sure if this is the right place to ask the question.
I have a Blackberry Curve 9300 phone. Is it possible the access logs which shows when the phone was switched on and off. Also if it is logged when the data was used over network and over WiFi.
I would like to access it without using any code if possible. However, I do not mind a quick and dirty C# application that could allow me to do so. This is a once off activity and I do not really want to invest lot of time in writing code.
try using EventLogger API to get System events,and save it in Persistant DB as as the part of the your application and use it when required

Can't reload MKMapView while doing other tasks

I got my MKMapView running fine on my iOS app. The purpose of the app is to scan a Wifi network for data all the time. Like many times every second. This is just a background task and the user don't need to do anything for that scanning process to work. But, for some reason the MKMapView can't load new tiles at the same time as I'm scanning in the background. I would be lame to show some code from the scanning because I don't even know which part that are interrupting the MapView. So, is this a common problem that have been seen before or is this something weird?
When I move around in the MapView without scanning in background from the Wifi Network the map loads fine and uses both cache and fetches data from the mapping servers.
When I move around in the MapView WHILE scanning in the background no maps are being shown. Just empty boxes that are "telling me that the map are loading".
I'm using this library https://github.com/FuzzyLuke/OBD2Kit to fetch data from an WiFi plug that is connected to a car while I'm trying to show the user's current location on a map.
Suggestions?
I dont know how you're scanning but I guess it is breaking the internet connection and the map view cannot connect to the server then
When you say "many times every second" - how exactly are you 'scanning' the wifi network for data, and what data is it? Because it sounds like you're creating many dozens, if not more, distinct connections per second, which is going to totally cripple your networking stack, and would explain why your maps can't load.
I would encourage you to share more information about what exactly it is you're doing on the network, because that's almost certainly where the problem is. I can guarantee there's a better way to achieve what you want than firing off tens or hundreds of network requests every second.

Passing object/NSData between iOS devices

I'm creating a game, turn based, and I was thinking of using Game Center to handle it, but the passed game-object is evidently max 64kb. Is there another way to pass objects between devices for this use, without having to create a database or storage-server as middle man? The game-object itself for me is probably a lot less than 64kb, but there are some initial variables I would like to send, such as images. With my calculations, the initial data for one game is about 500kb, but after getting those images once, the passed game object is just a couple of kb's, and are never going to include those images again.
Is there a way to send these images directly?
There are a few ways to get around the limit.
This answer mentions Alljoyn which would allow you to transfer that size of files.
You could also send them indirectly by transferring them to your own server, then passing a link to the file to the other player. For a turn based game, this would have good advantages of enhanced reliability as you could put in retries on error for both the upload to the server and the download to the device and control it yourself. I would recommend AFHTTPClient for this, also.
Is there another way to pass objects between devices for this use, without having to create a database or storage-server as middle man?
Without your own server, there isn't.

iOS notification and server cheking

I'm making a program for IOS for the first time. I never had a iPhone so I don't really get how it works...
I want to make my system able to call a webservice on the background and depending in the answer show a notification.
How can I do this?
I read on the Internet that I can push notifications to the phone, however that won't solve my problem because I want my server to track the user position, so it need the user to silently tell the server it's gps coordinates.
Thank you,
GustDD
I will suggest building the app first to run in the foreground. I will assume you already understand how to use the GPS, so will not go into detail on that.
First off, you will need to write the server backend and app pretty much simultaneously. There are many choices for writing the server backend language wise. I prefer python, others ruby on rails. You want to build a REST API for the server that the iDevice can talk to with simple HTTP protocol.
You must decide on the API. You must think about what kind of data you will want to send and receive and how you will wrap the data. Also what HTTP protocols will you be using for specific requests, like GET POST etc. Furthermore, you will have to decide at what URL's on the server will it be useful to GET or POST to depending on the data you want to send or receive. I would suggest you use JSON to wrap your data. It is quite intuitive and easy to encode and decode.
Next you will have to decide how to talk to the server in iOS. There are many great third party libraries that dress up NSURLConnection or you can use NSURLConnection itself (sometimes a bit tedious). I personally like to use AFNetworking. It will do the JSON decoding and encoding for you which is a big bonus.
Finally, once you have the two communicating with how you want and with the data you want, now time to dress it up. You can allow your app to run in the background and collect GPS data and send it. You can also use the notification center to display information it gets from the server in the background.
Update to Comment
This will be extremely helpful for you with background programming. From an Android perspective, iOS is a little bit different since there is not really a direct correlation for Android services in iOS. Every little detail to put your project together is in that link.

How to display live data in iphone app?

I am building an iphone app for my local high school football team. What is the best way to show live data for the scores of games without using a sql db and having to updated the entire app after every game.
there are a few ways of doing it, one would be to create an rss feed on a remote server, and parse that, and if you wanted realtime updates, you could use push notifications.
If you plan on creating the app to only show what the end result of each game was you can use NSXMLParser as #MCannon suggests. If you plan on having the app update in REAL TIME, as in. "The ball is on the 45 Yard line, 3rd and 3". Then you can stick with NSXMLParser but create a NSTimer to update the information every 30 seconds or so.
That would also mean you would need to have the RSS feed updated in real time as well.
The only way to do what you're asking is to have the data stored on the internet in some fashion, then build into your app a routine for consulting the remote data source (on the internet) and update its internal storage accordingly.
It can be done with no DB but the data must exist and be accessible over the internet. As others have suggested, an RSS feed would be a great way to pipe in the data.

Resources