2012-11-16 114 views
0

我發現了一些討論這個並將其實現到我的代碼中的線程,但是我有一個錯誤。跟蹤發佈bug

我正在嘗試每5次發射一次。

另外的代碼設置launchAmounts,是建於到userDefaults,或做我必須聲明這個地方?

我在我的主視圖控制器中從viewwillappear這樣做。

NSUserDefaults * userDefaults = [NSUserDefaults standardUserDefaults]; 
NSInteger appLaunchAmounts = [userDefaults integerForKey:@"LaunchAmounts"]; 
appLaunchAmounts = appLaunchAmounts %5; 
NSLog(@"app has been launched = %d", appLaunchAmounts); 
[userDefaults setInteger:appLaunchAmounts+1 forKey:@"LaunchAmounts"]; 


if (appLaunchAmounts==0) { 
+1

什麼是錯誤? – mttrb

+0

爲什麼'appLaunchAmounts = appLaunchAmounts%5'? – trojanfoe

+0

我想它是多餘的?它應該是如果(applaunchamounts%5 == 0){...? –

回答

1

該代碼看起來像它應該工作,除了它在viewWillAppear它的事實。如果您在不同的視圖控制器之間來回切換,則可以在一次運行中多次調用該方法。您應該將其放入應用程序委託中的applicationDidFinishLaunching方法中。

什麼不是你現在的樣子?

+0

你是對的,我只是不得不在那裏工作。謝謝。快速學習:) –