Register local notification from background - iphone

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.

Related

How to receive acceleration-related data from the onboard hardware, when application in background mode?

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.

CLLocationManager disable monitoring significant changes 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.

iPhone: Find out where am I when application is in background

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.

Notifications for changes to Location Services?

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.

How long can an iPhone app live in the background?

I can't seem to find a clear answer to this-- I'm spec'ing out an iPhone app that I'd like to have live in the background and notify the user at certain periods throughout the day. So the user would launch the app in the morning and then continue to use their phone, then every few hours the app would pop open a notification dialog.
Will my app ever be shut down (automatically) by the OS? Or will it just live forever, notifying user when it needs to?
thanks,
Eric
Basically there are three kinds of running in the background on iOS 4:
Running in the background to "finish" stuff (e.g. upload a posting or a picture, finish processing something etc.). You ask the OS to grant you extra time after the user switches to another app, and it will tell you how much time you got. You can't run in the background for an indefinite time.
Running in the background to do specific stuff: VoIP, tracking location (e.g. for GPS navigation), or playing audio. You can only do the stuff that you told the OS you would do in the background.
Local notifications (UILocalNotification). From your description, this is what you're looking for. You're not actually running, you just schedule notifications, and when it's time to notify the user, they'll be notified and can go to your app. If you need to notify the user dynamically (i.e. you don't know ahead at what times they need to be notified and it's not location or VoIP triggered), you might want to look into push notifications.
Apple has a good overview here:
https://developer.apple.com/documentation/uikit/app_and_environment/scenes/preparing_your_ui_to_run_in_the_background/about_the_background_execution_sequence