我想动态更改 rootViewController。这取决于json响应。我有一个 BOOL 值,它在得到 json 响应后会发生变化。问题是即使条件为真,这个值也永远不会改变。
我的代码在下面,我把它放在应用程序 didFinishLaunchingWithOptions 中:
isTime = NO;
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:[NSURL URLWithString:
[url
stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding] ]];
__block NSDictionary * json;
[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response,NSData *data,NSError *connectionError){
json = [NSJSONSerialization JSONObjectWithData:data options:0 error:&connectionError];
NSLog(@"JSON >>>> %@",[json objectForKey:@"status"]);
if ([[json objectForKey:@"status"] isEqualToString:@"ok"]) {
isTime = YES;
}
}];
if(isTime){
//rootView1
}else{
//rootView2
}
我该如何解决?有任何想法吗?