Swift
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool { if let appearValue = UserDefaults.standard.object(forKey : "appearCount") as? Int { if appearValue + 1 == 2 { // showYourAlert } UserDefaults.standard.set(appearValue + 1, forKey: "appearCount") } else { UserDefaults.standard.set(1, forKey: "appearCount") } }
Objective-C
- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions { int appearCount = [[NSUserDefaults standardUserDefaults] objectForKey: @"appearCount"]; if (appearCount) { [[NSUserDefaults standardUserDefaults] setValue: 1 forKey: @"appearCount"]; } else { if (appearCount + 1 == 2) { // show alert } [[NSUserDefaults standardUserDefaults] setValue: appearCount + 1 forKey: @"appearCount"]; } }