我是UILocalNotification
概念的新手可以帮助我如何在scheduledLocalNotifications
数组中分隔每小时和每日通知,此处每小时通知是默认通知,每日通知是用户可以设置他们需要哪一天报警。
答案 0 :(得分:0)
您可以设置一些唯一的密钥来标识您的本地通知,请检查以下代码以供参考,下面的UserInfo Dictionary是您的唯一通知密钥。对于所有通知,这应该是不同的。
在您的ViewController.m中设置本地通知或在您想要触发本地通知的任何地方
UILocalNotification *notification = [[UILocalNotification alloc] init];
notification.timeZone = [NSTimeZone localTimeZone];
notification.fireDate = notificationDay;
NSDictionary *userInfo = [NSDictionary dictionaryWithObject:strTime forKey:@"time"]; // This is the UNIQUE value to detect notification
notification.userInfo = userInfo;
[[UIApplication sharedApplication] scheduleLocalNotification:notification];
收到后,您可以获取该userInfo值。
在AppDelegate.m
中接收本地通知-(void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
UIApplication *app = [UIApplication sharedApplication];
NSArray *eventArray = [app scheduledLocalNotifications];
for (int i=0; i<[eventArray count]; i++)
{
UILocalNotification* oneEvent = [eventArray objectAtIndex:i];
NSDictionary *userInfoCurrent = oneEvent.userInfo;
NSString *uid = [NSString stringWithFormat:@"%@",[userInfoCurrent valueForKey:@"time"]]; //Here you can detect the notification to cancel particular...
if ([uid isEqualToString:[[self.arrAlarmList objectAtIndex:sender.tag] valueForKey:@"time"]])
{
//Implement code here for this particular notification...
}
}
}
希望这会帮助你!感谢。