我制作了一个示例应用程序来激发本地通知。
当通知触发时,它始终在设备的通知区域中显示横幅,我已在图像中显示。
但我想提醒而不是这个,并希望根据该警报中的选定选项执行操作。
点击本地通知的代码如下。
-(IBAction)setNotification:(id)sender{
UILocalNotification *localNotif = [[UILocalNotification alloc] init];
if (localNotif == nil)
{
return;
}
localNotif.timeZone = [NSTimeZone defaultTimeZone];
// Get the year, month, day from the date
NSDateComponents *components = [[NSCalendar currentCalendar] components:NSYearCalendarUnit|NSMonthCalendarUnit|NSDayCalendarUnit|NSTimeZoneCalendarUnit|NSSecondCalendarUnit|NSHourCalendarUnit|NSMinuteCalendarUnit fromDate:[NSDate date]];
// Set the second to be zero
components.minute = components.minute + 1;
components.second = 0;
// Create the date
NSDate *date = [[NSCalendar currentCalendar] dateFromComponents:components];
NSLog(@"Fire Date :: %@",date);
localNotif.fireDate = date;
localNotif.alertBody = [NSString stringWithFormat:@"First Alarm"];
localNotif.alertAction =@"Ok";
localNotif.soundName=@"Alarm_1.mp3";
localNotif.applicationIconBadgeNumber = 1;
localNotif.alertAction = @"Application name";
localNotif.HasAction = true;
// Schedule the notification
[[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
}
如果有任何错误,请告诉我。
提前致谢。
答案 0 :(得分:0)
更改设置中的通知类型 - >通知中心 - >你的应用 - >警报:
最初来自Quinn“The Eskimo!”,quoted by IBG:
“这取决于你的意思。你可以控制自己的意思 根据您设置UILocalNotification的方式显示通知 属性(诸如alertBody,soundName等)。但是,如果 你问的是这些属性的解释方式 (用户可以在“设置”>“通知”中自定义的内容) 是用户首选项,不通过任何API公开。“
答案 1 :(得分:0)
这是一个简短的答案。你不能这样做。 苹果文档仅说明didReceiveLocalNotification。显示通知的方式不取决于开发人员。用户将使用SETTINGS选择他想要查看通知的方式。
在您的情况下,只需在用户点击通知时通过实施委托回调来连接逻辑。
答案 2 :(得分:-1)
您可以通过此方法收到通知:
编写此代码以从userInfo获取数据:
[[userInfo objectForKey:@“aps”] objectForKey:@“price”]];
使用userInfo Dict获取通知值,之后您可以将该数据用于Alert。