User97693321
User97693321

Reputation: 3346

alert once on launch of iPhone/iPad application

I want to popup an alert with "OK" and "Cancel" button. This alert should appear only once on first launch of iPhone/iPad application and for the alert if OK button is pressed then next launch of application the alert should not appear. If Cancel button is pressed then on the next launches of the application same alert should appear.

My approach is to take any integer variable for which default value should be 0, when first time the application is launched this integer value should be checked if it is 0 only the alert should appear either no alert. If alert appears and the OK button is pressed, value should be changed to 1 and on the next launch of the application this integer value should be retained 1 so that the alert should not appear again.

Please help what should be the type of this variable and how to retain the value on next launch of the application.

Upvotes: 2

Views: 1675

Answers (1)

Adrian Smith
Adrian Smith

Reputation: 17553

To persist the value, use NSUserDefaults with the methods setBool:forKey: (to save the value) and boolForKey: (to read the previously-saved value). The first time you call boolForKey: you will get the boolean value of NO.

See here for the official Apple documentation.

Upvotes: 6

Related Questions