iphone - 如何在应用每启动三次后显示弹出窗口?

标签 iphone objective-c ios cocoa-touch ios4

我的应用每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/

相关文章:

objective-c - 在要求非常高的应用程序上强制更新 UI

ios - IOS 示例中的自定义 UUID 对 BLE 意味着什么?

ios - 合并两个 NSRegularExpression

javascript - 在钛移动应用程序中单击 TableViewSection 时无法查看 Tableviewrow

iphone - 如何在两个iOS设备之间有效传输实时视频(如facetime、skype、fring、tango)

iphone - 旋转图像上下文 (CGContextRotateCTM) 使其变为空白。为什么?

ios - Xcode Playground 运行时间太长

ios - Nodejs Socket.io 适用于桌面 safari 和 chrome,但不适用于 iPhone

objective-c - 推送 View 和 viewWillAppear 之间的顺序是什么?

iOS 停止全局队列运行