PDA

View Full Version : Detecting second and third launch using "prevStartupVersions"




gwelmarten
May 5, 2012, 11:53 AM
Hi
I'm detecting the number of times my Mac application has being opened using the following 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:

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



PatrickCocoa
May 5, 2012, 01:34 PM
How about

if ([prevStartupVersions length] == 1)

gwelmarten
May 5, 2012, 01:41 PM
No luck I'm afraid :
'NSArray' may not responnd to 'length'

chown33
May 5, 2012, 04:12 PM
No luck I'm afraid :
'NSArray' may not responnd to 'length'

Read the reference doc for NSArray. Look up the count method.