当我停止从XCode启动时,行为会发生变化

时间:2010-12-08 04:28:31

标签: iphone

我正在努力提供用户在继续使用该应用之前必须接受的“是/否”屏幕。

这个'接受或拒绝'方法从ApplicationDidFinishLaunching中触发,并且在2秒钟内(或每当)触发一个计时器。它在NSUserDefaults中查找并检索一个密钥,该密钥告诉我协议是否已被接受。如果不是(或为零),我启动一个modalViewController来呈现协议。 AppDidFinishLaunching方法实际上是样板文件,如下所示:

- (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;
}

一切都很好。问题是,当我从Xcode启动时,它只能工作一次。如果我停止应用程序并从模拟器或我的设备启动,则不会向用户显示模态视图。

有人能告诉我发生了什么事吗?我假设它与appDelegate本身有关?我要留下什么了吗?

任何帮助都会非常感激 - 我还是很绿: - )

谢谢,

- (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);
        }
    }   

1 个答案:

答案 0 :(得分:0)

我的第一个猜测是你有一个竞争条件,在你的基于计时器的回调激发之前,视图并不总是被加载和显示。

尝试将checkTheEula的调用直接放入视图控制器的viewDidAppear中,以便在屏幕上显示UI后触发它。

要返回应用代理,您可以执行类似

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

    DelegateClass *app = (DelegateClass*)[UIApplication sharedApplication].delegate;
    [app checkTheEula];
}