how to dismiss all the alertviews opened in iOS7 - ios7

I am new to iOS.I am developing an application which contain notifications.While using the app when a notification arrives an alertView is displayed.Everything works fine but if notification arrives when another alertView is already displayed problem starts.Notification alertView is displayed above the existing alertView.When I click OK for the notification alertView UI navigates to a new view controller and there the fist alertView remains displayed.If i click on that alertView my app crashes.
Is there any way to close all the alertviews that is displayed, when I click on the notification alertView.
I got this solution
for (UIWindow* window in [UIApplication sharedApplication].windows)
{
NSArray* subviews = window.subviews;
if ([subviews count] > 0)
if ([[subviews objec`enter code here`tAtIndex:0] isKindOfClass:[UIAlertView class]])
[(UIAlertView *)[subviews objectAtIndex:0] dismissWithClickedButtonIndex:[(UIAlertView *)[subviews objectAtIndex:0] cancelButtonIndex] animated:NO];
}
But this code works for iOS6 not iOS7.
I want a corresponding code in iOS7.
Can anyone please help.Thanks in advance

UIAlertView *alert1 = [[UIAlertView alloc]initWithTitle:#"title" message:#"message" delegate:nil cancelButtonTitle:nil otherButtonTitles:nil];
[alert1 show];
[self performSelector:#selector(dismiss:) withObject:alert1 afterDelay:1.0];
-(void)dismiss:(UIAlertView*)alert
{
[alert dismissWithClickedButtonIndex:0 animated:YES];
}

Related

UIAlertView for user to download another app

I downloaded an app from app store and noticed that once I installed and opened the app, I got a UIAlertView suggesting that I download another app..
How can I achieve this? Are there any existing code that I can be directed towards?
Seems like a simple feature but I'd like to integrate it. Please see attachment
Here is my edited code, but the 'Hello' button won't link anywhere.. What am I doing wrong?
UIAlertView *message = [[UIAlertView alloc] initWithTitle:#"Hello World!"
message:#"This is your first UIAlertview message."
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:#"Hello", nil];
[message show];
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSString *title = [alertView buttonTitleAtIndex:buttonIndex];
if([title isEqualToString:#"Hello"])
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString: #"https://itunes.apple.com/gb/app/islam/id667021108?mt=8&affId=1930871&ign-mpt=uo%3D4"]];
}
}
first you have to make alertView, if you want to show the alert as first thing but this code inside (ViewDidLoad) method
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:#"your title"
message:#"your message"
delegate:self
cancelButtonTitle:#"Not now"
otherButtonTitles:#"Download now"
, nil];
[alert show];
after viewDidLoad but this method
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if (buttonIndex != [alertView cancelButtonIndex]) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"here but your application link"]];
}else{
}
}
//=================================================//
To know what's NSUserDefaults, I suggest to take a look the official doc.
And of course you can use it to fulfill your goal. You use a user default to store information about the current amount of runs in the app.
More or less like:
BOOL NotTheFirstTime = [[NSUserDefaults standardUserDefaults] boolForKey:#"NotTheFirstTime"];
if(!NotTheFirstTime){
// Show the alert view
// Then set the first run flag
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:#"NotTheFirstTime"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
if that help you please make it the best question.
It is pretty simple:
1) Set up an UIAlertView as usual with the text and the button titles you like.
2) Set up the UIAlertView's delegate and use this method to figure out which button was clicked (whether the user does or does not want to go to the App Store):
alertView:clickedButtonAtIndex:
3) If the user wants to go to the App Store, open up an App Store link:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString: #"<#This is your App Store Link#>"]];

UIActionSheet pass touches through?

I'm looking to use a UIActionSheet kind of like a contextual message box (with no action buttons at all and just a label in the bubble with an arrow pointing at something). Since there are no actions the user can take, I would like it to not require a tap to dismiss, but I can't see any way (such as a passthroughViews property) to allow this.
It's probably not designed for this, but it does happen to be handy for it.
This is some example code of how to show an UIAlertView and dismiss it automatically.
Show it:
- (void)show
{
UIAlertView* alert = [[UIAlertView alloc] initWithTitle:#"title"
delegate:self
cancelButtonTitle:nil
otherButtonTitles:nil];
alert.tag = tag;
[alert show];
}
Dismiss it:
- (void)dismiss
{
for (UIWindow* w in [UIApplication sharedApplication].windows)
for (NSObject* o in w.subviews)
if ([o isKindOfClass:[UIAlertView class]]) {
UIAlertView *alert = (UIAlertView*) o;
if (alert.tag == tag)
[alert dismissWithClickedButtonIndex:[(UIAlertView*)o cancelButtonIndex] animated:YES];
}
}
Yo can call the dismiss method after a couple of seconds:
[self performSelector:#selector(dismiss) withObject:nil afterDelay:1.0 inModes:nil];

how to hide uialertview when its enter its delegate method?

hi guys I have a method called manageui which display a waiting view for a while and when the times out it's display UIAlertView which display a message for try again
My problem is that i can't hide the UIAlertView before calling manageui called
here is my code :
-(void)mangeui
{
double Currenttime=0;
double ptime=Currenttime+5000;
NSLog(#"fire /n");
do
{
//add condition for found session
if (Currenttime<ptime)
{
NSLog(#"inside if");
[spinner setHidden:NO];
[alert setHidden:YES];
}
else
{
alert = [[UIAlertView alloc] initWithTitle:#"Oops:("
message:#"No device found \n Make sure bluetooth is activated and the devices are within range."
delegate:self
cancelButtonTitle:#"Tap to retry"
otherButtonTitles:nil];
[spinner setHidden:YES];
[alert show];
}
Currenttime+=1;
} while (Currenttime < ptime+1 &&[_matchmakingClient availableServerCount]==0);
}
the delegate for alertview is :
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
[alertView dismissWithClickedButtonIndex:1 animated:true];
[spinner setHidden:NO];
alertView.hidden=YES;
[self mangeui];
}
Try this:
[alertView dismissWithClickedButtonIndex:0 animated:YES];
Well I think you didn't understand the concept of delegates
here in docs it says alertView:clickedButtonAtIndex:
The receiver is automatically dismissed after this method is invoked.
yeah there is no need to declare separately to dismiss the alert view.The method is called whenever a button in alertview is pressed and the alertview disappears

wait_fences: failed to receive reply: 10004003 while displaying UIAlertView and home button pressed

I have searched the forums regarding this and found no information on this error. I created a simple single view application in xcode and added code to create a test alert in viewDidLoad method.
- (void)viewDidLoad
{
[super viewDidLoad];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Alert Test"
message:#"Alert Test"
delegate:self
cancelButtonTitle:#"Dismiss"
otherButtonTitles:nil];
[alert show];
// Do any additional setup after loading the view, typically from a nib.
}
I have not added any other code. When I run this on my iphone 4 it runs without any problem. But when I click the home button of my iphone 4 with the alert displayed I get the mentioned error.
Device: iphone 4
OS: iOS 5.1.1
Please help. Thanks in advance
you should not display the alertView in viewDidLoad, [UIAlertView show] displays the alertView using animation. we should avoid animation performance when we are not in screen/view , display the alertView in viewDidAppear instead.
EDIT:
-(void)viewDidLoad
{
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(dismiss) name:#"UIApplicationWillResignActiveNotification" object:nil];
}
-(void)viewDidAppear:(BOOL)animated{
[super viewDidAppear:animated];
alert = [[UIAlertView alloc]initWithTitle:#"test" message:#"test" delegate:nil cancelButtonTitle:#"ok" otherButtonTitles:nil, nil];
[alert show];
}
//do not forget to add this in your header
-(void)dismiss{
[alert dismissWithClickedButtonIndex:-1 animated:NO];
}

UIAlertView with Button linking alternate ViewController

I needed a button that causes a UIAlertView with actions to pop up.
Once the Alert pops up it needs to have 1 button to cancel and stay on the same page and 1 button that links you to another ViewController.
This is what I pieced together from some forums but I have no idea what I'm doing and it gives me about 9 error messages. Please Help!
-(IBAction)Alert:(id)sender {
UIAlertView *Alert = [[UIAlertView alloc] initWithTitle:#"Alert"
message:#"Warning! By entering the Tutorial, all data will be lost. Are you sure you want to continue?"
delegate:self
cancelButtonTitle:#"Return to Data Collection"
otherButtonTitles:#"Continue", nil];
[Alert Show];
[Alert Release];
}
- (void)Alert:(UIAlertView *)Alert clickedButtonAtIndex:(NSInteger)buttonIndex
{
if(Alert.tag==0) {
if(buttonIndex == 1)//OK button pressed
{
Tutorial *Info = [[Tutorial alloc] initWithNibName:nil bundle:nil];
[self presentModalViewController:Info animated:YES];
}
The first box of code works so that when I press a button on my home screen an alert with 2 buttons pops up.
However, I can't get the second button to link me to the next ViewController.
Objective-C is case-sensitive.
[Alert show];
[Alert release];
and
- (void)alertView:(UIAlertView *)Alert clickedButtonAtIndex:(NSInteger)buttonIndex
(How do you think, it can work, if you rename the methods???)
remove if(Alert.tag==0) {
Why are you not passing a name for a nib-file here: Tutorial *Info = [[Tutorial alloc] initWithNibName:nil bundle:nil];
Please stick to coding conventions. objects are named in camelCase.
Conclusion
get you a good book or videos to learn from the beginning. Some resources to do so.