How to turn off Location service with objective-c? [duplicate] - iphone

This question already has an answer here:
How To Turn Location Service On
(1 answer)
Closed 8 years ago.
I want turn on/off Location Service on Iphone with objective-c.
How to turn on/off Location Service programatically?
Is it possible?

No it is not possible, you cannot control settings within applications like bluetooth/airplane/wifi and location service.

Sorry. That's just out of your hand. You cant stop location services. One thing you can do is, you can stop updating location by using this :
[myLocationManager stopUpdatingLocation];
Call this method whenever your code no longer needs to receive location-related events. Disabling event delivery gives the receiver the option of disabling the appropriate hardware (and thereby saving power) when no clients need location data. You can always restart the generation of location updates by calling the startUpdatingLocation method again.
But to stop services, you have to go to settings options.

Related

Swift 3 - Retreive location at all times [duplicate]

This question already has answers here:
Periodic iOS background location updates
(9 answers)
Closed 5 years ago.
I have an app that is used for tracking van drivers. I need to be able to get the location (x&y) every 30 seconds or so. I have a method and a timer that allows me to do this.
I was wondering how (if at all possible) I can have this working regardless of whether the app is active or not?
I've recently started messing around with core-location so my knowledge my not be bullet-proof.
If the app is is still active but only in the background then as long as you set the allowsBackgroundLocationUpdates to true then you will get updates. But this could become battery consuming, it could go on until your battery dies.
You may want to avoid constant location checking by setting:
pausesLocationUpdatesAutomatically to true.
However if you do set it to true then if your driver stops at a location for too long(I don't know what means too long) then the app would stop completely from tracking location until you bring the app to foreground again. I'm saying that based on:
Important For apps that have in-use authorization, a pause to location
updates while in the background ends access to location updates until
the app returns to the foreground and is able to restart location
services. If you do not wish location updates to stop entirely,
consider disabling this property and changing location accuracy to
kCLLocationAccuracyThreeKilometers when your app moves to the
background. Doing so allows you to continue receiving location updates
in a power-friendly manner.
So it's a little tricky. You may want to set pausesLocationUpdatesAutomatically to true but then if your business requirements allow...do something like stopUpdatingLocation() after 1hr of app being in background to stop location updates completely.
Yes, this is possible.
If your iOS app must keep monitoring location even while it’s in the background, use the standard location service and specify the location value of the UIBackgroundModes key to continue running in the background and receiving location updates. (In this situation, you should also make sure the location manager’s pausesLocationUpdatesAutomatically property is set to YES to help conserve power.) Examples of apps that might need this type of location updating are fitness or turn-by-turn navigation apps.
For more information, check out the Location and Maps Programming Guide.

CLLocationManager while app is in background state

My question is: Is CLLocationManager continue running, while my app is inactive?
Yes, if CLLocationManager is first called startUpdatingLocation method, and in the AppName-Info.plist file is added Required Background Modes -> App registers for location updates
Yes, it could. You have two options for handling location service events when your app is suspended, which can be read at the article: Getting the User’s Current Location.
As noted:
There are two different services you can use to get the user’s current location:
The standard location service is a configurable, general-purpose solution and is supported in all versions of iOS.
The significant-change location service offers a low-power location service for devices with cellular radios. This service is available only in iOS 4.0 and later and can also wake up an application that is suspended or not running.
Also, as noted at the bottom of this article in the section "Getting Location Events in the Background":
If your application needs location updates delivered whether the application is in the foreground or background, there are multiple options for doing so. The preferred option is to use the significant location change service to wake your application at appropriate times to handle new events. However, if your application needs to use the standard location service, you can declare your application as needing background location services.
An application should request background location services only if the absence of those services would impair its ability to operate. In addition, any application that requests background location services should use those services to provide a tangible benefit to the user. For example, a turn-by-turn navigation application would be a likely candidate for background location services because of its need to track the user’s position and report when it is time to make the next turn.
There are some important subtleties with this (as of iOS 7.1):
The Location Update background mode should NOT be used if you are just looking for significant change and region enter/exit events. You will still receive these events even if the background flag is NOT set, and you will save a lot of battery at the same time.
If you do the above, you need to be mindful of limited permitted background time. If you don't take care to wrap up network requests etc. in the permitted time, you will network transaction failures.
You should ONLY use the location background mode if you need to use detailed location tracking (e.g. -startUpdatingLocation), in which case this background mode will keep your app awake.
Using the location background mode when not getting detailed location will piss off your users and may get your app rejected during the review process (depending on how you use location throughout your app).
Your app may be killed at anytime by the OS if you do not have the background location mode set, so you will need to be sure to properly re-initialize your CLLocationManager instance in applicationDidFinishLaunching or applicationWillFinishLaunching in order to get the subsequent updateLocation or didEnter/ExitRegion delegate call. Just because location wakes up your app with a location update, it does NOT magically re-create your CLLocationManager without you programming it!
Hope that helps!
To disable CLLocationManager while the app is in backround mode you simply must not add the
"App registers for location updates"
in the
"Required background modes"
key of the info.plist file.
I suggest to use the significant-change location service instead of the standard location service whenever possible, to preserve device battery.

Delegating something to the OS [duplicate]

This question already has answers here:
If background applications can't launch automatically how does Cardcase launch on a location change?
(2 answers)
Closed 9 years ago.
I was wondering if it is possible to tell the iphone operating system to lauch my application when I enter a particular region...If it is how can I do it?
Thank you
This will happen automatically for region monitoring - Once your application has registered for region monitoring (while it was running) and then gets suspended or stopped, and then if the region is crossed even when you app is not running the app is re-launched in the background to handle that event, from there you can post local notifications etc to alert the user and bring the app to foreground if the user is interested.
See reference to the Apple documentation here
No, your application can't launch itself for any reason.
You can, however, use background location and background local notifications to alert the user and allow them to opt to open your app.

iPhone App to send location even when closed

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)

iPhone background network connection by timer

I need to write an application, that every 10 minutes it should be awaken from suspended mode, get user location via gps and send this information to the server by network.
Depending on the response it should return to the suspended mode or show local notification to the user.
Is there a way to do this on iOS 4?
I've tried different approaches, but the only working for me was to start monitoring user location in backgroind and declare the application as location background application. In that case it worked in background and has a network connection. But this approach takes a lot of power and not accepted cause application should work 24/7.
May be there is a way to write some daemon that should work in background and wake my application every 10 minutes?
Apparently, Pastebot tried to do something similar with the 'audio' multitasking declaration (by playing a silent audiofile) and got rejected.. UNTIL they actually presented a option to the user to pick which audiofile they wanted to play. It's in the appstore now. :)
In this case: What is your reason for not wanting to use the location updates? If battery-usage is a concern, you can use the 'significant location changes only' option, after which you can temporarily change to a more accurate option.
This isn't possible outside of the method you have already tried.
The iPhone background task API will allow you to run a location service in the background.
There is no way to write daemons for the iPhone without jailbreaking, and that is not something I'm able/prepared to help you with.
App store friendly: use new APIs in iOS4, which allows u to make use of GPS location
Anti App store: create a daemon by adding a specific plist file to System/Library/LaunchDaemons/ and put ur app under Applications/. this approach requires a jailbroken iPhone however...
detailed information plz google the following keywords: daemon, multitask, background, etc...
cheers, Lloyd