基本属性 - iOS中的本地通知

本文详细介绍如何在iOS应用中实现本地通知功能,包括创建通知、设置属性如触发时间、提示内容和声音等,以及如何调度通知并注册用户通知权限。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

本地通知的基本使用

 

  • 创建本地通知
  • 设置属性
  • 调度通知(添加通知到本地通知调度池)
  • 注册用户通知权限(只需一次, 可以单独放在Appdelegate中, 或者别的地方) —> iOS8以后必须, 需要用户授权才可以发送通知

 

 

   

 1 //1. 创建本地通知对象
 2         UILocalNotification *localNotifi = [UILocalNotification new];
 3         
 4         //2. 设置属性
 5         
 6         //2.1 设置触发时间
 7         localNotifi.fireDate = [NSDate dateWithTimeIntervalSinceNow:3];
 8         
 9         //2.2 设置提示内容
10         localNotifi.alertBody = @"我是通知";
11         
12         //2.3 设置声音 (只有真机有效)
13         localNotifi.soundName = UILocalNotificationDefaultSoundName;
14         
15         localNotifi.applicationIconBadgeNumber = 5;
16         
17         //2.4 设置 默认YES
18         localNotifi.hasAction = NO;
19         
20         //2.5 设置 提醒样式的按钮文字 / 锁屏界面底部的文字
21         localNotifi.alertAction = @"通知";
22         
23         // 将通知加入到本地调度池中
24         [[UIApplication sharedApplication] scheduleLocalNotification:localNotifi];
25         
26         // 注册通知设置
27         UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert categories:nil];
28             [[UIApplication sharedApplication] registerUserNotificationSettings:settings];

 

转载于:https://www.cnblogs.com/SmileCCBoy/p/iOS.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值