Detecting second and third launch using "prevStartupVersions"

Discussion in 'Mac Programming' started by gwelmarten, May 5, 2012.

  1. macrumors 6502

    Joined:
    Jan 17, 2011
    Location:
    England!
    #1
    Hi
    I'm detecting the number of times my Mac application has being opened using the following code:
    Code:
     NSString *currentVersion = (NSString*)[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"];
        NSArray *prevStartupVersions = [[NSUserDefaults standardUserDefaults] arrayForKey:@"prevStartupVersions"];
        if (prevStartupVersions == nil) 
              {
              }
         else {
              }
     [[NSUserDefaults standardUserDefaults] synchronize];
    However, this only works for detecting the first launch. How would I detect a second and third launch? I did try:
    Code:
    if (prevStartupVersions == 1) 
    However, I am comparing an NSArray with an Interger there. How should adapt this to detect a second launch?

    Thanks in advance for any help,

    Sam
     
  2. macrumors 6502a

    Joined:
    Dec 2, 2008
    #2
    NSArray length

    How about

    Code:
    if ([prevStartupVersions length] == 1)
    
     
  3. thread starter macrumors 6502

    Joined:
    Jan 17, 2011
    Location:
    England!
    #3
    No luck I'm afraid :
    Code:
    'NSArray' may not responnd to 'length'
     
  4. macrumors 603

    Joined:
    Aug 9, 2009
    #4
    Read the reference doc for NSArray. Look up the count method.
     

Share This Page