How can I have alert show every 7 days (google analytics)

Discussion in 'iOS Programming' started by stera8, Dec 30, 2014.

  1. stera8 macrumors member

    Joined:
    Aug 21, 2014
    #1
    Hello. I have google analytics where an alert shows every time the user opens the app. I would like it to be where the user only sees this alert the first time they open it if they decide to opt in.

    If they decide not to opt in, I would like the alert to show every 7 days and allow them to change this in the settings app if they decide to opt in.

    Code:
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary     *)launchOptions
    {
     ...
    
    
    
    UIAlertView *av = [[UIAlertView alloc] initWithTitle:@"Google Analytics" message:@"With your permission usage information will be collected to improve the application." delegate:self cancelButtonTitle:@"Opt Out" otherButtonTitles:@"Opt In", nil];
    [av show];
    
    return YES;
    }
    
    - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    switch (buttonIndex) {
        case 0:
            [[GAI sharedInstance] setOptOut:YES];
            break;
        case 1:
            [[GAI sharedInstance] setOptOut:NO];
            break;
    
        default:
            break;
    }
    }
     
  2. DannyBres macrumors 65816

    DannyBres

    Joined:
    Oct 30, 2007
    Location:
    UK
    #2
    I'm sure your users will hate this.

    Can you not do it another way?

    ----------

    ...but to answer your question. I would store the day the user last said no, probably as a NSDate in an NSUserDefault.

    Then on launch calculate the number of days since that date or maybe just if ([lastDate timeIntervalSinceNow] < -6*60*60). If sufficient time has passed show the alert view again.
     
  3. stera8 thread starter macrumors member

    Joined:
    Aug 21, 2014
    #3
    Yes I agree. So until another update I ask the person on first launch and not again. I have to think about it.

    What does everyone else do to show users about collecting analytics?
     
  4. Boris-VTR, Jan 2, 2015
    Last edited: Jan 2, 2015

    Boris-VTR macrumors regular

    Joined:
    Apr 18, 2013
    #4
    Maybe try with scheduledLocalNotifications. It will fire alert on date (or dates) that you specify.

    To store option that user selected i would also use NSUserDefault. Store it as key-value pair and check it every time app is loaded.

    Code:
    BOOL userOption; // user selected opt to alerts.
    
    NSUserDefault *showAVAlert = [NSUserDefault standardUserDefaults];
    [showAVAlert setBool:userOption forKey:@"showAlert];
     
  5. DannyBres macrumors 65816

    DannyBres

    Joined:
    Oct 30, 2007
    Location:
    UK
    #5
    Thanks Boris.

    All my analytics are anonymous as most apps and I just do not mention it, very few apps do.
     
  6. Mascots macrumors 65816

    Mascots

    Joined:
    Sep 5, 2009
    #6
    This method will not scale across calendars, timezones, or daylight savings. I suggest you use NSCalendar and NSDateComponents.

    There's a lot of examples online (on my phone for the moment, so can't type or find one), but I HIGHLY suggest that route.
     

Share This Page