ios 本地通知
来源:互联网 发布:淘宝详情页面设计 编辑:程序博客网 时间:2024/06/07 11:42
在iOS中 相对于远程通知 本地通知要简单得多 只有两个地方写点代码就能实现
本地通知(UILocalNotification) 操作流程
1.接收通知(接收通知对象)
-(void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification{
// 接收通知操作
}
2.注册发送通知(需注意iOS8之后的改动)
- (void)pushNotification{// 注册发送通知的方法// 初始化 UILocalNotification alloc init UILocalNotification *not = [[UILocalNotification alloc]init];// 设置启动时间 not.fireDate = [NSDate dateWithTimeIntervalSinceNow:10];// 设置通知的标题 not.alertTitle = @"时间到";// 设置通知的内容 not.alertBody = @"起床敲代码";// 通过通知 传递内容 not.userInfo = @{@"key":@"value"};// 设置app图标上面红点显示的数字 not.applicationIconBadgeNumber = 1;// 注册通知// iOS8之前 not.soundName = UILocalNotificationDefaultSoundName; // NSCalendarUnitEra = kCFCalendarUnitEra,// NSCalendarUnitYear = kCFCalendarUnitYear,// NSCalendarUnitMonth = kCFCalendarUnitMonth,// NSCalendarUnitDay = kCFCalendarUnitDay,// NSCalendarUnitHour = kCFCalendarUnitHour,// NSCalendarUnitMinute = kCFCalendarUnitMinute,// NSCalendarUnitSecond = kCFCalendarUnitSecond,// NSCalendarUnitWeekday = kCFCalendarUnitWeekday,// NSCalendarUnitWeekdayOrdinal = kCFCalendarUnitWeekdayOrdinal, not.repeatInterval = NSCalendarUnitDay;// 判断是否可以响应某个方法// [self respondsToSelector:<#(SEL)#>]// UIUserNotificationTypeBadge| 圆圈内提示的数字// UIUserNotificationTypeSound| 通知提示的声音// UIUserNotificationTypeNone|// UIUserNotificationTypeAlert 振动 if ([[UIApplication sharedApplication] respondsToSelector:@selector(registerUserNotificationSettings:)]) { [[UIApplication sharedApplication]registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeBadge|UIUserNotificationTypeSound|UIUserNotificationTypeAlert categories:nil]]; }// 发送通知 [[UIApplication sharedApplication]scheduleLocalNotification:not]; }
//接收本地通知-(void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification{// 接收通知操作 NSLog(@"通知内容 %@",notification.userInfo); UIAlertView *alert = [[UIAlertView alloc]initWithTitle:notification.alertTitle message:notification.alertBody delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil]; [alert show];}
0 0
- iOS 本地通知 远程通知
- iOS本地通知 远程通知
- iOS本地通知&定时通知
- iOS实现本地通知
- iOS本地通知
- iOS本地通知
- iOS本地通知UILocalNotification
- IOS实现本地通知
- IOS 本地通知 UILocalNotification
- ios本地通知UILocalNotification
- iOS UILocalNotification本地通知
- iOS实现本地通知
- iOS实现本地通知
- IOS实现本地通知
- iOS-本地通知
- IOS 本地通知
- IOS本地推送通知
- iOS本地通知:UILocalNotification
- Centos 7 安装 vim自动补全神器 YouCompleteMe
- bnuoj 39566 Do use segment tree(树链剖分)
- iOS中的定时器
- 【计蒜客】难题题库 004 简单斐波那契
- Mac下如何安装调试apk
- ios 本地通知
- 起泡排序/快速排序
- 实现队列的MAX函数:返回队列中的最大值
- C++初始化变量
- PHP学习笔记(03)—— 控制结构
- RadioGroup+ViewPager+Fragment
- 当字符数组中没有结束符'\0'
- 黑马程序员----Objective-C学习笔记之内存管理的原则
- hdu 5130(2014广州 圆与多边形相交模板)