我想知道是否有人知道如何计算我的应用程序已打开的次数。 NSUserDefalte什么的... 我应该在哪里放var,并且它应该从哪里开始到0?计算应用程序在xcode中打开的次数
回答
在你的类AppDelegate中。你可以这样做:
//Application did launch
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
int count = [[NSUserDefaults standardUserDefaults] integerForKey:@"LaunchCount"];
if(count < 0) count = 0;
[[NSUserDefaults standardUserDefaults] setInteger:count+1 forKey:@"LaunchCount"];
}
//The application was in background and become active
- (void)applicationWillEnterForeground:(UIApplication *)application
{
int count = [[NSUserDefaults standardUserDefaults] integerForKey:@"LaunchCount"];
if(count < 0) count = 0;
[[NSUserDefaults standardUserDefaults] setInteger:count+1 forKey:@"LaunchCount"];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
//add 1
}
图像从http://www.cocoanetics.com/2010/07/understanding-ios-4-backgrounding-and-delegate-messaging/
他应该重写didBecomeActive方法: - (无效)applicationDidBecomeActive:(UIApplication *)应用程序 – Ashbay
在我对此问题的理解中,OP想知道应用程序启动/初始化了多少次。当应用程序从不活动状态转换到活动状态时,例如应用程序处于活动状态,然后发生中断(例如电话呼叫),将调用applicationDidBecomeActive',如果用户没有接听电话,则会调用applicationDidBecomeActive'。 – janusbalatbat
是的,你说得对。这是我没有想到的。 – Ashbay
是,使用是NSUserDefaults的一个简单的解决方案。
(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
// Get the NSUserDefault number here, if not available, create a new.
}
如果你想它来跟踪它是从后台重新开始的时刻,看看:
-(void) applicationWillEnterForeground:(UIApplication*)application
尝试是这样的:
// Get the number of starts:
NSNumber *starts = [[NSUserDefaults standardUserDefaults] objectForKey:@"starts"];
// increase by one
NSNumber *number = [NSNumber numberWithInt:([starts intValue] + 1)];
// store the number of starts
[[NSUserDefaults standardUserDefaults] setObject:starts forKey:@"starts"];
- 1. Xcode“应用程序无法在此计算机上打开”
- 2. 如何使一个Java程序打开计算器应用程序“X”次数
- 3. 我想统计每天打开应用程序的次数
- 4. ConnectionKit应用程序无法在其他计算机上打开
- 5. WinForms应用程序无法在其他计算机上打开
- 6. 在Xcode中的应用程序中打开网址
- 7. 首次打开应用程序?
- 8. Cocoa应用程序第一次打开
- 9. 在xcode中开发android应用程序
- 10. 在更新的应用程序第一次打开之前,可以打开应用程序扩展程序吗?
- 11. XCode 5:一次又一次崩溃,同时打开应用程序
- 12. 如何让我的应用程序仅打开一次,下次打开应用程序时会崩溃?
- 13. 如何在安装xcode 4.0.2时在Xcode 3.2.5中打开应用程序?
- 14. 在我的Android应用程序中打开vimeo应用程序?
- 15. 在我的应用程序中打开“消息”应用程序
- 16. 在我的应用程序中打开外部应用程序
- 17. xCode应用程序点击计数器
- 18. 每次打开应用程序,打开最后打开的活动
- 19. 计算程序启动的次数
- 20. 如何在应用程序打开后重置徽章计数?
- 21. 如何跟踪iPhone应用程序打开的次数?
- 22. 跟踪Android应用程序被打开的次数
- 23. “WPM”如何在打字速度应用程序中计算?
- 24. IOS每次打开应用程序或从Xcode运行时都会创建新的应用程序ID
- 25. 无法打开计算机上的窗口服务'。'在窗口应用程序
- 26. 在不同的计算机上打开应用程序时出错
- 27. 如何在每次打开应用程序时重新启动应用程序?
- 28. 计算C程序中的函数调用次数
- 29. 在iPhone SDK 3.2中无法打开打开的应用程序
- 30. 在Android应用程序中打开URL
10x工作完美! – Sosily
@Ashbay你可以把它放在viewDidLoad下面吗? –