iOS 本地通知
来源:互联网 发布:windows装mac双系统 编辑:程序博客网 时间:2024/06/08 12:55
具体代码:
AppDelegate.m:
#pragma mark- 接收本地通知的方法
-(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];
}
/*
本地通知 UILocalNotification
操作流程:
1.接收通知
2.注册 发送通知
提示事件 闹钟
在AppDelegate 里面实现代码
*/
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self pushNotfation];
}
#pragma mark-注册发送通知的方法
-(void)pushNotfation
{
// 注册 发送通知
// 初始化 alloc init
UILocalNotification *not = [[UILocalNotification alloc]init];
// fireDate通知启动的时间
not.fireDate = [NSDate dateWithTimeIntervalSinceNow:10];
// 设置通知的标题
not.alertTitle = @"起床了";
// 设置通知的内容
not.alertBody = @"生前何必久睡,死后自会长眠";
// 通过通知 传递内容
not.userInfo = @{@"key":@"value"};
// 设置App图标上面红点显示的数字
not.applicationIconBadgeNumber = 1; //在远程通知的时候 是系统提供给我们的
// 重复发送通知的方法
/*
NSCalendarUnitEra = kCFCalendarUnitEra,一个世纪
NSCalendarUnitYear = kCFCalendarUnitYear,一年
NSCalendarUnitMonth = kCFCalendarUnitMonth,一个月
NSCalendarUnitDay = kCFCalendarUnitDay,天
NSCalendarUnitHour = kCFCalendarUnitHour,时
NSCalendarUnitMinute = kCFCalendarUnitMinute,分
NSCalendarUnitSecond = kCFCalendarUnitSecond,秒
NSCalendarUnitWeekday = kCFCalendarUnitWeekday,一个礼拜
NSCalendarUnitWeekdayOrdinal = kCFCalendarUnitWeekdayOrdinal,
*/
not.repeatInterval = kCFCalendarUnitDay;
// 注册通知
// 判断方法 是否可以响应某个方法
// [self respondsToSelector:<#(SEL)#>]
if ([[UIApplication sharedApplication] respondsToSelector:@selector(registerUserNotificationSettings:)]) {
[[UIApplication sharedApplication]registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeBadge|UIUserNotificationTypeSound|UIUserNotificationTypeAlert|UIUserNotificationTypeNone categories:nil]];
// UIUserNotificationTypeBadge| 圆圈内提示的数字UIUserNotificationTypeSound| 通知提示的声音UIUserNotificationTypeAlert|震动 UIUserNotificationTypeNone
}
not.soundName = UILocalNotificationDefaultSoundName;
// 发送通知
[[UIApplication sharedApplication]scheduleLocalNotification:not];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
- iOS 本地通知 远程通知
- iOS本地通知 远程通知
- iOS本地通知&定时通知
- iOS实现本地通知
- iOS本地通知
- iOS本地通知
- iOS本地通知UILocalNotification
- IOS实现本地通知
- IOS 本地通知 UILocalNotification
- ios本地通知UILocalNotification
- iOS UILocalNotification本地通知
- iOS实现本地通知
- iOS实现本地通知
- IOS实现本地通知
- iOS-本地通知
- IOS 本地通知
- IOS本地推送通知
- iOS本地通知:UILocalNotification
- Xcode6:模拟器消失了?
- Codeforces Round #321 (Div. 2) 580B. Kefa and Company
- Java 7之基础 - 强引用、弱引用、软引用、虚引用
- C语言中auto,register,static,const,volatile的区别
- 【转】JSTL 核心标签库 使用
- iOS 本地通知
- 获取目录及子目录下所有文件名
- Privacy Policy
- Codeforces Round #320 (Div. 2) 579B. Finding Team Member
- 欢迎使用CSDN-markdown编辑器
- 实验1正篇——引导PC
- Codeforces Round #320 (Div. 2)578B."Or" Game
- 黑马程序员——JavaSE之学习IO流的心得(一)
- Android 定时器的实现(一)