Alert View

Discussion in 'iOS Development' started by Rockstarou812, Apr 20, 2009.

  1. Rockstarou812

    Rockstarou812 New Member

    Joined:
    Jan 17, 2009
    Messages:
    43
    Likes Received:
    0
    Okay, I am trying to get an Alert View to pop up the first time you open the app, and the first time after downloading an update.

    UIAlertView *alert = [[UIAlertView alloc]
    initWithTitle

    Please Register or Log in to view images

    "Welcome to my app!"
    message:msg
    delegate:nil
    cancelButtonTitle

    Please Register or Log in to view images

    "Welcome"
    otherButtonTitles:nil];

    I roughly made that up. Now how do I place that in my code to make it come up on start-up, rather than triggered by a button. And how do I get it to only display the first time?


    Thank You in advance, and please don't leave any details out, I am new and really want to understand this.
  2. SkylarEC

    SkylarEC Super Moderator Emeritus Staff Member

    Joined:
    Sep 19, 2007
    Messages:
    6,642
    Likes Received:
    129
    applicationdidfinishLaunching...

    if (![[NSUserDefaults standardUserDefaults] boolForKey

    Please Register or Log in to view images

    "FirstRun"])
    [self your alert code];
  3. Steaps

    Steaps New Member

    Joined:
    Oct 24, 2007
    Messages:
    5,074
    Likes Received:
    41
    Device:
    iPod touch
    Would you still have to create a variable and save it to know that the application has been opened before? Or is this an automatic variable that is saved after the first run?

    (I'm thinking the first one, but that would be awesome if there was a predefined one for this)
  4. Rockstarou812

    Rockstarou812 New Member

    Joined:
    Jan 17, 2009
    Messages:
    43
    Likes Received:
    0
    Skylar, I don't think I am doing this right. How do I declare it exactly? I am still learning, I hope this doesn't look stupid, this is what I did...

    - (void)applicationDidFinishLaunching

    Please Register or Log in to view images

    UIAlertView *)alertview {

    UIAlertView *alert = [[UIAlertView alloc]
    initWithTitle

    Please Register or Log in to view images

    "Welcome to my app!"
    message:msg
    delegate:nil
    cancelButtonTitle

    Please Register or Log in to view images

    "Welcome"
    otherButtonTitles:nil];

    errors are
    "unused variable "alert"
    msg undeclared
  5. jamil_d

    jamil_d Active Member

    Joined:
    Dec 15, 2007
    Messages:
    2,041
    Likes Received:
    12
    Device:
    iPhone 3GS (Black)
    [alert show] after that section of code.
  6. gojohnnyboi

    gojohnnyboi Well-Known Member

    Joined:
    Jan 25, 2008
    Messages:
    3,339
    Likes Received:
    55
    I will try to clear this up for you. You want to save a boolean in the NSUserDefaults for your application the first time you run it, so that next time you run it, it knows you already ran it.


    ex:

    Code:
    - (void)applicationDidFinishLaunching:(UIApplication *)app {
            if(![[NSUserDefaults standardUserDefaults] boolForKey:@"AlreadyRan"] ) {
                    [[NSUserDefaults standardUserDefaults] setBool:TRUE forKey:@"AlreadyRan"];
                    // proceed to do what you wish to only on the first launch
            }
    
            // finish with rest of your stuff
    }

Share This Page