-4

ジョンが私のアプリを 3 ~ 6 分間使用していたとします。次に、私の場合は広告を含むビューをポップアップ表示したいと思います。

このようなもの、

 AdViewController *adViewController = [[AdViewController alloc] init];
 [self presentViewController:adViewController animated:YES completion:nil];

しかし、ランダムな時間の後にポップアップさせるにはどうすればよいですか? デリゲート ファイルを操作し、arc4random 関数を使用する必要があると思います。

ジョンが広告を見た後、彼はそれを閉じる必要がありますが、それは問題ではありません..

誰かが私にコード例を教えてもらえますか?

4

1 に答える 1

1

簡単な解決策は、

  • NSTimer を作成し、300 秒 (5 分) ごとに起動させます。
  • NSTimer は、ポップアップを表示するアクションを起動します。

よくわからないけど、なんでこんなにわかりにくかったの?

//use arc4random() if you need random time


NSTimer *timer2 = [NSTimer scheduledTimerWithTimeInterval:300.0 target:self selector:@selector(rateThisApp) userInfo:nil repeats:YES];

// *********
// ********* RATE APP ***********
// *********
- (IBAction)rateThisApp
{
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Rate this App"
                                                                message:@"Are you enjoying this app? Please leave a rating at the app store and tell us what you think of this app and its features. We would love to hear from you!"
                                                               delegate:self cancelButtonTitle:@"Not Now"
                                                      otherButtonTitles:@"Rate Now", nil];
        [alert show];
        alert.tag = 400;

}


-(void)alertView:(UIAlertView *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (actionSheet.tag == 400)
    {
        if (buttonIndex == 0)
        {
            //dont do anything, user hit cancel
        }
        else if (buttonIndex == 1)
        {
            [[UIApplication sharedApplication]
             openURL:[NSURL URLWithString:@"itms-apps://ax.itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?type=Purple+Software&id=1234567"]];
        }
    }

}
于 2013-11-22T14:34:09.130 に答える