是否可以在iPhone中更新本地通知 [英] Is it possible to update the local notification in iPhone
本文介绍了是否可以在iPhone中更新本地通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经按以下方式添加了本地通知:
I have added a local notification programmatically like below:
UILocalNotification *eventLocalNotification=[[UILocalNotification alloc]init];
eventLocalNotification.fireDate=myDate;
eventLocalNotification.timeZone=[NSTimeZone defaultTimeZone];
eventLocalNotification.alertBody=@"My notification";
eventLocalNotification.soundName=UILocalNotificationDefaultSoundName;
我可以更改firingDate,timeZone,alertBody或任何其他财产吗?
Can I change the firingDate, timeZone, alertBody, or any other property?
推荐答案
经过互联网搜索后,我得到的一件事我们不能编辑
a UILocal通知一旦添加。但确定我找到了另一种方式。
After searching a lot over internet, I got a thing that we can't edit
a UILocal Notification once added. But sure there is another way that I have found.
- 获取设备的所有本地通知。
- 搜索相应的本地通知
- 取消该通知
- 创建新通知
- Get all the Local notification of your device.
- Search the respective local notification
- Cancel that notification
- Create a New one
以下是添加通知的方法。
-(void)setLocalNotification
{
UILocalNotification *eventLocalNotification = [[UILocalNotification alloc]init];
eventLocalNotification.fireDate = //set firing Date of NSDate type
eventLocalNotification.timeZone = [NSTimeZone defaultTimeZone];
eventLocalNotification.alertBody = [NSString stringWithFormat:@"An event has arrived\n Event Name: %@",notificationName.Text];
eventLocalNotification.soundName = UILocalNotificationDefaultSoundName;
if ([repeat isEqualToString:@"Once"]){
eventLocalNotification.repeatInterval = 0;
}else if ([repeat isEqualToString:@"Daily"]){
eventLocalNotification.repeatInterval = NSDayCalendarUnit;
}else if ([repeat isEqualToString:@"Weekly"]){
eventLocalNotification.repeatInterval = NSWeekCalendarUnit;
}else if ([repeat isEqualToString:@"Monthly"]){
eventLocalNotification.repeatInterval = NSMonthCalendarUnit;
}else if ([repeat isEqualToString:@"Yearly"]){
eventLocalNotification.repeatInterval = NSYearCalendarUnit;
}
NSDictionary *info = [NSDictionary dictionaryWithObject:[NSString stringWithFormat:@"%@",notificationName.text] forKey:@"name"];
eventLocalNotification.userInfo = info;
NSLog(@"notification userInfo gets name : %@",[info objectForKey:@"name"]);
[[UIApplication sharedApplication] scheduleLocalNotification:eventLocalNotification];
NSLog(@"Notification created");
}
以下是取消通知的功能
-(void)cancelLocalNotification
{
UILocalNotification * notificationToCancel=nil;
for(UILocalNotification * aNotif in [[UIApplication sharedApplication] scheduledLocalNotifications])
{
NSLog(@"%@",[aNotif.userInfo objectForKey:@"name"]);
if([[aNotif.userInfo objectForKey:@"name"] isEqualToString:notificationName ])
{
notificationToCancel = aNotif;
[[UIApplication sharedApplication] cancelLocalNotification:notificationToCancel];
NSLog(@"Notification Cancelled");
break;
}
}
}
希望你会从中受益。运气最佳
Hope you will get benefit from it. Best of Luck
这篇关于是否可以在iPhone中更新本地通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文