abha abha - 3 months ago 12
iOS Question

How to stop AlertView from showing up by adding "Don't show again" button?

I have an application with an alertview that shows up when the application launches to explain about the app function.
On my alertView I want to make "Don't show again" button, so the user doesn't have to see the same alert every time he/she uses my app.
So how can I stop the alertView from showing up after the user selects this button. Should I work on the appDelegate or should I work on the viewcontroller where my alertview will pop up?

Answer

I would store a value in NSDefault for this, as we cannot change this on UIAlertView.

So once the UIAlertView has shown, set this value to something that represents "read", retrieve it in one of the App Delegate methods such as applicationDidBecomeActive and use it as a condition in a if statement for displaying the UIAlertView.

Let say you had an NSInteger = 0, which signifies "unread", once the UIAlertView is shown, set it to 1 and store it in NSDefault.

if(alertHasBeenRead == 0)
{
   //bring up alert view
}

And subsequently in one of the delegate callback, set this value to something else other than 0, for example.

Hope this helps.

Comments