iOS本地通知的实现
来源:互联网 发布:上海数据交易中心 面试 编辑:程序博客网 时间:2024/06/05 01:51
/*
@property(nonatomic,copy) NSDate *fireDate; // 设置本地推送的时间
@property(nonatomic,copy) NSTimeZone *timeZone; // 时区
@property(nonatomic) NSCalendarUnit repeatInterval; // 重复多少个单元发出一次
@property(nonatomic,copy) NSCalendar *repeatCalendar; // 设置日期
@property(nonatomic,copy) CLRegion *region NS_AVAILABLE_IOS(8_0); // 比如某一个区域的时候发出通知
@property(nonatomic,assign) BOOL regionTriggersOnce NS_AVAILABLE_IOS(8_0); //进入区域是否重复
@property(nonatomic,copy) NSString *alertBody; 消息的内容
@property(nonatomic) BOOL hasAction; 是否显示alertAction的文字(默认是YES)
@property(nonatomic,copy) NSString *alertAction; 设置锁屏状态下,显示的一个文字
@property(nonatomic,copy) NSString *alertLaunchImage; 启动图片
@property(nonatomic,copy) NSString *soundName; UILocalNotificationDefaultSoundName
@property(nonatomic) NSInteger applicationIconBadgeNumber; 应用图标右上角的提醒数字
// user info
@property(nonatomic,copy) NSDictionary *userInfo;
*/
// 1.创建本地通知
UILocalNotification *localNote = [[UILocalNotificationalloc]init];
// 1.1.设置什么时间弹出
localNote.fireDate = [NSDatedateWithTimeIntervalSinceNow:5];
// 1.2.设置弹出的内容
localNote.alertBody = @"吃饭了吗?";
// 1.3.设置锁屏状态下,显示的一个文字
localNote.alertAction = @"快点打开";
// 1.4.显示启动图片
localNote.alertLaunchImage = @"123";
// 1.5.是否显示alertAction的文字(默认是YES)
localNote.hasAction = YES;
// 1.6.设置音效
localNote.soundName =UILocalNotificationDefaultSoundName;
// 1.7.应用图标右上角的提醒数字
localNote.applicationIconBadgeNumber =999;
// 1.8.设置UserInfo来传递信息
localNote.userInfo = @{@"alertBody" : localNote.alertBody,@"applicationIconBadgeNumber" :@(localNote.applicationIconBadgeNumber)};
// 2.调度通知
[[UIApplicationsharedApplication]scheduleLocalNotification:localNote];
iOS8 以后需要设置
/**
* 如果应用在后台,通过点击通知的时候打开应用会来到该代理方法
* 如果应用在前台,接受到本地通知就会调用该方法
*
* @param notification通过哪一个通知来这里
*/
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{
// if (application.applicationState == UIApplicationStateActive) return;
// if (application.applicationState == UIApplicationStateInactive) {
// NSLog(@"跳转");
// }
UILabel *label = [[UILabelalloc]init];
label.frame = CGRectMake(0, 0, 300, 300);
label.backgroundColor = [UIColorredColor];
label.text = [NSStringstringWithFormat:@"%@", notification];
label.font = [UIFontsystemFontOfSize:14.0];
label.numberOfLines = 0;
[self.window.rootViewController.viewaddSubview:label];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
/*
UIUserNotificationTypeNone = 0, 没有,没有本地通知
UIUserNotificationTypeBadge = 1 << 0, 接受图标右上角提醒数字
UIUserNotificationTypeSound = 1 << 1, 接受通知时候,可以发出音效
UIUserNotificationTypeAlert = 1 << 2, 接受提醒(横幅/弹窗)
*/
// iOS8需要添加请求用户的授权
if ([UIDevicecurrentDevice].systemVersion.floatValue >=8.0) {
UIUserNotificationSettings *settings = [UIUserNotificationSettingssettingsForTypes:UIUserNotificationTypeBadge |UIUserNotificationTypeAlert | UIUserNotificationTypeSoundcategories:nil];
[application registerUserNotificationSettings:settings];
}
// iOS 中本地通知启动的程序 launchOptions 的键名 UIApplicationLaunchOptionsLocalNotificationKey会有值
if (launchOptions[UIApplicationLaunchOptionsLocalNotificationKey]) {
UILabel *label = [[UILabelalloc]init];
label.frame = CGRectMake(0, 300, 300, 300);
label.backgroundColor = [UIColorblueColor];
label.text = [NSStringstringWithFormat:@"%@", launchOptions];
label.font = [UIFontsystemFontOfSize:14.0];
label.textColor = [UIColorwhiteColor];
label.numberOfLines = 0;
[self.window.rootViewController.viewaddSubview:label];
}
return YES;
}
- iOS本地通知的实现
- iOS 本地通知的实现
- iOS本地通知的实现
- iOS 本地通知的实现
- iOS实现本地通知
- IOS实现本地通知
- iOS实现本地通知
- iOS实现本地通知
- IOS实现本地通知
- IOS本地通知实现
- ios-实现本地通知(UILocalNotification)
- ios 本地通知(UILocalNotification)的学习和使用(通过本地通知实现提醒功能)
- iOS实现本地通知(local notification)的方法
- 【iOS开发】UILocalNotification 本地通知的实现 —— 伊禾媛
- (七十三)iOS本地推送通知的实现
- iOS的本地通知tishikuang
- iOS中 本地通知/本地通知详解 韩俊强的博客
- iOSAPP本地通知的实现
- iOS学习之关于#import导入补全问题
- 计算机进程
- CF#201 div2 C Alice and Bob(number theory)
- 操作系统文件管理
- SpringMVC注解@RequestParam全面解析
- iOS本地通知的实现
- Fiddler工具——手机抓包
- RecyclerView GridLayoutManager实现复杂的列数变化的布局
- MyEclipse下Maven的安装配置以及运行
- 9,累加思想与计数思想
- HUD 1394 归并求逆序数
- As of ADT 14, resource fields cannot be used as switch cases
- 数据库基础
- defwindowproc与pretranslatemessage有什么区别