0
我使用以下代碼行獲取本地通知。使用UILocalNotification從Array獲取隨機消息的問題
Class cls = NSClassFromString(@"UILocalNotification");
if (cls != nil) {
UILocalNotification *notif = [[cls alloc] init];
notif.fireDate = itemDate;
notif.timeZone = [NSTimeZone defaultTimeZone];
NSMutableArray *newArray=[[self appDelegate].defaultsvalue objectForKey:@"ArrayMessage"];
//int index = arc4random() % [newArray count];
notif.alertBody =[newArray objectAtIndex:arc4random() % [newArray count]];
notif.alertAction = @"Show me";
notif.soundName = UILocalNotificationDefaultSoundName;
notif.applicationIconBadgeNumber = 1;
notif.repeatInterval = NSDayCalendarUnit;
NSDictionary *userDict = [NSDictionary dictionaryWithObject:[newArray objectAtIndex:arc4random() % [newArray count]]
forKey:@"kRemindMeNotificationDataKey"];
notif.userInfo = userDict;
[[UIApplication sharedApplication] scheduleLocalNotification:notif];
}
從上面的代碼「newArray」是NSMutable Array,它存儲了100條消息。現在,我想每天早上8:00從該陣列隨機通知消息。
從上面的代碼我每天都收到相同的消息。我想從該數組中隨機發送消息。
謝謝你..!
你有什麼問題?更新你的問題。 – Harin
你的問題沒有意義。請重寫它。 – trojanfoe
現在請參考問題 – jigs