iOS UIAlertView button to go to Setting App - ios

Is there a way to have the button of a UIAlertView go to the Settings App for the specific App calling it?
Thanks

For example:
NSURL*url=[NSURL URLWithString:#"prefs:root=WIFI"];
[[UIApplication sharedApplication] openURL:url];
And
[font=]
About — prefs:root=General&path=About
Accessibility — prefs:root=General&path=ACCESSIBILITY
Airplane Mode On — prefs:root=AIRPLANE_MODE
Auto-Lock — prefs:root=General&path=AUTOLOCK
Brightness — prefs:root=Brightness
Bluetooth — prefs:root=General&path=Bluetooth
Date & Time — prefs:root=General&path=DATE_AND_TIME
FaceTime — prefs:root=FACETIME
General — prefs:root=General
Keyboard — prefs:root=General&path=Keyboard
iCloud — prefs:root=CASTLE
iCloud Storage & Backup — prefs:root=CASTLE&path=STORAGE_AND_BACKUP
International — prefs:root=General&path=INTERNATIONAL
Location Services — prefs:root=LOCATION_SERVICES
Music — prefs:root=MUSIC
Music Equalizer — prefs:root=MUSIC&path=EQ
Music Volume Limit — prefs:root=MUSIC&path=VolumeLimit
Network — prefs:root=General&path=Network
Nike + iPod — prefs:root=NIKE_PLUS_IPOD
Notes — prefs:root=NOTES
Notification — prefs:root=NOTIFICATIONS_ID
Phone — prefs:root=Phone
Photos — prefs:root=Photos
Profile — prefs:root=General&path=ManagedConfigurationList
Reset — prefs:root=General&path=Reset
Safari — prefs:root=Safari
Siri — prefs:root=General&path=Assistant
Sounds — prefs:root=Sounds
Software Update — prefs:root=General&path=SOFTWARE_UPDATE_LINK
Store — prefs:root=STORE
Twitter — prefs:root=TWITTER
Usage — prefs:root=General&path=USAGE
VPN — prefs:root=General&path=Network/VPN
Wallpaper — prefs:root=Wallpaper
Wi-Fi — prefs:root=WIFI`
prefs:root=INTERNET_TETHERING

Opening settings apps programmatically is possible only from iOS 8. So, use the following code...
if([CLLocationManager locationServicesEnabled]&&
[CLLocationManager authorizationStatus] != kCLAuthorizationStatusDenied)
{
//...Location service is enabled
}
else
{
if([[[UIDevice currentDevice] systemVersion] floatValue]<8.0)
{
UIAlertView* curr1=[[UIAlertView alloc] initWithTitle:#"This app does not have access to Location service" message:#"You can enable access in Settings->Privacy->Location->Location Services" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil, nil];
[curr1 show];
}
else
{
UIAlertView* curr2=[[UIAlertView alloc] initWithTitle:#"This app does not have access to Location service" message:#"You can enable access in Settings->Privacy->Location->Location Services" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:#"Settings", nil];
curr2.tag=121;
[curr2 show];
}
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSLog(#"buttonIndex:%d",buttonIndex);
if (alertView.tag == 121 && buttonIndex == 1)
{
//code for opening settings app in iOS 8
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
}
}

Apparently, this does not work in iOS 5.1 whatsoever. I have been fighting it all morning, and then ran across this blog
http://www.alexcurylo.com/blog/2011/11/04/settings-urls/

In ios5 and above...
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"prefs:root=General"]];

It works on iOS8+ also,but we need to change something
NSURL*url=[NSURL URLWithString:#"prefs:root=WIFI"];
if([[UIApplication sharedApplication] canOpenURL:url]){
[[UIApplication sharedApplication] openURL:url];
}

Related

How can I track iPhone usage like the 'Moment' app does?

How to track total usage of iPhone, even if our app is running in background(not forcefully terminated). Recently i have come across app, namely
Moment this app does track your iPhone usages, even if this app is running in background. actually they are using location service to get execution time. my question is when they get execution time, how they can be sure if user's iPhone screen lock or unlock ?
i have code to check if screen is lock or unlock
-(void)registerAppforDetectLockState {
int notify_token;
notify_register_dispatch("com.apple.springboard.lockstate", &notify_token,dispatch_get_main_queue(), ^(int token) {
uint64_t state = UINT64_MAX;
notify_get_state(token, &state);
if(state == 0) {
NSLog(#"unlock device");
UIAlertView *errorAlert = [[UIAlertView alloc]
initWithTitle:#"unlock device" message:#"test" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[errorAlert show];
} else {
NSLog(#"lock device");
UIAlertView *errorAlert = [[UIAlertView alloc]
initWithTitle:#"lock device" message:#"test" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[errorAlert show];
}
});
}
but this code is working only when app is running in foreground.
Your code is working only when app is running in foreground because when app goes in to background it is not called you have to use one of the background mode to wakeup your application can execute your code .

Prevent Phone Screen Popping Up

I have an app I'm working on that when a button is pressed will call a number on the iPhone. That said, I want to prevent the phone screen from popping up and instead keep the app open as is. Here's my code so far. I have no idea if this is even possible. Any help would be great.
NSString *phNo = #"+919876543210";
NSURL *phoneUrl = [NSURL URLWithString:[NSString stringWithFormat:#"telprompt:%#",phNo]];
if ([[UIApplication sharedApplication] canOpenURL:phoneUrl]) {
[[UIApplication sharedApplication] openURL:phoneUrl];
} else
{
calert = [[UIAlertView alloc]initWithTitle:#"Alert" message:#"Call facility is not available!!!" delegate:nil cancelButtonTitle:#"ok" otherButtonTitles:nil, nil];
[calert show];
}
All calls made through traditional phone numbers can only use the iPhone's phone app.
As has been suggested, if you create your own VOIP service or use an existing one, you'll be able to process this call in-app as a data call.

Local notifications on gps services off

I am using location services on background in my app for fetching user location.
I want to get local notifications from my application when the user switches off the location services in settings page.
Thanks in advance!!!!
Try This :
It's called every time user disable/enable location services in settings
- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status;
Why you want to use local notification? Why not UIAlertView?
I would like to suggest you to use UIAlertView as it will inform the user what to do when he/she opens the app. For local notification, you can schedule it. Most likely, the user will not see the notification when the user is on the foreground of the app (when open). And you are not able to know if the app has the right to use location or not if the user never opens the app.
By using didFailWithError delegate method from locationManager, you will be able to know if the user allows your app to get the location or not.
You will have to implement the locationManager delegate method like below:-
- (void)locationManager: (CLLocationManager *)manager didFailWithError: (NSError *)error
{
switch([error code])
{
case kCLErrorNetwork: // general, network-related error
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"" message:#"Network Error" delegate:nil cancelButtonTitle:#"Ok" otherButtonTitles:nil, nil];
[alert show];
}
break;
case kCLErrorDenied:{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"" message:#"YOUR APP NAME doesn't work without Location Services enabled. To turn it on, go to Settings > Privacy > Location Services" delegate:nil cancelButtonTitle:#"Ok" otherButtonTitles:nil, nil];
[alert show];
}
break;
default:
{
}
break;
}
}
If you insist want to implement local notification, replace the above UIAlertView with local notification code.

Can't present Settings Alert iOS6 +

Is there a way to present a alert like the alert presented by twitter SDK if no account is signed-in.
I want to display that type of alert if user has disabled Settings->Notification Center for my app.
Just want to present the alert, mentioned twitter as ref. Its not about twitter.
NOTE: I don't want to display / use social media, its for reference, question is can we display a custom alert which can navigate the user to settings app of iOS.
There is no way to know the status of the switch in Notification Center > Your app. The only thing you can access is what type of notifications he will get ([[UIApplication sharedApplication] enabledRemoteNotificationTypes];).
You can know notification setting of your app and can show alert when it is disable as below
UIRemoteNotificationType types = [[UIApplication sharedApplication] enabledRemoteNotificationTypes];
if (!(types & UIRemoteNotificationTypeAlert)) {
UIAlertView *al = [[UIAlertView alloc] initWithTitle:#"TITLE" message:#"YOUR MESSAGE" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:#"Settings",nil];
[al show];
[al release];
}
For more reference, you may check Determine on iPhone if user has enabled push notifications
The only settings you can access are your app's settings, which can be within your app or in Settings app. Your app's settings are the ones you set/get with [NSUserDefaults standardUserDefaults]. However for your case you could schedule a notification which fires after one second, and see if you get called from - (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification. Here is an example code.
-(void) createLocalNofication{
UILocalNotification *local = [[UILocalNotification alloc] init];
local.fireDate = [NSDate dateWithTimeIntervalSinceNow:1.0f];
local.alertBody = #"Some Alert Body";
local.timeZone = [NSTimeZone defaultTimeZone];
[[UIApplication sharedApplication] scheduleLocalNotification:local];
}
- (void)application:(UIApplication *)application didReceiveLocalNotification: (UILocalNotification *)notification {
//Here you can set some flag
}
To gain more insight on the topic, you can check out this apple documentation link.

How can I tell if my device doesn't see beacons?

I'm creating an iOS 7 app that will react to nearby beacons. However, I need to consider users that have an iPhone 4 or any other device that will not detect beacons. How can I tell if the device my app is running on supports beacons?
you can use CBCentral manager state. If it is CBCentralManagerStateUnsupported it doesn't support BLE.
If you want to monitor or range for beacons you might want to check if monitoring is available via CoreLocation Framework - Here is the way to do it :
if (![CLLocationManager isMonitoringAvailableForClass:[CLBeaconRegion class]]) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Monitoring not available" message:nil delegate:nil cancelButtonTitle:#"Ok" otherButtonTitles: nil];
[alert show];
return;
}
else{
//Monitoring is available
}

Resources