开发者

Popup alert dismiss forever after button clicked

开发者 https://www.devze.com 2023-03-19 17:24 出处:网络
I\'m kinda new on programming UIAlertView\'s. What i had in mind was to do a Popup that shows on launch of the application with two more buttons besides the default dismiss button.

I'm kinda new on programming UIAlertView's. What i had in mind was to do a Popup that shows on launch of the application with two more buttons besides the default dismiss button. One of the buttons would be a link to the appstore and the other would be to dismiss that popup forever. I've already done everything besides the last button. Any help?

Thank You!

- (void)viewDidLoad {

alert = [[UIAlertView alloc] initWithTitle:@"Rate!" message:@"Your rate is much apreciated" deleg开发者_如何学JAVAate:self cancelButtonTitle:@"Not Now" otherButtonTitles:@"Okay!   ", @"No, Thanks!", nil ];
[alert show];
[alert release];
 }



-(void)alertView:(UIAlertView *) alertView clickedButtonAtIndex:(NSInteger)buttonIndex{

if (buttonIndex == 0) {

}

if (buttonIndex == 1) {

     [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://itunes.apple.com/pt/app/designertools/id444778173?mt=8#" ]];

}


}


You seem to be doing an alert to rate your app in the app store, instead of answering your direct (technical) question, I'll try to solve the larger issue. You should consider an existing Open Source solution to handle prompting users for reviews, you can control features like how many launches/days later to prompt them.

I can recommend Appirater by Arash Pyan. What it does is handle the rating portion of the app automatically. It take users right into your App's review page and its very customizable. The best solution for a new developer! It's available on GitHub.

iRate by demosthenese is a similar solution but is cleaner and supports fast app switching.

Use these "off the shelf" solutions instead! It should work out better rather than handle it yourself! They include documentation and samples on how to customize the features.

As an aside, I think Apple doesn't recommend using AlertViews for getting users to rate applications. Use the tools mentioned responsibly. Don't prompt users too quickly, and make sure that you include a dismiss forever button!

If you're here for a technical solution to the issue (ie on Prompt on launch with a dismiss forever button), here's an overview of what you should do:

-(void)viewdidload{

//Access NSUSerDefaults and check a variable called launch
// launch's default value is 0
if (launch == 0) {

    alert = [[UIAlertView alloc] initWithTitle:@"Rate!" message:@"You'll see this everytime you launch until you click Dismiss Forever" delegate:self cancelButtonTitle:@"Not Now" otherButtonTitles:@"Okay!   ", @"Dismiss Alert and Don't Show it to me", nil ];
[alert show];
[alert release];
 }

} 
else
{
//nothing
}
//continue customizing
}

-(void)alertView:(UIAlertView *) alertView clickedButtonAtIndex:(NSInteger)buttonIndex{

if (buttonIndex == 0) 
//Assume this is the Okay Button
 {

//Now use NSUserDefaults and set a variable called launch to 1 
// the default value for launch should be 0
// now that its set to 1
     [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"ILoveAlertViews.com" ]];


}

if (buttonIndex == 1) {
//assume this is the dismiss button
//Now use NSUserDefaults and set a variable called launch to 2
//2 means that they never want to see it. The AlertView should not be called on the next launch 


}


}


You'll want to use something like the NSUserDefaults, maybe like this:

- (void)viewDidLoad
{
    if(![[NSUserDefaults standardUserDefaults] boolForKey:@"com.mycompany.myapp.block_rate_reminder"])// this could be any string as long as it's descriptive enough for you (and match what you use to set, of course)
    {
        alert = [[UIAlertView alloc] initWithTitle:@"Rate!" message:@"Your rate is much apreciated" delegate:self cancelButtonTitle:@"Not Now" otherButtonTitles:@"Okay!   ", @"No, Thanks!", nil ];
        [alert show];
        [alert release];
    }
}



-(void)alertView:(UIAlertView *) alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{

    if (buttonIndex == 0) {

    }

    if (buttonIndex == 1) {

        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://itunes.apple.com/pt/app/designertools/id444778173?mt=8#" ]];

    }

    if (buttonIndex == 2)
    {
        [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"com.mycompany.myapp.block_rate_reminder"];
    }
}


you can use this function

-(void)dismiss{
     [self performSelector:@selector(dismissAlertView:)withObject:alertView afterDelay:2];
}

-(void)dismissAlertView:(UIAlertView *)alertView{
    [alertView dismissWithClickedButtonIndex:0 animated:YES];
}


First, add another if statement testing buttonIndex 2. Then, I believe you're going to want to use the NSUserDefaults class to store a BOOL. Then, set this BOOL to NO, if the "No thanks" button is tapped. Test for the value of this BOOL in your viewdidLoad method and display the alert only if the BOOL reads YES.

0

精彩评论

暂无评论...
验证码 换一张
取 消