我找不到一种方法来检测这是否是第一次运行应用程序.有任何想法吗?
- (BOol)application:(UIApplication *)application dIDFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // OverrIDe point for customization after application launch NSUserDefaults *padFactoIDs; int launchCount; padFactoIDs = [NSUserDefaults standardUserDefaults]; launchCount = [padFactoIDs integerForKey:@"launchCount" ] + 1; [padFactoIDs synchronize]; NSLog(@"this is the number: %i of times this app has been launched",launchCount); if ( launchCount == 1 ) { NSLog(@"this is the FirsT LAUNCH of the app"); // do stuff here as you wish bbb = [[Blue alloc]init]; [window addSubvIEw:bbb.vIEw]; } if ( launchCount >= 2 ) { NSLog(@"this is the SECOND launch of the damn app"); // do stuff here as you wish rrr = [[Red alloc]init]; [window addSubvIEw:rrr.vIEw]; } [window makeKeyAndVisible]; return YES;}
这里Red& Blue是两个类中uivIEwcontroller的子类,只有一个不同之处在于 – (voID)vIEwDIDLoad {
self.vIEw.backgroundcolor = [UIcolor redcolor];
在Red class&在显示蓝色backgroundcolor的蓝色类
但是,当我执行应用程序时,它的显示只有蓝色不显示红色,我错了我做的时候,当我运行应用程序时,它显示红色…..
在任何地方添加此代码.也许只是在您的应用程序中:dIDFinishLaunchingWithOptions:文件AppDelegate.m中的例程.或者,无论您在何处为应用程序进行常规设置. (但是,请确保它只运行一次.)
NSUserDefaults *padFactoIDs;int launchCount;padFactoIDs = [NSUserDefaults standardUserDefaults];launchCount = [padFactoIDs integerForKey:@"launchCount" ] + 1;[padFactoIDs setInteger:launchCount forKey:@"launchCount"];[padFactoIDs synchronize];NSLog(@"number of times: %i this app has been launched",launchCount);if ( launchCount == 1 ) { NSLog(@"this is the FirsT LAUNCH of the app"); // do stuff here as you wish }if ( launchCount == 2 ) { NSLog(@"this is the SECOND launch of the damn app"); // do stuff here as you wish }// enjoy!
除了最简单的应用程序之外,几乎每个应用都会这样做.希望能帮助到你.从理论上来说,你不一定要打扰“同步”调用,但是我们已经发现了大量的实际用户运行,如果你确实包含它,它可能更可靠.
PS不要在偏好中使用布尔值.如果您是一名新程序员,那么理解默认值并因此无法维护是不明智的.坚持整数. (首次使用时,它们总是“整数零”,因此您没有问题.)Easy Peasy.希望能帮助到你.
总结以上是内存溢出为你收集整理的如何在iphone上首次确定负载应用?全部内容,希望文章能够帮你解决如何在iphone上首次确定负载应用?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)