1

我对 UIAlertView 的编程有点陌生。我想到的是做一个弹出窗口,在应用程序启动时显示除了默认的关闭按钮之外还有两个按钮。其中一个按钮是指向应用商店的链接,另一个按钮是永远关闭该弹出窗口。除了最后一个按钮,我已经完成了所有操作。有什么帮助吗?

谢谢你!

- (void)viewDidLoad {

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#" ]];

}


}
4

4 回答 4

3

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"];
    }
}
于 2011-07-11T20:32:53.323 回答
3

您似乎正在提醒您在应用商店中评价您的应用,而不是回答您的直接(技术)问题,我将尝试解决更大的问题。您应该考虑使用现有的开源解决方案来处理提示用户进行评论,您可以控制诸如多少次启动/天后提示他们的功能。

我可以推荐Arash Pyan 的 Appirater。它的作用是自动处理应用程序的评分部分。它将用户直接带到您的应用程序的评论页面,并且它非常可定制。新开发人员的最佳解决方案!它在 GitHub 上可用。

demosthenese 的iRate是一个类似的解决方案,但更清洁并支持快速的应用程序切换。

改用这些“现成的”解决方案!它应该工作得更好,而不是自己处理!它们包括有关如何自定义功能的文档和示例。

顺便说一句,我认为 Apple 不建议使用 AlertViews 来让用户对应用程序进行评分。负责任地使用提到的工具。不要太快地提示用户,并确保您包含一个永久关闭按钮!

如果您在这里寻求问题的技术解决方案(即在 Prompt on launch 中使用永久关闭按钮),以下是您应该做什么的概述:

-(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 


}


}
于 2011-07-11T20:51:18.253 回答
3

你可以使用这个功能

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

-(void)dismissAlertView:(UIAlertView *)alertView{
    [alertView dismissWithClickedButtonIndex:0 animated:YES];
}
于 2011-07-11T20:20:23.617 回答
2

首先,添加另一个 if 语句测试 buttonIndex 2。然后,我相信您会想要使用 NSUserDefaults 类来存储 BOOL。然后,如果点击“不,谢谢”按钮,则将此 BOOL 设置为 NO。在您的 viewdidLoad 方法中测试此 BOOL 的值,并仅在 BOOL 读取为 YES 时显示警报。

于 2011-07-11T19:54:12.290 回答