UILocalNotification本地通知
// 执行通知一定要退出应用或挂起应用(进入后台)才能收到通知。
// 创建本地通知
UILocalNotification *notification = [[UILocalNotification alloc] init];
// 通知触发时间
// 5秒钟之后触发 notification.fireDate = [NSDate dateWithTimeIntervalSinceNow:5];
// 通知时区
// 使用本地时区 notification.timeZone = [NSTimeZone defaultTimeZone];
// 通知提示内容
notification.alertBody = @"顶部提示内容,您有有一个通知";
// 通知提示音
//使用默认的通知提示音 notification.soundName = UILocalNotificationDefaultSoundName;
// 应用程序右上角显示的数字
notification.applicationIconBadgeNumber = 1;
// 数据字典
notification.userInfo = @{@"userName": @"小明", @"age": @(18)};
// 启动这个通知
[[UIApplication sharedApplication] scheduleLocalNotification:notification];
// 进入前台,清除右上角图标
- (void)applicationWillEnterForeground:(UIApplication *)application { [application setApplicationIconBadgeNumber:0]; }
// 点顶端通知进入应用
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"标题" message:notification.userInfo[@"userName"] delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil]; [alert show]; }
// 清除当前应用所有通知
[[UIApplication sharedApplication] cancelAllLocalNotifications];
【推荐】还在用 ECharts 开发大屏?试试这款永久免费的开源 BI 工具!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· ASP.NET Core 模型验证消息的本地化新姿势
· 对象命名为何需要避免'-er'和'-or'后缀
· SQL Server如何跟踪自动统计信息更新?
· AI与.NET技术实操系列:使用Catalyst进行自然语言处理
· 分享一个我遇到过的“量子力学”级别的BUG。
· C# 中比较实用的关键字,基础高频面试题!
· .NET 10 Preview 2 增强了 Blazor 和.NET MAUI
· 为什么AI教师难以实现
· 如何让低于1B参数的小型语言模型实现 100% 的准确率
· AI Agent爆火后,MCP协议为什么如此重要!