iOS之本地推送(前台模式与后台模式)
#import "AppDelegate.h"
#import "GlobalDefine.h"
@interface AppDelegate ()
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// 判断是否是8.0以上
if ([UIDevice currentDevice].systemVersion.floatValue >= 8.0) {
UIMutableUserNotificationCategory *category = [[UIMutableUserNotificationCategory alloc] init];
category.identifier = NotificationIdentifier;
UIMutableUserNotificationAction *foregroundAction = [[UIMutableUserNotificationAction alloc] init];
foregroundAction.identifier = foregroundActionidentifier;
foregroundAction.title = @"前台模式";
foregroundAction.activationMode = UIUserNotificationActivationModeForeground;
UIMutableUserNotificationAction *backgroundAction = [[UIMutableUserNotificationAction alloc] init];
backgroundAction.identifier = backgroundActionidentifier;
backgroundAction.title = @"后台模式";
backgroundAction.activationMode = UIUserNotificationActivationModeBackground;
[category setActions:@[foregroundAction, backgroundAction] forContext:UIUserNotificationActionContextDefault];
NSSet *set = [NSSet setWithObjects:category, nil];
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeBadge | UIUserNotificationTypeAlert | UIUserNotificationTypeSound categories: set];
[[UIApplication sharedApplication] registerUserNotificationSettings:settings];
}
return YES;
}
- (void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forRemoteNotification:(NSDictionary *)userInfo withResponseInfo:(NSDictionary *)responseInfo completionHandler:(void (^)())completionHandler {
if ([identifier isEqualToString:foregroundActionidentifier]) {
NSLog(@"ios9点击了前台模式");
}
completionHandler();
}
@end
______________________________________华丽的分割线_________________________________________________
#import "ViewController.h"
#import "GlobalDefine.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
UILocalNotification *notification = [[UILocalNotification alloc] init];
notification.fireDate = [NSDate dateWithTimeIntervalSinceNow:5]; // 推送时间
notification.alertTitle = @"推送"; // 推送标题
notification.alertBody = @"推送内容"; // 推送的内容
notification.category = NotificationIdentifier;
[[UIApplication sharedApplication] scheduleLocalNotification:notification];
}
@end
______________________________________华丽的分割线_________________________________________________
#ifndef GlobalDefine_h
#define GlobalDefine_h
#define NotificationIdentifier @"NotificationIdentifier"
#define backgroundActionidentifier @"backgroundAction.identifier"
#define foregroundActionidentifier @"foregroundAction.identifier"
#endif /* GlobalDefine_h */
PS: 最下面的 #ifndef GlobalDefine_h 头文件
可以全部复制进去运行,
iOS之本地推送(前台模式与后台模式)的更多相关文章
- iOS开发本地推送(iOS10)UNUserNotificationCenter
1.简介 iOS10之后苹果对推送进行了封装,UNUserNotificationCenter就这样产生了.简单介绍本地推送的使用UserNotifications官方文档说明! 2.简单使用UNUs ...
- iOS开发本地推送
1.简介 本地通知是由本地应用触发的,它是基于时间行为的一种通知形式,例如闹钟定时.待办事项提醒,又或者一个应用在一段时候后不使用通常会提示用户使用此应用等都是本地通知. 2.创建UILocalNot ...
- iOS的本地推送删除不了解决方法
最近在研究苹果推送,当测试本地推送的时候,发现一个问题,就是一旦你添加了一个本地推动的通知,当你修改代码,删除应用,当你再次运行app,它还是会在横幅上面弹出推送,尼玛怎么搞都删除不了,近乎崩溃了,开 ...
- iOS关于本地推送
不多说 直接上代码 NSDate *now = [NSDate date]; UILocalNotification *reminderNotification = [[UILocalNoti ...
- IOS中程序如何进行推送消息(本地推送,远程推送)
[1]-------------什么是推送消息? 我就以一张图解释------------ [2]-----------IOS程序中如何进行本地推送?----------- 2.1,先征求用户同意 1 ...
- IOS之推送通知(本地推送和远程推送)
推送通知和NSNotification是有区别的: NSNotification:是看不到的 推送通知:是可以看到的 IOS中提供了两种推送通知 本地推送通知:(Local Notification) ...
- 81、iOS本地推送与远程推送详解
一.简介 分为本地推送和远程推送2种.可以在应用没打开甚至手机锁屏情况下给用户以提示.它们都需要注册,注册后系统会弹出提示框(如下图)提示用户石否同意,如果同意则正常使用:如果用户不同意则下次打开程序 ...
- ios 开发之本地推送
网络推送可能被人最为重视,但是本地推送有时候项目中也会运用到: 闲话少叙,代码如下: 1.添加根视图 self.window.rootViewController = [[UINavigationCo ...
- IOS 本地推送(UILocalNotification)
推送通知 ● 注意:这里说的推送通知跟NSNotification有所区别 • NSNotification是抽象的,不可见的 • 推送通知是可见的(能用肉眼看到) ● iOS中提供了2种推送通知 ● ...
随机推荐
- UIImageView填充模式(contentMode)
UIViewContentModeScaleToFill :拉伸填充UIImageView满屏 UIViewContentModeScaleAspectFit :拉伸到合适UIIma ...
- android控制之 adb shell (已完成,不定期增加内容)
第一步:首先,下载adb1.0.32.zip,里面有如下图的内容: 第二步:解压缩,复制Adb.exe,和fastboot.exe到System32,注意AdbWinUsbApi.dll,AdbWin ...
- OpenRisc-39-ORPSoC,or1200的memory hierarchy整体分析
引言 前面我们简单分析了ORPSoC的整体结构,or1200_top的整体结构,or1200_cpu的整体结构. 并对ORPSoC的启动过程,ORPSoC的debug子系统,clock子系统进行了介绍 ...
- 表单同时有中文字段和文件上传,加上enctype="multipart/form-data"后导致的中文乱码问题
因为一个表单需要同时上传字段和文件,所以加上enctype="multipart/form-data",但是上传后的中文字段变成了乱码. 把enctype="multip ...
- java 编码转换
在网络中爬取到的数据,编码可能与当前编译器的编码不相同,而导致可能产生显示乱码的问题.那么如何将网络的编码,转换为当前编译器认可的编码(一般为UTF-8),就是个问题了. 主要使用了两个方法: Str ...
- 自定义VIew基础
一.坐标 ①.通过View获取坐标,通过调用getLeft().getRight()...方法获取坐标. 1.获取到的是相对于View父控件的位置 2.指的是左上角和右下角的x,y值 3.View还提 ...
- 一个人的旅行--hdu2066
一个人的旅行 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Subm ...
- UVA 10791 Minimum Sum LCM
唯一分解定理 把n分解为 n=a1^p1*a2^p2*...的形式,易得每个ai^pi作为一个单独的整数最优. 坑: n==1 ans=2: n因子种数只有一个 ans++: 注意溢出 ...
- 使用 Strace 和 GDB 调试工具的乐趣
编写 UNIX® 系统程序充满乐趣,并且具有教育意义.使用 UNIX strace 工具和 GDB(GNU 项目调试工具),您可以真正地深入研究系统的功能,并了解组成这些功能的各种各样的程序.同时使用 ...
- 【转】linux 关机命令总结
linux下常用的关机命令有:shutdown.halt.poweroff.init:重启命令有:reboot.下面本文就主要介绍一些常用的关机命令以及各种关机命令之间的区别和具体用法. 首先来看一下 ...