I can get the current location of my iPhone but I was wondering if it is possible to call my methods when application is in background and pop-up message(may be using local notification?) if user has reached at particular location.
Thanks.
Yes, this is possible. A local notification is also an excellent solution.
All you need to do is to set the flags for background position updates in the app plist. Then, in the callback methods for the location manager, perform the distance and/or location tracking logging and fire a local notification.
Related
Am developing application for calculate count of user moved steps and draw the user activities in the map. And we are using UIAccelerometer delegate for receive acceleration-related data from the onboard hardware. So I need to receive acceleration-related data when the application in background mode too. Last time one of my application got rejected because of using location service in background, Apple suggested me like "you can only use this background mode if your app truly needs this information to provide value for the user". Kindly suggest the best approach for this application.
You cannot run accelerometer in background.
You can track user's location in background... however, if you just keep tracking it and do nothing with that info.. apple is going to reject it and tell you to just get the lates location when app comes to foreground.
what you can try is.. update the user of total distance covered etc on a regular basis (like run keeper) and this will justify tracking location in background.
But first, you can try appealing to the review board explaining that you need to track location in background because you show entire route travelled by user when app comes to foregraound. and compare this to existing apps like run keeper and if you are lucky apple may approve your application without any changes...
This can easily be done.
What happens in that iOS put your application in halt state when your application is not in running in foreground state.
You just need to register your application for background execution.
Refer :
http://dcraziee.wordpress.com/2013/05/20/background_ios/
Also refer :
iOS background application network access
for apple policies about using location service.Which states that you can use location service in background.
I'm using background geolocation to schedule local notifications when the user is in a specific location.
Since theses notifications are link to a commercial operation I've got a date, stored in the userdefaults to manage when I should disable the background geolocation when the operation is other.
I don't want the user to have to launch the application to be able to disable the significant changes monitoring.
So I tried to stopMonitoringSignificantLocationChanges the CLLocationManager directly in the locationManager:didUpdateToLocation:fromLocation: but it doesn't seam to work.
Any advice? What is the best practice for this issue?
Thanks.
Given the rules of the road for backgrounded applications or apps that aren't running, your hands are somewhat tied here.
Here is your one and only option if you want to disable location without any interaction from the user.
Each time your user's location updates from the background, your location manager delegate will receive this update. You don't get a lot of processing power here, so keep it short and sweet or register for a long running background task, check your date and if you are done with location, call the stop monitoring call there, reset any data or flags in your user defaults and you are done.
If you trigger from a local notification, the user will need to click on the open button to perform any actions. You can fire notifications from your background location delegate method for sure. But that is your one and only path to automating anything without user interaction. What you do there is up to you. There is no problem with checking for location udpates and turning that off from the background delegate method.
I have a situation where I have to present alert while my app is in background.
So I was thinking that the solution is Local notification.
But the problem is that, I want to show that alert only when user has crossed a particular predefined location point.
So I have to show the notification without any registration for it in Foreground(Or you can say register the local notification in background).
Is it doable ?
Please help.
Yes, you can let your run in the background while you still receive location updates.
You have to the add location to UIBackgroundModes in your apps info.plist;
And any instance of CLLocationManager will keep receiving location updates.
But be aware that this could drain the battery of the iPhone really fast, so it's a good idea to only monitor major location changes.
I've been experimenting with CLLocationManager for an app I'm building. I understand how to check if Location Services are enabled and whether or not a user has allowed my app to use their current location.
If a user allows my app to use their location initially, and then the user either:
turns location services off explicitly
puts the phone in airplane mode
explicitly de-authorizes my app to use their location
Are any notifications posted that I can subscribe to and respond to automatically when they reopen my app?
If not, would the best way to handle this scenario (so I can update views that were displaying GPS coordinates) to manually put this check in my AppDelegate's applicationDidFinishLaunching and applicationWillEnterForeground methods?
The reason I was thinking it should go there is because when you relaunch an app, viewWillAppear is not triggered for the first view, and if that view needs to change from showing GPS coordinates to a friendly message asking them to re-enable location services, the AppDelegates were the best hook I could think of.
Thanks!
On iOS 4.2 and later you will get a delegate call
- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status;
Your approach is sound. If you find Core Location is unavailable on re-opening the app or network access has changed, you could then send a notification to those viewControllers that need to updated accordingly. Check out NSNotificationCenter
Even if you adopt the above I would suggest you do these check every time in viewDidAppear anyway as network access could be lost at anytime. Plus in line tests where you do any location checking.
Basically, I've been learning Objective-C and how to develop for the iPhone over the past few months and have created a few basic applications. Now I've got an idea for an iPhone app that I'm interested in developing and I'm just looking for a bit of advice on wether it is actually possible. I'm looking to create an app that sends the iPhones location to my server every 15 minutes - even when the app hasn't been opened/isn't opened.
Is this possible? If it is, could you point me in the direction of some more info on this subject.
Thanks.
You can declare your application as needing background location services. But this is available only in iOS 4, and user needs to allow location services for your app.
More info about multitasking can be found here
More info about getting users's location can find here
The answer to your question could be a partial YES or a partial NO. Basically ur app can give location updates even when it is not opened ... and u can handle it to be sent to ur server whenever user location updates .. but it is not possible to send the location update on a time basis like every 15 minutes ..
If you want ur app to register for location updates in background mode, u have two options:-
send location update on significant location change (i.e. a location update is sent when user moves significantly such that the cell tower changes for the user ) in this case u have to use startMonitoringSignificantLocationChanges OR
send continous location updates by using startupdatingLocation and in info.plist file declare background mode key for location updates (uses GPS)
and u have to handle didUpdatetoLocation for location updates in both cases and Ur app will be woken up in background as soon as a location update is recieved (beware of battery usage in 2nd case)