我有一个表单,用户填写所有信息,如姓名,事件名称,提醒日期等。所以我做的是根据这样的键设置通知
- (void)scheduleNotificationForNotificationID:(NSString *)notificationID1:(NSString *)notificationID2:(NSString *)notificationKey
{
//Set notification after confirmation of saved data
Class cls = NSClassFromString(@"UILocalNotification");
reminderNotification = [[cls alloc] init];
if (cls != nil)
{
NSDateFormatter *dateFormat = [[[NSDateFormatter alloc]init]autorelease];
[dateFormat setDateFormat:@"YYYY-MM-dd HH:mm:ss"];
NSDate *notificationDate = [dateFormat dateFromString:textField2.text];
reminderNotification.fireDate = notificationDate;
reminderNotification.timeZone = [NSTimeZone defaultTimeZone];
NSString *reminderText = [NSString stringWithFormat:@"%@ 's %@ on %@",textField.text,textField1.text,strDate];
reminderNotification.alertBody = reminderText;
reminderNotification.alertAction = @"View";
reminderNotification.soundName = @"apple_ring.mp3";
reminderNotification.applicationIconBadgeNumber = 1;
//Use name and event name as keys
NSDictionary *infoDict = [NSDictionary dictionaryWithObjectsAndKeys:notificationID1,@"Name",notificationID2,@"Event",notificationKey,@"Date",nil];
reminderNotification.userInfo = infoDict;
[[UIApplication sharedApplication] scheduleLocalNotification:reminderNotification];
}
}
textField保存Name和 textField1保存事件名称
所以我有一个保存按钮动作来保存每个提醒,如果按钮标题是“保存”,它将保存提醒并插入新记录,如果它是“完成”,它将编辑提醒细节和记录将更新。
现在通知的问题是不是不正确的射击或不射击等问题。问题是通知警报正文,这是接收本地通知的代码:
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{
application.applicationIconBadgeNumber = 0;
NSString *reminderText = [notification.userInfo objectForKey:kReminder];
[self.addViewController performSelector:@selector(showReminder:) withObject:reminderText afterDelay:1];
}
所以这是通知警报正文的行动
//Notification alert
- (void)showReminder:(NSString *)text
{
self.reminderAlert = [[UIAlertView alloc] initWithTitle:@"Reminder" message:reminderNotification.alertBody delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil];
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(220, 10, 40, 40)];
UIImage *image= [UIImage imageNamed:@"icon@2x.png"];
[imageView setImage:image];
[reminderAlert addSubview:imageView];
[imageView release];
[reminderAlert show];
[reminderAlert release];
}
现在,在我编辑提醒/记录详细信息之后,以前的通知会被取消,但我的问题是警报正文与通知警报正文不同,即。通知警报正在更新,但不是警报正文,即根据名称和事件名称,例如:
“史蒂夫约伯7月3日的生日”,如果这是保存时的初始事件 如果用户更新/更改为“史蒂夫乔布斯7月3日的费用”
警报正在保存上一个事件名称值,其中通知警报正在保存正确且正确更新的新提醒详细信息。如果标题是保存,我尝试分配一个警报正文,如果标题已完成,则尝试指定另一个值,我的意思是我拿了几个字符串来保存名称和事件名称的值,对于保存和完成的操作,全局声明字符串,尝试在完成操作等分配提醒体之前使字符串值为nil ...没有用!
因此我分配了提醒通知警报正文。即使这不起作用:(
我哪里错了...... ???
请帮助我,并提前感谢所有人:)
答案 0 :(得分:1)
我找到了一个适当的解决方案,用于将文本分配给提醒警报正文,即。因为我们正在根据三个键保存通知:
NSDictionary *infoDict = [NSDictionary dictionaryWithObjectsAndKeys:notificationID1,@"Name",notificationID2,@"Event",notificationKey,@"Date",nil];
我们可以使用这些键为警报视图分配文本/正文,例如:
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{
application.applicationIconBadgeNumber = 0;
NSString *name = [notification.userInfo objectForKey:@"Name"];
NSString *event = [notification.userInfo objectForKey:@"Event"];
//Get the date of event and convert it to required format...
NSString *date = [notification.userInfo objectForKey:@"Date"];
NSDateFormatter *dateFormat = [[[NSDateFormatter alloc] init]autorelease];
[dateFormat setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
NSDate *dateVal = [dateFormat dateFromString:date];
[dateFormat setDateFormat:@"MMMM dd"];
NSString *eventDate = [dateFormat stringFromDate:dateVal];
NSString *reminderText = [NSString stringWithFormat:@"%@'s %@ on %@", name, event, eventDate];
[self.addViewController performSelector:@selector(showReminder:) withObject:reminderText afterDelay:1];
}
我们不必担心showReminderAction中的任何文本分配,即:
- (void)showReminder:(NSString *)text
{
self.reminderAlert = [[UIAlertView alloc] initWithTitle:@"Reminder" message:text delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil];
[reminderAlert show];
[reminderAlert release];
}
那应该让事情顺其自然,希望这对一些人有所帮助,谢谢:)