UILocalnotification

时间:2014-05-29 11:21:08

标签: ios iphone uilocalnotification

我想在游戏中安排本地通知 第一次通知将在游戏结束后两小时发出 之后,如果仍然没有游戏玩法,那么另外一个会在接下来的24小时内到来如果游戏玩法在2小时后重置,则每24小时重置一次,直到他们进入游戏。 如果你能帮助我,我将非常感谢你 这是我的代码:

UILocalNotification *notif = [[UILocalNotification alloc] init];
notif.alertBody =  [self.notifyArray objectAtIndex:index];

NSTimeInterval sec = 7200;
notif.fireDate = [NSDate dateWithTimeIntervalSinceNow:sec];
notif.repeatInterval = NSDayCalendarUnit;
notif.soundName = UILocalNotificationDefaultSoundName;
NSLog(@"notif : %u",notif.repeatInterval);
notif.applicationIconBadgeNumber += 1;
[[UIApplication sharedApplication] scheduleLocalNotification:notif];

//notif.fireDate = [NSDate dateWithTimeIntervalSinceNow:20];
 //[[UIApplication sharedApplication] scheduleLocalNotification:notif];

2 个答案:

答案 0 :(得分:1)

首先尝试通过检查预定通知列表进行调试。您可以查看此主题以获取详细信息iOS find list of Local Notification the app has already set

答案 1 :(得分:0)

首先为您的本地通知提供“标识符”。然后,当应用程序转到后台时,使用该标识符来识别应用程序的预定通知中的通知。并在2小时后重新安排,重复一天的时间间隔。

UIApplication *app = [UIApplication sharedApplication];
NSArray *eventArray = [app scheduledLocalNotifications];
for (int i=0; i<[eventArray count]; i++)
{
    UILocalNotification* oneEvent = [eventArray objectAtIndex:i];
   if ( oneEvent.identifier = yourNotificationIdentifier){
//Reschedule oneEvent.
}
}