iOS CLLocationManager Turn On Location Services - ios

In my app, if location services is turned off, it prompts the user: Turn On Location Services to Allow "MyAPP" to Determine Your Location.
The two option buttons are Settings and Cancel.
How do I handle when the user presses cancel?
Is there any delgate method to handle the cancel button press ?

Maybe this might work for what you want.
First, conform to the UIAlertViewDelegate protocol in your header file.
Then there's a delegate method you can implement.
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
// if the alert view that appeared has titled "Location Denied" and user pressed on cancel button (cancel button is button at index 0)
if(alertView.title isEqualToString:#"Location Denied"] && buttonIndex == 0)
{
// do something
}
}

// through Button name in UIAlertview you can access which Button you are pressed*
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSString *title = [alertView buttonTitleAtIndex:buttonIndex];
if([title isEqualToString:#"cancel"])
{
}
}

Related

How to dismiss UIAlertView in both iOS 7 & iOS 6?

How to dismiss uialertview(default) when click on out side. Here I have set the uialert with only one button (OK). Intend for implement this alert, if user seen free offer pack from this uialertview and he want to access his free pack offer by clicking the OK button in uialertview. Otherwise if he doesn't want to access his free offer pack at this time the user can tap the outside of uialert view and the alertview dismissed it.
Kindly give suggestion for how dismiss uialertview from out side clicking.
offeredAlert = [[UIAlertView alloc] initWithTitle:nil
message:strMessage
delegate:self
cancelButtonTitle:#"Ok"
otherButtonTitles:nil,nil];
[offeredAlert setTag:10002];
[offeredAlert show];
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSString *tempStr;
if(alertView.tag == 10001)
{
if(buttonIndex == 1)
{
tempStr = #"payable";
[self dietPackPurchaseAPI:id_Pack type:tempStr];
}
}
}

How to respond to UIImagePickerController Generated UIAlertView

I am using UIImagePickerController to capture video from my app and i have set video maximum duration to 30 seconds. When that 30 seconds limit is reached. I get an alert with a message "maximum video recording limit reached" produced by UIImagePickerController and it stops capturing video.
What I want is that I want to respond to that alert that is generated automatically when 30 seconds limit is reached. I want to perform some action when "OK" button of that alert is pressed. I have implemented all the delegate methods of UIAlertView but it does come in any method when I press OK button.
Please help me how I can respond to that alert?
You can't use all those delegate methods because you didn't initiate the UIAlertView so you can't set his delegate...
The only thing I can think about is to do somethong like listening to the UIWindowDidBecomeVisibleNotification to detect when an alert is shown and to the UIWindowDidBecomeHiddenNotification notification to detect when it disappears.
You should know that those notification will fire for all kind of components that uses their own UIWindow such as UIActionSheet or the keyboard, so you need to make sure this is the right one (maybe check to see if there is a UIAlertView in one of the subviews..)
Set yourself as a delegate of your UIImagePickerController, and implement the UIImagePickerControllerDelegate protocol. Specifically, the following method:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)
Use UIAlertViewDelegateProtocol
Form docs
alertView:clickedButtonAtIndex:
Sent to the delegate when the user
clicks a button on an alert view.
(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex Parameters alertView The
alert view containing the button. buttonIndex The index of the button
that was clicked. The button indices start at 0. Discussion The
receiver is automatically dismissed after this method is invoked.
Availability Available in iOS 2.0 and later. Declared In UIAlertView.h
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex == 0)
{
// do stuff for button index 0,ie cancel button and sthe same for other button indeces
}
}
Please refer this tutorials : http://mobile.tutsplus.com/tutorials/iphone/uialertview/ you can get more ideal about this :
UIAlertView *message = [[UIAlertView alloc] initWithTitle:#"Hello World!"
message:#"This is your first UIAlertview message."
delegate:self
cancelButtonTitle:#"Button 1"
otherButtonTitles:#"Button 2", #"Button 3", nil];
[message show];
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSString *title = [alertView buttonTitleAtIndex:buttonIndex];
if([title isEqualToString:#"Button 1"])
{
NSLog(#"Button 1 was selected.");
}
else if([title isEqualToString:#"Button 2"])
{
NSLog(#"Button 2 was selected.");
}
else if([title isEqualToString:#"Button 3"])
{
NSLog(#"Button 3 was selected.");
}
}

Show fullscreen Flurry ad after a click in an AlertView

I've got a problem,
I added Flurry SDK in my iOS app and want to show a full screen add each time when the user click in the "Ok" button of an uiAlertView. The problem is that it doesn't work.
So, I tried try to do it without the AlertView and it works perfectly.
Someone knows why it doesn't work after clicking on an AlertView.
// The call of the alertview
UIAlertView *myAlert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(#"TitlePopupNewGame", nil) message:nil delegate:self cancelButtonTitle:NSLocalizedString(#"CancelPopupNewGame", nil) otherButtonTitles:NSLocalizedString(#"YesPopupNewGame", nil), nil];
myAlert.tag = 1;
myAlert.delegate = self;
[myAlert show];
// Alertview method
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if (alertView.tag == 1 && buttonIndex == 0){
[self showInterstitial];
}
}
// ShowInterstitial method
-(void) showInterstitial{
if ([FlurryAds adReadyForSpace: #"Full screen banner"]) {
[FlurryAds displayAdForSpace: #"Full screen banner"
onView:mv];
[FlurryAds fetchAdForSpace:#"Full screen banner"
frame:mv.frame size:FULLSCREEN];
} else {
// fetch an ad
[FlurryAds fetchAdForSpace:#"Full screen banner"
frame:mv.frame size:FULLSCREEN];
}
}
Thanks

ios - I have a 2-button UIAlertView, how do I know which button is pressed? [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 10 years ago.
I have this 2-button alert view:
UIAlertView* message = [[UIAlertView alloc]
initWithTitle: #"Delete?" message: #"This business will be deleted permenently." delegate: nil
cancelButtonTitle: #"Cancel" otherButtonTitles: #"Delete", nil];
[message show];
I also have this method:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSString *title = [alertView buttonTitleAtIndex:buttonIndex];
if([title isEqualToString:#"Delete"])
{
NSLog(#"Button DELETE was selected.");
}
else if([title isEqualToString:#"Cancel"])
{
NSLog(#"Button CANCEL was selected.");
}
}
and I added this to the .h file:
<UIAlertViewDelegate>
Right now when either button is pressed, it just closes the dialog. That is ok for cancel, but how do I know when the delete button is pressed?
Thanks!
You have to implement the – alertView:clickedButtonAtIndex: method of the UIAlertViewDelegate. You also have to set the delegate when initialising the alert view.
E.g.
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex == 0) {
//Do something
} else if (buttonIndex == 1) {
//Do something else
}
}
The cancel button's index is 0.
You are passing nil to the delegate parameter when you create the alert view. You need to pass self instead. As you have it now, the clickedButtonAtIndex: method is never called.
UIAlertView* message = [[UIAlertView alloc]
initWithTitle: #"Delete?"
message: #"This business will be deleted permenently."
delegate: self
cancelButtonTitle: #"Cancel"
otherButtonTitles: #"Delete", nil];
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex == alertView.cancelButtonIndex) {
// Cancel was tapped
} else if (buttonIndex == alertView.firstOtherButtonIndex) {
// The other button was tapped
}
}
message.delegate = self;
...
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
NSLog(#"Button %d was clicked", buttonIndex);
}
and the class must be declared to meet the UIAlertViewDelegate protocol.

UIActionSheet dismisses on 2nd click of the button

I have an actionSheet with EDIT and DELETE buttons, both being other buttons This is the Code i have written for it
-(void)method1
{
action = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:#"Edit", #"Delete", nil];
action.actionSheetStyle = UIActionSheetStyleBlackTranslucent;
[action showInView:self.view];
[action release];
}
I have used the deleate method to assign actions to method..
-(void)actionSheet:(UIActionSheet *)action didDismissWithButtonIndex:(NSInteger)buttonIndex
{
if(buttonIndex == 0)
{
// do something
}
if(buttonIndex == 1)
{
// do something
}
}
now the problem is that the actionsheet does not dismiss at one click of either of the buttons.. Please help me with some solution.
This appears to be a bug in iOS4.0. I had this issue in my simulator. I changed the version to 4.3 and 5.0 and it seemed ok.
Edit:
Seems that my issue was more specifically to do with the actionsheet being launched twice by a delegate method "-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField"
Not sure why this is called twice in this case but not others (again I assume a iOS 4.0 bug that's been fixed in later releases). My workaround is to keep track if it's been called already and not call it a second time.
Edit 2
I would suggest doing something like:
-(void)method1
{
if(hasLaunchedActionSheet)
{
return;
}
hasLaunchedActionSheet = YES;
...
and:
-(void)actionSheet:(UIActionSheet *)action didDismissWithButtonIndex:(NSInteger)buttonIndex
{
hasLaunchedActionSheet = NO;
...
For me, the issue's not so much in Xcode as it is in the iOS SDK itself calling my event twice. I'm not sure how you're calling method1 so it might be a different issue with a different event.
You are using wrong delegate methods, for button interaction, you should use:
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
instead of:
-(void)actionSheet:(UIActionSheet *)action didDismissWithButtonIndex:(NSInteger)buttonIndex

Resources