我已经阅读了许多通知帖子,但不知何故我在某个地方出错了,所以这就是我发布这个问题的原因。我想在我的应用程序中每天早上 9 点收到通知。我在上午 9 点正确收到它,没有任何问题,但困难在于我在凌晨 2 点也收到相同的通知。我尝试使用以下代码。谁能告诉我哪里出错了。还是ios6的问题。任何形式的帮助将不胜感激。谢谢你。
NSString *day =@"9:00 AM";
NSDateFormatter *dateFormat = [[[NSDateFormatter alloc] init]autorelease];
[dateFormat setDateFormat:@"hh:mm a"];
//NSTimeZone *gmt = [NSTimeZone timeZoneWithAbbreviation:@"GMT"];
//[dateFormat setTimeZone:gmt];
NSDate *today=[dateFormat dateFromString:day];
NSLog(@"string %@ & date %@",day,today);
Class cls = NSClassFromString(@"UILocalNotification");
if (cls != nil)
{
// delObj.QCouter=delObj.QCouter+1;
//[[UIApplication sharedApplication] cancelAllLocalNotifications];
notif = [[cls alloc] init];
notif.fireDate =today;
notif.timeZone = [NSTimeZone systemTimeZone];
NSLog(@"timeZone %@ ",[NSTimeZone systemTimeZone]);
notif.alertBody = @"You have a new letter ";
notif.alertAction = NSLocalizedString(@"View", nil);;
notif.soundName = @"Ding3.wav";
notif.applicationIconBadgeNumber = 1;
notif.repeatInterval = NSDayCalendarUnit;
[[NSUserDefaults standardUserDefaults] setObject:@"1" forKey:@"Status"];
NSDictionary *userDict = [NSDictionary dictionaryWithObject:@"You have a notifiaction"
forKey:kRemindMeNotificationDataKey];
notif.userInfo = userDict;
// NSLog(@"userInfo %@",notif.userInfo);
[[UIApplication sharedApplication] scheduleLocalNotification:notif];
[notif release];
[[NSUserDefaults standardUserDefaults] setObject:@"CurrentDay" forKey:@"DayChange"];
}