我有一个与“Flocked”用户类似的问题(请参阅此处的问题Load an other View from applicationDidFinishLaunching in the AppDelegate),但是在阅读了他的帖子后,我没有设法解决它,也许我的情况与他不同。
我的didFinishLaunchingWithOptions
内部有一个例程,用于检查应用程序是否是首次运行(也来自其他用户):
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
if (![[NSUserDefaults standardUserDefaults] boolForKey:@"everLaunched"]) {
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"everLaunched"];
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"firstLaunch"];
}
else{
[[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"firstLaunch"];
}
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"firstLaunch"]) {
NSLog(@"First run");
}
[[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(reachabilityChanged:) name: kReachabilityChangedNotification object: nil];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
}
如果发生firstLaunch,则无法加载另一个视图
InfoView
(用于安装的视图)。我努力了:
InfoView *infoView = [[InfoView alloc]init];
[self presentViewController:infoView animated:YES completion:nil];
里面
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"firstLaunch"])
但没有运气。有什么想法或帮助吗?
最佳答案
尝试这个:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
[[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(reachabilityChanged:) name: kReachabilityChangedNotification object: nil];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
if (![defaults boolForKey:@"everLaunched"]) {
NSLog(@"First run");
[defaults setBool:YES forKey:@"everLaunched"];
InfoView *infoView = [[InfoView alloc]init];
[self.viewController presentViewController:infoView animated:YES completion:nil];
}
return YES;
}