Popping System Alert on UISwitch's 'ON' state - ios

I am new to this and this is my first question.
Would any one let me know whether we can or cannot pop a System Alert on UISwitch's 'ON' state.
I Know we can have custom alert but i don't want that.It is related to GPS whereby when the user switches on the switch it should give you an System Alert asking to on your GPS.

No, it's automatically displayed when the app accesses Core Location. If the user rejects it, it's displayed a second time at the next launch, then it keeps quiet and is not shown anymore.
So there is no way you could force this dialog to show again. iOS will ask the user again on the next start-up of the app.
Edit : If you need to show an alert for GPS you van check whether GPS is enabled or not as if userlocation is nil or not. if it is not nil then set your switch enabled else set disbled.
MKUserLocation *userLocation = mapView.userLocation;
if (!userLocation.location)
{
// Show an alert here to turn on Location service
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Location Service Disabled"
message:#"To re-enable, please go to Settings and turn on Location Service for this app."
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert show];
}
So user can enable GPS in settings directly.
Hope it helps you.

Related

how to open a uialertview just before exit app manually in ios?

I want to show this alert view just before when user exit app manually by clicking home button . I tried it by writing it in to did enter background delegate but its not showing.
Code
UIAlertView *rating = [[ UIAlertView alloc]initWithTitle:#"Rate Our App" message:#"" delegate:self cancelButtonTitle:#"cancel" otherButtonTitles:#"Never",#"Not Now",#"Later", nil];
[rating show];
That will not work. You cannot delay the app from moving to the background.
Use this method to release shared resources, invalidate timers, and store enough app state information to restore your app to its current state in case it is terminated later.
https://developer.apple.com/library/prerelease/ios/documentation/UIKit/Reference/UIApplicationDelegate_Protocol/index.html
Got it backwards. Do it the other way around, show this alert every time app launches. One cannot delay app closing or displaying interactive pop-ups when an app goes in background.
However, You can run non-interactive background tasks for 10 mins max to cleanup temp files, download something in the background etc. But those are all non-interactive user actions.
On a side note if you need a cool control that rates your app on app launch then try this SARate

Alert message not rotating in IOS8

I am building an iPhone app which shows an alert message when a particular button is tapped. Auto-rotaion is in ON state. When i rotate my phone the whole app view as well as the alert message rotates in iOS7 But, in iOS8 views are rotated except alert message`
UIAlertView does not work properly in iOS8 The, iOS8 uses a new UIAlertController The given linked worked for my case.
Reference Link
This is happening because the iOS not able to understand the multiple operation at a time .You can call the UIalertview with delay like .I have same issue with iOS8 this code is working fine for me.
[self performSelector:#selector(showAlert) withObject:nil afterDelay:0.5];
-(void)showAlert
{
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:#"Your alert Title." message:#"Your alert Message." delegate:nil cancelButtonTitle:#"Ok" otherButtonTitles:nil, nil];
[alert show];
}

Let the UIAccessibilityPostNotification complete in UIAlertView

I want to announce a message through UIAccessibilityPostNotification in a UIAlertView. My problem is that the alert view closes and the message abruptly stops (at least that is my analysis), barely two words get spoken. Is there any way to let the notification complete? My code is as follows:
//Function which calls UIAlertView
-(IBAction)foo:(id)sender
{
UIAlertView* myAlert = [[UIAlertView alloc] initWithTitle:#"Select to get more information"
message:#""
delegate:self
cancelButtonTitle:#"Cancel"
otherButtonTitles:#"a",#"b",#"c", nil];
myAlert.tag=2;
[myAlert show];
//Code comes here immediately, even if I don't select anything on alertView.
NSLog(#"Does it come here? Yes!");
}
My AlertView:
if ([alertView tag]==2)
{
//Some code
NSString* message = #"Long message";
if (UIAccessibilityIsVoiceOverRunning())
UIAccessibilityPostNotification(UIAccessibilityAnnouncementNotification, message);
else
NSLog(#"Voice-over is not running.");
}
I am also ready to change my code logic. I tried if the code continues after we select a choice on alert view, so that I can make the message variable global and post the notification through the foo function. It doesn't happen as expected. Program stops after alertView closes.
Does any workaround exist? I am an amateur iOS programmer so a little code along with the explanation would help.
P.S. I can even use something other than alert view, if there is any. I just want to have a pop-up and some buttons as choices.
IMO, you should create your on Custom popup using UIView to display options to the end user. Then first display your popup that gives user the options, once user selected one of them (or tap a button after selecting one of them), call UIAlertView to show the relevant messages.
Hope this way your problem will be solved.

How to present UIAlertView which contains Settings + Cancel button when location services are turned off in my app?

In one of my app I'm using Location Services. I'm throwing a normal alert view whenever the location services are off like "Enable Your Location Services" with "OK" button when I open my app. But I don't want this. Rather I need to show the alert view as "Turn on Location Services to Allow Your_App_Name to Determine Your Location" with "Settings" and "Cancel" button as shown in the image. Give me the suggestions with a sample code, Thanks.
You should just pop up an UIAlertView telling the user that needs to enable Location Services.
If you want to be more precise, you can always create a new View explaining the user how to enable location Services using graphical content, that makes it so much easier for the user.
You cannot open the Settings page from your app, and if you could, your app would be rejected on the app store.

How to position a UIAlertView

I've tried using this
message = [[UIAlertView alloc] initWithTitle:#"Incorrect!"
message:wrongString
delegate:self
cancelButtonTitle:#"Try Again"
otherButtonTitles:nil];
if(adjustIncorrect) {
NSLog(#"Showing adjusted");
message.transform = CGAffineTransformMakeTranslation( 0.00, 300.00);
}
[message show];
It is printing out Showing Adjusted, so I know that's not the issue. But the alert isn't moving no matter what numbers I put in. I've seen a few posts saying with the newer versions of iOs this might not work, any ideas?
Unfortunately you can't do it: "The UIAlertView class is intended to be used as-is and does not support subclassing. The view hierarchy for this class is private and must not be modified.". You should not access any private properties in UIAlertView directly as well as you should not subclass UIAlertView - this is clearly stated by Apple and is likely to lead to a rejection of your App during revision when sent for publication to the Apple Store. The same applies to UIActionSheet.
Instead you should look into implementing your own alert view to be loaded modally when needed.

Resources