我想知道是否有人知道如何計算我的應用程序已打開的次數。 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下面嗎? –