I want to have the same functionality as the Map app, where user is prompted every time they press the 'current location' button to turn on their Location Services if they are off:
Turn off location services
User presses 'getCurrentLocation' button
App tries to get location using CLLocationManager
User gets 'Turn On Location Services..." message that shows "Settings" and "Cancel" buttons.
User taps 'Cancel'
User presses ''getCurrentLocation' button again
App tries to get location using CLLocationManager again
User does not get 'Turn On Location Services..." message any more
In the Map app, the user gets "Turn On Location Services..." message every time. How can I get my app to do the same? I made user I am using a new instance of CLLocationManager, in case that was the problem, but it was not. I can't see any settings that would affect this.
If I make my own Alert I cannot get the same 'Settings' button functionality. Also, I don't want the user to see multiple Alerts that look the same.
Any ideas?
New in iOS 8 there is a constant called UIApplicationOpenSettingsURLString.
From the "What's new in iOS" document under UIKit is the line:
You can take the user directly to your app-related settings in the Settings app. Pass the UIApplicationOpenSettingsURLString constant to the openURL: method of the UIApplication class.
From Apple's documentation:
UIApplicationOpenSettingsURLString
Used to create a URL that you can pass to the openURL: method. When you open the URL built from this string, the system launches the Settings app and displays the app’s custom settings, if it has any.
You can pass this into the UIApplication openURL: method. It might look something like:
NSURL *settings = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
if ([[UIApplication sharedApplication] canOpenURL:settings])
[[UIApplication sharedApplication] openURL:settings];
If you want to point the user back to the Location Services screen in the Settings app, you can do so by sending them to a special URL, like so:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString: #"prefs:root=LOCATION_SERVICES"]];
You can query the shared CLLocationManager instance if the location service is enabled. The correct way is to respect the users choice to disable location services.
But if you want to, just start the location service anyway and the user will be prompted to start it again. If the user opts in on the request locations will begin to be reported on your delegate as usual. If the user instead denies your request you will get a failure callback to the locationManager:didFailWithError: delegate method. The error will have an error code of kCLErrorDenied.
I would strongly discourage you from doing this, but you can try to start the service again if the user says no, and the user will be asked again. Most users will hate you for it though.
Related
I am trying to access user current Location.When i call CLLocationManager(startUpdating).
Its show alertview ex. "Xyz App would like to use your current location".
If user taps "Dont allow". and now if i check authorization status it reply 2 "means Denied".
I check status and if its 2(means denied), i show showalertview "Xyz want to use your current location"
Now if user Taps "Allow" how to enabled it programmatically,instead of user goes to setting screen & manually enabled.
You can not enable programmatically it the user taps don't allow. You just can inform the user that he has to go to settings->Location Services and enable it for your app if he wants to use this feature.
You can set the purpose of the location and it will be displayed in the first alert view that is displayed by the os when will ask user for permission.
purpose
An application-provided string that describes the reason for using location services.
#property(copy, nonatomic) NSString *purpose
Discussion
If this property is not nil and the system needs to ask for the user’s consent to use location services, it displays the provided string. You can use this string to explain why your application is using location services.
You must set the value of this property prior to starting any location services. Because the string is ultimately displayed to the user, you should always load it from a localized strings file.
How to turn ON location services through Code in my application if location service is in OFF condition i want it to ON through alertView i have two buttons in alertview cancel & settings
if i click settings it needs to go settings of the device is it possible???
Could anyone help me??
thanks...........
You can't enable location services in code. You just invoke the service, and iOS will seek permission from the user on behalf of your app.
I've had to deal with the same problem but this is just not possible under iOS. You have to check if location services is enabled :
[CLLocationManager locationServicesEnabled];
and if not, ask the user to go to the settings to enable it (through an AlertView for example).
Note that Apple says :
locationServicesEnabled : You should check the return value of this
method before starting location updates to determine if the user has
location services enabled for the current device. If this method
returns NO and you start location updates anyway, the Core Location
framework prompts the user with a confirmation panel asking whether
location services should be reenabled.
But that only seem to work the very first time you check. If the user denies, the confirmation panel is not shown anymore.
You may also check :
switch ([CLLocationManager authorizationStatus]) {
case kCLAuthorizationStatusDenied:
case kCLAuthorizationStatusRestricted:
case kCLAuthorizationStatusNotDetermined:
}
Those are the two basic questions. First of all, I need to know if it's even possible to programmatically hang-up the phone from within my app (when the user presses a button, for instance). Also, is it possible to make a call from within my app, without having to leave my app? As in, the user can talk on the phone, but still see my app front and center the whole time?
Thanks
No to both questions*: it's not possible, unless you go to the dark side (jailbreak).
To know what kind of options are available to developers in regard to the phone functionality, take a look at Core Telephony's documentation.
You can pass a phone call by passing a url of the type tel://%# to [[UIApplication sharedApplication] openURL:url] but you can't "stay" in the App itself (phone.app will take care of the phone call).
When you programmatically make a phone call, your app jumps into the phone app.
You can make a phone call like this:
NSURL *url = [[[NSURL alloc] initWithString:[NSString stringWithFormat:#"tel://%#", kSavedNumber]] autorelease];
[[UIApplication sharedApplication] openURL:url]
Once you do this, the user will not be in your app, and they will be hanging up using the standard phone interface.
How can we make phone calls programmatically without using the code
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"tel://9423456789"]];
The method you've suggested is the only means of programmatically requesting that a call is placed.
If you're attempting to subvert the user's acceptance of the call, then this isn't possible using the public APIs.
So do this:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"tel://9423456789"]];
Then create a local notification that pops up in 1 seconds to bring the user back to your app.
The only way to make a call completely within your own application is to create your own VoIP-like solution. You can't make cellular phone calls within your own app.
It's completely user-controllable and, just like sending SMS and email, should stay that way. There were too many applications for Windows Mobile for example, which would send premium SMS behind user's back.
#Prasanth T R
But the my app is switching to the Phone app and it's cannot turn back
to my app after ending the call. I need the call to be made within my
app
To go back to your app, use telprompt://9423456789 instead of tel://9423456789
using "telprompt://" when a call finish the user will go back to your app
NSString *phoneDigits = #"9423456789";
NSString *phoneNumber = [NSString stringWithFormat#"telprompt://%#",phoneDigits];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:phoneNumber]]
I am going to develop a iPhone application.
In that i need to run another iPhone app when the user clicks on the button.
Is it possible to run a iPhone app from another iPhone app?
If possible, Please let me know your inputs on this.
Thanks for any help.
[copy and paste of a previous answer I gave here for the click-averse]
You can use the url scheme built into iOS. For example, you could call Safari with a url because it is registered as the application which handles the http URL scheme
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"http://www.google.com/"]]
The openURL: method is an instance method of the singleton UIApplication instance, on which you can call any application installed which registers in its plist an ability to handle some sort of input data.
Here's a list of common url schemes in iOS.
A little known way to detect the existence of another application on a device is to use canOpenURL: on the same singleton instance:
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:#"cydia://"]])
{
NSLog(#"cydia installed");
}
else
{
NSLog(#"cydia not installed");
}
Only if that other app is already installed and run and has been designed to register a custom URL handler to itself with the OS.
The your app can run it by using that custom URL scheme.
If the app has a custom URL Schema and you know what it is, then it is possible to launch another app form yours.
When user pressed the button, your current app will close and run the new app..
Yea.. Its possible.. BUT you must know the "short link" of the other app.. I tried it before and even successfully transferred data from the lite version to the full version..
Its called url scheme..
Here's a link:
http://www.idev101.com/code/Objective-C/custom_url_schemes.html
Hope it can achieve what you want..