我已經在我的項目上實現了UILocalNotification成功,我在隨機化字符串失敗時出現了NSDictionary,我需要每5分鐘發送一次整個世界。每隔5分鐘,我需要在UILocalNotification中傳遞隨機字符串。使用UILocalNotification與隨機化字符串
這裏是我的示例代碼:
NSArray *word1Array= [_tmp objectForKey:@"word1"];
NSArray *word2Array = [_tmp objectForKey:@"word2"];
if([word1Array count] > 0)
{
int minCount = 0;
int totalcount = (int)[word1Array count];
int randomIndex = (arc4random()%(totalcount-minCount))+minCount;
NSString *word1 = [word1Array objectAtIndex:randomIndex];
NSString *word2 = [word2Array objectAtIndex:randomIndex];
NSString *wordbody = [NSString stringWithFormat:@"%@ - %@",word1,word2];
UILocalNotification *reminderNote = [[UILocalNotification alloc]init];
reminderNote.repeatInterval = NSMinuteCalendarUnit;
reminderNote.alertBody = wordbody;
reminderNote.alertAction = @"Bak";
reminderNote.soundName = @"sound.aif";
reminderNote.fireDate = [NSDate dateWithTimeIntervalSinceNow:60 * 5];
reminderNote.applicationIconBadgeNumber = 1;
[[UIApplication sharedApplication] scheduleLocalNotification:reminderNote];
}
此代碼開始與隨機字符串,但是每5分鐘發送通知,它通過4-5個字同時這實在是煩人。我如何解決它只發送每5分鐘一個字符串?
怎麼樣,如果我想使它無限循環。我的意思是它會在5分鐘內發送本地通知。它會每隔5分鐘發送一次,而不是5個字* 5 = 25分鐘。 – 2014-09-04 14:00:57
不幸的是,一切都有限制。您最多可以有64個預定的本地通知。除非你找到了一個接一個聰明的方法。查看上面更新的答案。 – Ricky 2014-09-04 14:03:41
注意:**定期通知**將具有相同的警報消息。這可能會在一個又一個的時間表上幫助:http://stackoverflow.com/questions/18792997/uilocalnotification-with-various-alert-body – Ricky 2014-09-04 14:14:53