1

UIAlertViewのプログラミングは少し新しいです。私が念頭に置いていたのは、アプリケーションの起動時に、デフォルトの閉じるボタンの他​​に2つのボタンを表示するポップアップを実行することでした。ボタンの1つはアプリストアへのリンクであり、もう1つはそのポップアップを永久に閉じることです。最後のボタン以外はすべて完了しました。何か助けはありますか?

ありがとう!

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

この機能を使用できます

-(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 に答える
3

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

直接の(技術的な)質問に答えるのではなく、アプリストアでアプリを評価するためのアラートを実行しているようです。より大きな問題を解決しようとします。ユーザーにレビューを求めるプロンプトを処理するには、既存のオープンソースソリューションを検討する必要があります。ユーザーにプロンプ​​トを表示するための起動/日数などの機能を制御できます。

ArashPyanの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 


}


}
于 2011-07-11T20:51:18.253 に答える
2

最初に、buttonIndex 2をテストするifステートメントをもう1つ追加します。次に、NSUserDefaultsクラスを使用してBOOLを格納する必要があると思います。次に、「いいえ」ボタンがタップされている場合は、このBOOLをNOに設定します。viewdidLoadメソッドでこのBOOLの値をテストし、BOOLがYESと表示された場合にのみアラートを表示します。

于 2011-07-11T19:54:12.290 に答える