单击按钮后弹出警报将永远消失

发布于 2024-11-19 06:58:35 字数 714 浏览 1 评论 0原文

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

}


}

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

}


}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

全部不再 2024-11-26 06:58:35

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

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

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

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

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

如果您在这里寻求问题的技术解决方案(即在启动时提示并使用永久关闭按钮),以下是您应该执行的操作的概述:

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


}


}
怎樣才叫好 2024-11-26 06:58:35

你会想要使用类似 NSUserDefaults 的东西,也许像这样:

- (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'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"];
    }
}
风吹短裙飘 2024-11-26 06:58:35

你可以使用这个功能

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

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

you can use this function

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

-(void)dismissAlertView:(UIAlertView *)alertView{
    [alertView dismissWithClickedButtonIndex:0 animated:YES];
}
街角卖回忆 2024-11-26 06:58:35

首先,添加另一个if语句测试buttonIndex 2。然后,我相信您会想要使用NSUserDefaults类来存储BOOL。然后,如果点击“不,谢谢”按钮,则将此 BOOL 设置为 NO。在 viewdidLoad 方法中测试此 BOOL 的值,仅当 BOOL 为 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文