开发者

Is there any delegate that fires when I run the iphone application for the first time?

开发者 https://www.devze.com 2023-02-09 09:35 出处:网络
I 开发者_开发百科need to track the download of a certain iphone application. I tried a lot and found out that we could track it from the AppStore. But i need to track that from my application itself.

I 开发者_开发百科need to track the download of a certain iphone application. I tried a lot and found out that we could track it from the AppStore. But i need to track that from my application itself. So please help me to identify the method that fires when the application starts for the first time. Thanks.


There's no specific method that fires only on the 1st application launch. You can set a flag in user defaults on application start - so if the flag is not present then that will mean that application launched for the 1st time:

- (void)applicationDidFinishLaunching:(UIApplication *)application { 
    if (![[NSUserDefaults standardDefaults] boolForKey:@"AlreadyLaunched"]){
        // First launch logic

        [[NSUserDefaults standardDefaults] setBool:YES forKey:@"AlreadyLaunched"];
        [[NSUserDefaults standardDefaults] synchronize];
    }
    ...
}


But i need to track that from my application itself.

No.

But if you really want to do this you could use something like this:

BOOL hasUsedSpyWareFunctions = [[NSUserDefaults standardUserDefaults] boolForKey:@"SpyWareKey"];
if (!hasUsedSpyWareFunctions) {
    [self spyOnUser];
    [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"SpyWareKey"];
}

if you are a Pro in spying you only set the key to YES if the method returned successfully (ie a network connection could be established)


There’s no such an event, at least not one that I know of. But what you want can be trivially done using NSUserDefaults. Simply check for some boolean flag and if it’s not there, it’s a first run and you can set the flag:

NSString *const AlreadyRunKey = @"already-run";
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
if (![prefs boolForKey:AlreadyRunKey]) {
    [prefs setBool:YES forKey:AlreadyRunKey];
    [prefs synchronize];
    // do whatever else you want
}
0

精彩评论

暂无评论...
验证码 换一张
取 消