从选择 Table 单元格设置本地通知
Set Local Notification from Selecting Table cell
其实这个问题已经被问过很多次了。但我对这些感到困惑。这个我试过了。
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if([[cell.btn backgroundImageForState:UIControlStateNormal]isEqual:[UIImage imageNamed:@"unchecked.png"]])
{
[cell.btn setBackgroundImage:[UIImage imageNamed:@"checked.png"] forState:UIControlStateNormal];
UILocalNotification *reminderNote =[[UILocalNotification alloc]init];
reminderNote.soundName = @"music.mp3";
[[UIApplication sharedApplication] scheduleLocalNotification:reminderNote];
reminderNote.alertBody = @"Wish birthday to :%@",[kAppDelegate.commString objectAtIndex:indexPath.row];
NSString *date =[kAppDelegate.String objectAtIndex:indexPath.row];
NSDate *dateP = [ dateformat dateFromString:date];
components = [[NSCalendar currentCalendar] components:NSCalendarUnitDay | NSCalendarUnitMonth | NSCalendarUnitYear fromDate:dateP];
[components setHour:4];
[components setMinute:59];
[components setSecond:10];
reminderNote.fireDate = [[NSCalendar currentCalendar] dateFromComponents:components];
}
其中单元格是 UITableviewCell
的对象,但没有任何类型的通知。我知道有一点Bug,请帮我看看。
将最后一行作为 [[UIApplication sharedApplication] scheduleLocalNotification:reminderNote]; 放在 reminderNote.fireDate[= 之后23=]行.
记录 reminderNote.fireDate 并检查格式。
希望对您有所帮助。
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if([[cell.btn backgroundImageForState:UIControlStateNormal]isEqual:[UIImage imageNamed:@"unchecked.png"]])
{
[cell.btn setBackgroundImage:[UIImage imageNamed:@"checked.png"] forState:UIControlStateNormal];
UILocalNotification *reminderNote =[[UILocalNotification alloc]init];
reminderNote.soundName = @"music.mp3";
reminderNote.alertBody = @"Wish birthday to :%@",[kAppDelegate.commString objectAtIndex:indexPath.row];
NSString *date =[kAppDelegate.String objectAtIndex:indexPath.row];
NSDate *dateP = [ dateformat dateFromString:date];
components = [[NSCalendar currentCalendar] components:NSCalendarUnitDay | NSCalendarUnitMonth | NSCalendarUnitYear fromDate:dateP];
[components setHour:4];
[components setMinute:59];
[components setSecond:10];
reminderNote.fireDate = [[NSCalendar currentCalendar] dateFromComponents:components];
[[UIApplication sharedApplication] scheduleLocalNotification:reminderNote];
}
单次最多可添加64条本地通知。
UILocalNotification *localNotification = [[UILocalNotification alloc] init];
NSDate *newDate = [fireDate dateByAddingTimeInterval:(6*60*60)];
// 6*60*60=6 hour*60 minutes*60 seconds
// [fireDate dateByAddingTimeInterval:(6*60*60*i)];
localNotification.fireDate = newDate;
localNotification.timeZone = [NSTimeZone defaultTimeZone];
localNotification.repeatInterval = 0;
localNotification.alertBody = alertText;
localNotification.alertAction = alertAction;
if(soundfileName == nil)
{
localNotification.soundName = UILocalNotificationDefaultSoundName;
}
else
{
localNotification.soundName = soundfileName;
}
localNotification.alertLaunchImage = launchImage;
localNotification.applicationIconBadgeNumber = 1;
localNotification.userInfo = userInfo;
// NSLog(@"%@", [localNotification description]);
// Schedule it with the app
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
如果要保留 NSNotification
的所有对象,则需要将其存储在某个地方。即在数组中。
您还可以使用以下方法进行 NSNotifications 操作。
- (void)cancelLocalNotification:(UILocalNotification *)notification
- (void)cancelAllLocalNotifications
确保您在
上收到通知
-(void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
作为使用该对象之前的良好做法,请确保您已初始化并将所有值设置为特定对象。
请试试这个本地通知
-(void)localnotification{
NSDate *pickerDate = [self.datepicker date];
// Schedule the notification
UILocalNotification* localNotification = [[UILocalNotification alloc] init];
localNotification.fireDate = pickerDate;
localNotification.alertBody = self.labelname.text;
localNotification.alertAction = @"Show me the item";
localNotification.timeZone = [NSTimeZone defaultTimeZone];
localNotification.applicationIconBadgeNumber = [[UIApplication sharedApplication] applicationIconBadgeNumber] + 1;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
}
其实这个问题已经被问过很多次了。但我对这些感到困惑。这个我试过了。
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if([[cell.btn backgroundImageForState:UIControlStateNormal]isEqual:[UIImage imageNamed:@"unchecked.png"]])
{
[cell.btn setBackgroundImage:[UIImage imageNamed:@"checked.png"] forState:UIControlStateNormal];
UILocalNotification *reminderNote =[[UILocalNotification alloc]init];
reminderNote.soundName = @"music.mp3";
[[UIApplication sharedApplication] scheduleLocalNotification:reminderNote];
reminderNote.alertBody = @"Wish birthday to :%@",[kAppDelegate.commString objectAtIndex:indexPath.row];
NSString *date =[kAppDelegate.String objectAtIndex:indexPath.row];
NSDate *dateP = [ dateformat dateFromString:date];
components = [[NSCalendar currentCalendar] components:NSCalendarUnitDay | NSCalendarUnitMonth | NSCalendarUnitYear fromDate:dateP];
[components setHour:4];
[components setMinute:59];
[components setSecond:10];
reminderNote.fireDate = [[NSCalendar currentCalendar] dateFromComponents:components];
}
其中单元格是 UITableviewCell
的对象,但没有任何类型的通知。我知道有一点Bug,请帮我看看。
将最后一行作为 [[UIApplication sharedApplication] scheduleLocalNotification:reminderNote]; 放在 reminderNote.fireDate[= 之后23=]行.
记录 reminderNote.fireDate 并检查格式。
希望对您有所帮助。
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if([[cell.btn backgroundImageForState:UIControlStateNormal]isEqual:[UIImage imageNamed:@"unchecked.png"]])
{
[cell.btn setBackgroundImage:[UIImage imageNamed:@"checked.png"] forState:UIControlStateNormal];
UILocalNotification *reminderNote =[[UILocalNotification alloc]init];
reminderNote.soundName = @"music.mp3";
reminderNote.alertBody = @"Wish birthday to :%@",[kAppDelegate.commString objectAtIndex:indexPath.row];
NSString *date =[kAppDelegate.String objectAtIndex:indexPath.row];
NSDate *dateP = [ dateformat dateFromString:date];
components = [[NSCalendar currentCalendar] components:NSCalendarUnitDay | NSCalendarUnitMonth | NSCalendarUnitYear fromDate:dateP];
[components setHour:4];
[components setMinute:59];
[components setSecond:10];
reminderNote.fireDate = [[NSCalendar currentCalendar] dateFromComponents:components];
[[UIApplication sharedApplication] scheduleLocalNotification:reminderNote];
}
单次最多可添加64条本地通知。
UILocalNotification *localNotification = [[UILocalNotification alloc] init];
NSDate *newDate = [fireDate dateByAddingTimeInterval:(6*60*60)];
// 6*60*60=6 hour*60 minutes*60 seconds
// [fireDate dateByAddingTimeInterval:(6*60*60*i)];
localNotification.fireDate = newDate;
localNotification.timeZone = [NSTimeZone defaultTimeZone];
localNotification.repeatInterval = 0;
localNotification.alertBody = alertText;
localNotification.alertAction = alertAction;
if(soundfileName == nil)
{
localNotification.soundName = UILocalNotificationDefaultSoundName;
}
else
{
localNotification.soundName = soundfileName;
}
localNotification.alertLaunchImage = launchImage;
localNotification.applicationIconBadgeNumber = 1;
localNotification.userInfo = userInfo;
// NSLog(@"%@", [localNotification description]);
// Schedule it with the app
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
如果要保留 NSNotification
的所有对象,则需要将其存储在某个地方。即在数组中。
您还可以使用以下方法进行 NSNotifications 操作。
- (void)cancelLocalNotification:(UILocalNotification *)notification
- (void)cancelAllLocalNotifications
确保您在
上收到通知-(void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
作为使用该对象之前的良好做法,请确保您已初始化并将所有值设置为特定对象。
请试试这个本地通知
-(void)localnotification{
NSDate *pickerDate = [self.datepicker date];
// Schedule the notification
UILocalNotification* localNotification = [[UILocalNotification alloc] init];
localNotification.fireDate = pickerDate;
localNotification.alertBody = self.labelname.text;
localNotification.alertAction = @"Show me the item";
localNotification.timeZone = [NSTimeZone defaultTimeZone];
localNotification.applicationIconBadgeNumber = [[UIApplication sharedApplication] applicationIconBadgeNumber] + 1;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
}