2010-12-08 54 views
0

我正在努力提供用户在继续访问应用程序之前必须接受的YES/NO屏幕。当我停止从XCode启动时行为发生变化

这个'接受或拒绝'方法从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); 
     } 
    } 
+0

你可以发布你的`checkTheEULA`代码? – 2010-12-08 04:44:53

+0

当然。今晚会这样做。谢谢! – 2010-12-08 14:29:56

回答

0

我的第一个猜测是,你有一个竞争条件,其中的观点是不总是在基于定时器的回调触发之前加载并呈现。

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

要返回给应用程序代理,你可以这样做

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

    DelegateClass *app = (DelegateClass*)[UIApplication sharedApplication].delegate; 
    [app checkTheEula]; 
} 
相关问题