iOS Notification(本地通知)
代码
#import "ViewController.h" @interface ViewController () @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. } /** // 触发时间 @property(nullable, nonatomic,copy) NSDate *fireDate; // 时区 @property(nullable, nonatomic,copy) NSTimeZone *timeZone; // 重复 --> 单位是日历组件 , 0 代表不重复 @property(nonatomic) NSCalendarUnit repeatInterval; // 重复 --> 上面那个属性所依赖的日历格式 公历 农历 @property(nullable, nonatomic,copy) NSCalendar *repeatCalendar; // 区域 @property(nullable, nonatomic,copy) CLRegion *region NS_AVAILABLE_IOS(8_0); // 区域只检测一次 @property(nonatomic,assign) BOOL regionTriggersOnce NS_AVAILABLE_IOS(8_0); // 提醒的主题内容 @property(nullable, nonatomic,copy) NSString *alertBody; // 是否显示锁屏时的文字以及提醒样式的按钮文字 @property(nonatomic) BOOL hasAction; // 设置显示锁屏时的文字以及提醒样式的按钮文字 @property(nullable, nonatomic,copy) NSString *alertAction; // 设置启动图 @property(nullable, nonatomic,copy) NSString *alertLaunchImage; // 设置标题 @property(nullable, nonatomic,copy) NSString *alertTitle // 设置声音 , 默认声音: UILocalNotificationDefaultSoundName @property(nullable, nonatomic,copy) NSString *soundName; // 设置图标的数字角标 (图标标记) @property(nonatomic) NSInteger applicationIconBadgeNumber; // 0 means no change. defaults to 0 // 设置携带参数 @property(nullable, nonatomic,copy) NSDictionary *userInfo; // 设置分类 @property (nullable, nonatomic, copy) NSString *category */ #pragma mark 点击发送本地通知 - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event { //1. 创建本地通知对象 UILocalNotification *localNotifi = [UILocalNotification new]; //2. 设置属性 //2.1 设置触发时间 localNotifi.fireDate = [NSDate dateWithTimeIntervalSinceNow:3]; //2.2 设置提示内容 localNotifi.alertBody = @"今天不适合敲代码"; //2.3 设置声音 (只有真机有效) localNotifi.soundName = UILocalNotificationDefaultSoundName; localNotifi.applicationIconBadgeNumber = 5; //2.4 设置 默认YES localNotifi.hasAction = NO; //2.5 设置 提醒样式的按钮文字 / 锁屏界面底部的文字 localNotifi.alertAction = @"回复呵呵"; #pragma mark 不常用属性 //2.6 设置重复 最小单位是分钟 如果此属性设置了, 那么调度池不会用完释放 //localNotifi.repeatInterval = NSCalendarUnitMinute; //2.7 设置重复所依赖的日历 不设置的话, 默认是跟随系统设置走得 // 默认就是跟随系统走 //localNotifi.repeatCalendar = [NSCalendar calendarWithIdentifier:@"跳进官方文档, 里面就有一堆的标示符, 找chinese的选项, 就代表是农历"]; //3. 调度通知 , 如果是IOS7 , 这一步写完就OK //schedule : 调度 // 将通知加入到本地调度池中 [[UIApplication sharedApplication] scheduleLocalNotification:localNotifi]; //4. iOS8 需要增加一个方法 --> 需要授权 /** UIUserNotificationTypeNone = 0, UIUserNotificationTypeBadge = 1 << 0, //图标标记 UIUserNotificationTypeSound = 1 << 1, //声音 UIUserNotificationTypeAlert = 1 << 2, //提醒 */ UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert categories:nil]; [[UIApplication sharedApplication] registerUserNotificationSettings:settings]; //5. 删除通知 // 删除当前程序注册的所有通知 [[UIApplication sharedApplication] cancelAllLocalNotifications]; // 删除指定的通知 --> 一般用于干掉会重复的通知 / 或者还没有被调用的通知 //[[UIApplication sharedApplication] cancelLocalNotification:localNotifi]; // 获取通知 --> 配合删除用的 NSArray *localNotifications = [[UIApplication sharedApplication] scheduledLocalNotifications]; for (UILocalNotification *local in localNotifications) { NSLog(@"local: %@", local); } // 如果是当前程序内收到了通知, 那么界面没有任何变化 } @end

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。
持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。
转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。
- 上一篇
iOS QRCode(二维码)
实现思路 输入设备(用来获取外界信息) 摄像头, 麦克风, 键盘 输出设备 (将收集到的信息, 做解析, 来获取收到的内容) 会话session (用来连接输入和输出设备) 特殊的layer (展示输入设备所采集的信息) 1. 导包 #import <AVFoundation/AVFoundation.h> 2. 代码 #import "ViewController.h" #import <AVFoundation/AVFoundation.h> @interface ViewController ()<AVCaptureMetadataOutputObjectsDelegate> //1. 输入设备(用来获取外界信息) 摄像头, 麦克风, 键盘 @property (nonatomic, strong) AVCaptureDeviceInput *input; //2. 输出设备 (将收集到的信息, 做解析, 来获取收到的内容) @property (nonatomic, strong) AVCaptureMetadataOutput *outpu...
- 下一篇
iOS Spin(换肤)
MTSkinTools.h #import <UIKit/UIKit.h> //专门写常量值的 // 以下的格式, 只是对常量的声明 //extern: 代表其他类可以引用 extern NSString *const MTSkinToolLabelTextDayColor; extern NSString *const MTSkinToolLabelBackgroundDayColor; @interface MTSkinTools : NSObject /** 返回对应的皮肤的图像*/ + (UIImage *)imageWithImageName:(NSString *)imageName; /** 保存皮肤信息*/ + (void)saveSkinName:(NSString *)skinName; /** 返回制定标识符所对应的颜色*/ + (UIColor *)colorWithName:(NSString *)name; @end MTSkinTools.m #import "MTSkinTools.h" //专门写常量值的 // 以下的格式, 只是对常量的声...
相关文章
文章评论
共有0条评论来说两句吧...
文章二维码
点击排行
推荐阅读
最新文章
- 设置Eclipse缩进为4个空格,增强代码规范
- CentOS7,CentOS8安装Elasticsearch6.8.6
- CentOS7编译安装Gcc9.2.0,解决mysql等软件编译问题
- CentOS8安装Docker,最新的服务器搭配容器使用
- CentOS6,7,8上安装Nginx,支持https2.0的开启
- CentOS8安装MyCat,轻松搞定数据库的读写分离、垂直分库、水平分库
- Docker安装Oracle12C,快速搭建Oracle学习环境
- Hadoop3单机部署,实现最简伪集群
- SpringBoot2初体验,简单认识spring boot2并且搭建基础工程
- Windows10,CentOS7,CentOS8安装MongoDB4.0.16