0
这可能是一个重复的问题,但请帮助我。我使用下面的代码来发射本地通知,但它并未发射。我使用了一个拾取器来设置发射本地请帮助我..本地通知不在iphone中触发
[self.actionSheet dismissWithClickedButtonIndex:0 animated:YES];
if (nil != self.data) {
//send data picker message
[self.target performSelector:self.action withObject:[NSNumber numberWithInt:self.selectedIndex]];
}
else {
//NSDate *date = [NSDate date];
//NSDateFormatter *dateFormat = [[NSDateFormatter alloc]init];
//[dateFormat setDateFormat:@"HH:mm:ss zzz"];
//NSString *dateString = [dateFormat stringFromDate:date];
//send date picker message
NSCalendar *calendar = [NSCalendar autoupdatingCurrentCalendar];
// Get the current date
NSDate *pickerDate = [self.datePickerView date];
//NSLog(@"date ==%@",pickerdate);
//Break the date up into components
NSDateComponents *dateComponents = [calendar components:(NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit)
fromDate:pickerDate];
NSDateComponents *timeComponents = [calendar components:(NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit)
fromDate:pickerDate];
// Set up the fire time
NSDateComponents *dateComps = [[NSDateComponents alloc] init];
[dateComps setDay:[dateComponents day]];
[dateComps setMonth:[dateComponents month]];
[dateComps setYear:[dateComponents year]];
[dateComps setHour:[timeComponents hour]];
//NSLog(@"day%@",[dateComponents day]);
// Notification will fire in one minute
[dateComps setMinute:[timeComponents minute]];
[dateComps setSecond:[timeComponents second]];
NSDate *itemDate = [calendar dateFromComponents:dateComps];
[dateComps release];
UILocalNotification *localNotif = [[UILocalNotification alloc] init];
if (localNotif == nil)
return;
localNotif.fireDate = itemDate;
NSLog(@"%@what is this",itemDate);
localNotif.timeZone = [NSTimeZone defaultTimeZone];
//Notification details
localNotif.alertBody = @"Tip of the day";
//Set the action button
localNotif.alertAction = @"View";
localNotif.soundName = UILocalNotificationDefaultSoundName;
localNotif.repeatInterval = NSDayCalendarUnit;
localNotif.applicationIconBadgeNumber = 1;
// Specify custom data for the notification
NSDictionary *infoDict = [NSDictionary dictionaryWithObject:@"someValue" forKey:@"someKey"];
localNotif.userInfo = infoDict;
// Schedule the notification
[localNotif release];
}
当你从这个问题复制粘贴代码http://stackoverflow.com/questions/6785989/local-notification-not-firing-in-iphone。您错过了[[[UIApplication sharedApplication] scheduleLocalNotification:localNotif];' –
如果您的应用程序处于前台,则通知也不会出现 –
@ xs2bush对不起,我发布我的答案之前没有看到您的评论发布。 – MiguelB