ios本地推送
#import "AppDelegate.h"
@interface AppDelegate ()
@end
@implementation AppDelegate
//无论程序在前后台运行,只要接收到通知,就会调用此方法
-(void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{
NSLog(@"%@",notification);
//添加控件,接收显示到的信息
UILabel *label=[[UILabel alloc]initWithFrame:CGRectMake(100, 100, 100, 100)];
label.backgroundColor=[UIColor grayColor];
label.text=[NSString stringWithFormat:@"%@",notification];
[self.window.rootViewController.view addSubview:label];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
UILocalNotification *info=launchOptions[UIApplicationLaunchOptionsLocalNotificationKey];
if (info) {
UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 320, 300)];
label.backgroundColor = [UIColor orangeColor];
[self.window.rootViewController.view addSubview:label];
//取出携带信息
label.numberOfLines = 0;
//NSDictionary *dict = info[@"UIConcreteLocalNotification"];
// NSArray *keys = [info allKeys];
//for (NSString *str in keys) {
// label.text = [NSString stringWithFormat:@"%@",str];
//}
//NSDictionary *dict1 = dict[@"user info"];
label.text = [NSString stringWithFormat:@"%@",info.userInfo];
//跳转对应的界面
}
return YES;
}
@end
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
//iOS8之后 需要注册通知类型 包含哪些(声音,图标文字,文本) 信息
/*
UIUserNotificationTypeNone = 0,
UIUserNotificationTypeBadge = 1 << 0, 包含图标文字 0001
UIUserNotificationTypeSound = 1 << 1, // 声音 0010
UIUserNotificationTypeAlert = 1 << 2, // 主题内容 0100
*/
UIUserNotificationSettings *setting=[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeBadge|UIUserNotificationTypeSound categories:nil];
//注册通知
[[UIApplication sharedApplication]registerUserNotificationSettings:setting];
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
//创建本地通知
UILocalNotification *local=[[UILocalNotification alloc]init];
local.alertBody=@"老易:你为什么这么爱生气?";
local.fireDate=[NSDate dateWithTimeIntervalSinceNow:3];
local.soundName=UILocalNotificationDefaultSoundName;
local.alertAction=@"约";
local.applicationIconBadgeNumber=5;
local.userInfo=@{@"name":@"大易",@"age":@"18"};
//定制通知
[[UIApplication sharedApplication]scheduleLocalNotification:local];
// //立即发送通知
// [[UIApplication sharedApplication]presentLocalNotificationNow:local];
// //取消本地所有通知
// [[UIApplication sharedApplication]cancelAllLocalNotifications];
/*
// timer-based scheduling 定制 特定的时间发出通知
@property(nonatomic,copy) NSDate *fireDate; 触发 时间
@property(nonatomic,copy) NSTimeZone *timeZone; 时区
@property(nonatomic) NSCalendarUnit repeatInterval; 重复间隔 // 0 means don't repeat
@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); //决定区域的一个bool值
// alerts
@property(nonatomic,copy) NSString *alertBody; 提醒的主题
@property(nonatomic) BOOL hasAction; // NO 不显示滑动解锁的按钮 反之 显示
@property(nonatomic,copy) NSString *alertAction; //滑动解锁的文字
@property(nonatomic,copy) NSString *alertLaunchImage; //点击通知横幅的启动程序的 启动 图片
@property(nonatomic,copy) NSString *alertTitle 提示的标题文字
// sound 默认: UILocalNotificationDefaultSoundName
@property(nonatomic,copy) NSString *soundName;
// badge
@property(nonatomic) NSInteger applicationIconBadgeNumber; //图标文字
// user info
@property(nonatomic,copy) NSDictionary *userInfo; // 用户指定的携带参数
[UIUserNotificationSettings settingsForUserNotificationTypes:userNotificationActionSettings:]
@property (nonatomic, copy) NSString *category NS_AVAILABLE_IOS(8_0);分类
*/
}
@end
ios本地推送的更多相关文章
- (七十三)iOS本地推送通知的实现
iOS的推送通知分为本地推送和网络推送两种,如果App处于挂起状态,是可以发送本地通知的,如果已经被杀掉,则只有定时通知可以被执行,而类似于QQ的那种网络消息推送就无法实现了,因为App的网络模块在被 ...
- 81、iOS本地推送与远程推送详解
一.简介 分为本地推送和远程推送2种.可以在应用没打开甚至手机锁屏情况下给用户以提示.它们都需要注册,注册后系统会弹出提示框(如下图)提示用户石否同意,如果同意则正常使用:如果用户不同意则下次打开程序 ...
- IOS 本地推送(UILocalNotification)
推送通知 ● 注意:这里说的推送通知跟NSNotification有所区别 • NSNotification是抽象的,不可见的 • 推送通知是可见的(能用肉眼看到) ● iOS中提供了2种推送通知 ● ...
- iOS 本地推送通知
1.什么是本地推送通知 不需要联网的情况下,应用程序经由系统发出的通知 2.本地推送的使用场景 定时提醒,如玩游戏.记账.闹钟.备忘录等 3.实现本地推送通知的步骤 创建本地推送通知的对象UILoca ...
- IOS 本地推送 IOS10.0以上 static的作用 const的作用
//需要在AppDelegate里面启动APP的函数 加上 UIUserNotificationType types = UIUserNotificationTypeBadge | UIUserNot ...
- iOS本地推送与远程推送
原文在此 分为本地推送和远程推送2种.可以在应用没有打开甚至手机锁屏情况下给用户以提示.它们都需要注册,注册后系统会弹出提示框(如下图)提示用户是否同意,如果同意则正常使用:如果用户不同意则下次打开程 ...
- [转载]iOS本地推送-备用
第一步:创建本地推送// 创建一个本地推送UILocalNotification *notification = [[[UILocalNotification alloc] init] autorel ...
- iOS本地推送与远程推送详解
一.简介 分为本地推送和远程推送2种.可以在应用没有打开甚至手机锁屏情况下给用户以提示.它们都需要注册,注册后系统会弹出提示框(如下图)提示用户是否同意,如果同意则正常使用:如果用户不同意则下次打开程 ...
- IOS 本地推送
// 1.打开本地推送并设置属性 NSString *str = @"本地推送的信息"; UIApplication *app = [UIApplication sharedApp ...
随机推荐
- POJ 3009
http://poj.org/problem?id=3009 一个搜索的题目: 大意就是一个冰球,在冰面上滑动,你打击一次,就沿一个反向滑动,知道碰到墙就会停下,而墙则会破碎. 求从起点到终点的最短的 ...
- 修改UINavigationController返回按钮颜色
系统默认颜色是蓝色的 视觉效果非常难看 在push进的ViewController中写 //修改UINavigationController的文字颜色 self.navigationControlle ...
- event.srcElement 用法笔记e.target
event.srcElement 可以捕获当前事件作用的对象,如event.srcElement.tagName可以捕获活动标记名称. 注意获取的标记都以大写表示,如"TD",&q ...
- LeetCode 263 Ugly Number
Problem: Write a program to check whether a given number is an ugly number. Ugly numbers are positiv ...
- [Android] 关于getinstalledpackages参数的分析
reference to : http://blog.csdn.net/luojiusan520/article/details/47696891 getinstalledpackages()的方法 ...
- String[] a = new String[]{"1","2"},我如果想增加一个"3"到a中,如何增加?
在java中数组是定长的,当你声明了数组的大小后数组的长度就不能改变在你的程序中,数组的初始化大小为2,a[0]="1";a[1]="2",所以无法产生元素a[ ...
- ajaxFileUpload上传文件没反应
调用jquery的ajaxFileUpload异步上传文件,IE浏览器不进入success问题 原因:json转换异常,ie浏览器处理后的返回json没有<pre>标签,直接是完整的jso ...
- Http返回码
HTTP协议状态码表示的意思主要分为五类 ,大体是 : ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1×× 保留 2×× 表示请求成功地接收 3×× 为完成请求客户需 ...
- hdu1722(gcd)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1722 题意:要使一块蛋糕既能均分给a个人,又能均分给b个人,问至少需要分成几块(不需要每块都一样大小) ...
- Scrapy爬取美女图片 (原创)
有半个月没有更新了,最近确实有点忙.先是华为的比赛,接着实验室又有项目,然后又学习了一些新的知识,所以没有更新文章.为了表达我的歉意,我给大家来一波福利... 今天咱们说的是爬虫框架.之前我使用pyt ...