0

I’m working on a way to present a YES / NO screen the user must accept before proceeding to the app.

This ‘accept or decline’ method fires from within ApplicationDidFinishLaunching, and is on a timer to fire in 2 seconds (or whenever). It looks in NSUserDefaults and retrieves a key which tells me whether or not the agreement has been accepted. If not (or nil), I launch a modalViewController to present the agreement. The AppDidFinishLaunching method is virtually boilerplate and looks like this:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
  // Override point for customization after application launch.
  // Add the tab bar controller's view to the window and display.
  [window addSubview:tabBarController.view];
  [window makeKeyAndVisible];
  [self performSelector:@selector(checkTheEULA) withObject:nil afterDelay:kDelay];
  return YES;
}

Everything works great. The problem is, it only works once—when I launch from Xcode. If I stop the app and launch from the simulator or on my device, no modal view is presented to the user.

Could anyone tell me what’s happening to cause this? I’m assuming it has something to do with the appDelegate itself? Am I leaving something out?

Any help would be very appreciated--I'm still quite green :-)

Thanks,

- (void)checkTheEULA{                             

    // get value in kAcceptedOrNot key (NSString, either YES NO or nil), assign it to acceptedOrNot
    self.acceptedOrNot = [[NSUserDefaults standardUserDefaults] objectForKey:kAcceptedOrNotKey];

    if (self.acceptedOrNot == nil || [self.acceptedOrNot isEqualToString:@"NO"]) {

        NSLog(@"The value of kAcceptedOrNot is %@ (nil or NO). This means that the EULA has never been launched, or has launched but has been UNaccepted", self.acceptedOrNot);
        NSLog(@"I'm launching the ModalView to give the user the chance to accept the EULA");

        [self showModalView];
    } else {

        // else, the value of kAcceptedOrNot exists and is YES, and so no action needs to be taken

        NSLog(@"Value of accepteOrNot is %@. (hopefully it's 'YES' :-)", acceptedOrNot);
        }
    }   
3
  • Can you post your code for checkTheEULA? Dec 8, 2010 at 4:44
  • Absolutely. Will do so this evening. Thanks! Dec 8, 2010 at 14:29
  • There's another method, showModalView, which I can post, but didn't know how much upstream code to post here. Let me know if I should post more. Dec 9, 2010 at 3:39

1 Answer 1

0

My first guess is that you have a race condition where the view isn't always being loaded and presented before your timer-based callback fires.

Try putting the call to checkTheEula directly into the view controller's viewDidAppear, so that it fires it once you have UI on the screen.

To get back to the app delegate you can do something like

-(void) viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];

    DelegateClass *app = (DelegateClass*)[UIApplication sharedApplication].delegate;
    [app checkTheEula];
}
2
  • That's not a bad idea. My current setup uses a TabBarController for the root viewController. After checkTheEULA fires, I determine which viewController is visible, assign that VC as the modal view's parent view and delegate, then ask it to present the modalView. Practically speaking though, it makes sense to simplify this step, and use the tabBar's left-most viewController at startup. If I can't figure this our I may just do so. I'll also investigate 'race condition' to see if that sheds any light on this. Thanks! Dec 9, 2010 at 16:46
  • Ahh sorry. By 'race condition' what I mean is that you have an event that sometimes happens late enough that everything works, but other times happens too soon, before other pieces are in place. This is a common kind of problem to see between running in a simulator and on a device. My guess is that when you start up through Xcode there's some combination of timing factors that makes your UI appear before you try to make your EULA call, so you have something to paint on. On the device it's probably taking longer to get the UI initialized, and so when you call EULA the UI isn't ready yet. Dec 9, 2010 at 17:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.