[英]iOS first launch tour - detecting if the app is launched for the first time
[英]How to setup first time launch of an iOS App
我想在我的应用首次启动时显示条款和条件。
目前我正在使用didFinishLaunchingWithOptions
编写代码。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Handle launching from a notification
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"HasLaunchedOnce"])
{
NSLog(@"Already Run");
}
else
{
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"HasLaunchedOnce"];
[[NSUserDefaults standardUserDefaults] synchronize];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle: nil];
FirstPage * termsView = [storyboard instantiateViewControllerWithIdentifier:@"FirstPage"];
UINavigationController *navController=[[UINavigationController alloc]initWithRootViewController:termsView];
self.window.rootViewController=navController;
// This is the first launch ever
}
}
更新::
当我的应用程序第一次在TERMSandCONDITIONSVC
启动时,我想要一个Accept
按钮。 当用户Accepts
聚合时,只有他允许进一步。
上述代码问题:
当我第一次运行我的应用程序时, TermsandCondition
显示给我。我按下主页按钮应用程序进入后台。 TermsandCondtion
打开应用程序从启动器和TermsandCondtion
显示。
但是,当我将我的应用程序放在后台并通过加倍点击主页按钮将其从后台删除并运行应用程序我直接转移到我的主屏幕。
没有条款和条件。
我怎样才能从中恢复过来。
您将获得黑屏,因为没有将viewcontroller设置为根视图。
做一件事也将你的其他部分写入IF部分,并将控制器从术语页面更改为第二页。
尝试将下面的代码放在didFinishLaunch中并检查。
self.window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
UINavigationController *navController
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"HasLaunchedOnce"])
{
NSLog(@"Already Run");
SecondView *secondView = [storyboard instantiateViewControllerWithIdentifier:<storyboard id>];
navController=[[UINavigationController alloc]initWithRootViewController:secondView];
}
else
{
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"HasLaunchedOnce"];
[[NSUserDefaults standardUserDefaults] synchronize];
TermsView *termsView = [storyboard instantiateViewControllerWithIdentifier:<storyboard id>];
navController=[[UINavigationController alloc]initWithRootViewController:termsView];
// This is the first launch ever
}
}
self.window.rootViewController=navController;
return YES;
更新:只需拖动以下行以同意按钮的单击事件并从didFinishlaunching中删除此行。
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"HasLaunchedOnce"];
[[NSUserDefaults standardUserDefaults] synchronize];
您正在以错误的方式实例化您的termsView
。 在你的故事板分配FirstPage
视图控制器的storyboardID FirstPage
。
然后在你的didFinishLaunchingWithOptions
执行以下操作
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle: nil];
FirstPage * termsView = [storyboard instantiateViewControllerWithIdentifier:@"FirstPage"];
这将找到您的主要故事板,然后根据提供的storyboardID(即FirstPage
)使用ViewController实例化termsView
。
如果您想要首次启动iOS应用程序。 使用此代码,条款和条件将仅在应用程序首次启动时显示或显示。
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"HasLaunchedOnce"])
{
NSLog(@"Already Run");
}
else
{
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"HasLaunchedOnce"];
[[NSUserDefaults standardUserDefaults] synchronize];
FirstPage *termsView = [[FirstPage alloc]init];
UINavigationController *navController=[[UINavigationController alloc]initWithRootViewController:termsView];
self.window.rootViewController=navController;
// This is the first launch ever
UIStoryboard *story=[UIStoryboard storyboardWithName:@"Main" bundle:nil];
//first goto storyboard and give storyboard id "TermsConditionVC" to TermsConditionVC
TermsConditionVC *firstVC = [story instantiateViewControllerWithIdentifier:@"TermsConditionVC"];
self.window.rootViewController =firstVC;
}
有关完整文章和完整流程设置您的第一个计时器iOS应用程序启动访问下面的链接
http://findnerd.com/list/view/How-to-setup-first-time-launch-of-an-iOS-App/2770/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.