in application, want store date @ app started first time.
i'm using following code in application:didfinishlaunchingwithoptions method
nsdate* today = [nsdate date]; [[nsuserdefaults standarduserdefaults] registerdefaults: @{@"conscience_start_date" : today}]; nslog(@"%@", [[nsuserdefaults standarduserdefaults] objectforkey:@"conscience_start_date"]);
but every time when start application, printing time @ app starting. not printing date @ started app.
i tried reset simulator , ran code again. still no success. can 1 point me error in code please?
since goal keep track of first time user starts app, need in application:didfinishlaunchingwithoptions
:
nsdate *date = [[nsuserdefaults standarduserdefaults] objectforkey:@"conscience_start_date"]; if (!date) { // 1st run of app date = [nsdate date]; [[nsuserdefaults standarduserdefaults] setobject:date forkey:@"conscience_start_date"]; // save date } nslog(@"first run %@", date);
Comments
Post a Comment