我的应用每3次显示一次,便需要显示一个弹出窗口。
我也在使用Appirater
对我的应用程序进行评分,如果我在其中附加代码以完成任务,那可以吗?
还是有其他方法可以确认我的应用程序每3次启动一次?
最佳答案
您可以在此处存储NSUserDefault中的应用启动计数,并且可以每隔三次启动应用显示警报。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
if(![[[NSUserDefaults standardUserDefaults] valueForKey:@"firstTime"] isEqualToString:@"Yes"])
{
[[NSUserDefaults standardUserDefaults] setValue:@"Yes" forKey:@"firstTime"];
[[NSUserDefaults standardUserDefaults] setInteger:([[NSUserDefaults standardUserDefaults] integerForKey:@"ApplaunchCount"] + 1) forKey:@"ApplaunchCount"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
else
{
[[NSUserDefaults standardUserDefaults] setInteger:([[NSUserDefaults standardUserDefaults] integerForKey:@"ApplaunchCount"] + 1) forKey:@"ApplaunchCount"];
[[NSUserDefaults standardUserDefaults] synchronize];
if([[NSUserDefaults standardUserDefaults] integerForKey:@"ApplaunchCount"] % 3 ==0)
{
UIAlertView *lanuchAlert = [[UIAlertView alloc] initWithTitle:@"Your Message Title" message:@"Your Message Text" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK", nil];
[lanuchAlert show];
[lanuchAlert release];
}
}
// Add the tab bar controller's current view as a subview of the window
[self.window addSubview:navigationController.view];
[self.window makeKeyAndVisible];
return YES;
}
让我知道您是否需要更多帮助。
关于iphone - 如何在应用每启动三次后显示弹出窗口?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6798380/