I want to send GPS information when the program is running in the background of iPad.Thanks for your help.
1 Answers
By "background", I'm assuming that you mean on a background thread? If so, read on... otherwise, let me know, and I'll try to address better...
Here's how I tackled this:
1) Create a singleton "CoreLocationManager" class that implements CLLocationManagerDelegate
and has a CLLocationManager
property. Tell your locationManager to start updating by calling something like
[self.locationManager startUpdatingLocation];
Note: you probably do NOT want to have this locationManager constantly updating its GPS location (as this will drain the battery quickly). I shut mine off after I've got a good location and update only when needed.
2) Create an NSTimer set to fire whenever you would like to update the GPS location. This is also a great spot to send the desired information to the server.
3) Use a library such as AFNetworking (see https://github.com/AFNetworking/AFNetworking) to create asynchronous HTTP request in the background (easier, in my opinion), or roll out your own asynchronous dispatch queue in the background (harder, but maybe more robust, depending on circumstances)
If you're not sure what singleton
, NSTimer
, grand central dispatch (GCD), or CLLocationManager
are, you've got a bit of learning to do. Here's some resources on these:
Singleton:
http://en.wikipedia.org/wiki/Singleton_pattern
http://www.galloway.me.uk/tutorials/singleton-classes/
Grand Central Dispatch: https://developer.apple.com/library/mac/#documentation/Performance/Reference/GCD_libdispatch_Ref/Reference/reference.html
CLLocationManager:
Good luck!

- 12,454
- 8
- 55
- 81
-
Thank you very much.Maybe my question is not clear.I just want to achieve that when I press the "Home" and the software is running in the background(applicationDidEnterBackground),the program can also send messages by socket(I use the asyncsocket). – ling rong Dec 11 '12 at 06:03