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种推送通知 ● ...
随机推荐
- js实现楼层效果
今天自己写个楼层效果,有一点烦躁,小地方犯错误.各位大神来修改不足啊!!! <!DOCTYPE html><html lang="en"><head& ...
- JedisPool操作
Jedis 使用 commons-pool 完成池化实现. 先做个配置文件(properties文件): #最大分配的对象数 redis.pool.maxActive=1024 #最大能够保持idel ...
- mysql-5.7.12-winx64.zip Windows (x86, 64-bit), ZIP Archive版免安装配置
1.下载免安装版压缩包 下载地址:http://dev.mysql.com/downloads/mysql/ 选择符合你的操作系统的版本,点击download进入下载页面 不用注册也可以点击下载连接进 ...
- Trident内核中取验证码图片的几种方法
程序中用了IE的内核,想取出网站中的验证码图片,单独显示出来,调研了以下几路方法 1.枚举所有缓存文件,进行处理,找到想要的,核心代码 )//这段代码可以枚举所有缓存资源,然后对应做处理 { LPIN ...
- wind7下搭建ftp服务器
一.首先在本地机器上创建一个用户!这些用户是用来登录到FTP的!我的电脑右键->控制面板->管理工具->计算机管理->本地用户和组->用户->“右键”新建用户-&g ...
- Java 执行终端命令实现,调用执行另外一个Java文件
Test.java package com.journaldev.files; public class Test { public static void main(String[] args) { ...
- WordPress插件制作教程(五): 创建新的数据表
上一篇讲解了怎样将数据保存到数据库,今天为大家讲解创建新的数据表,也就是说当我们激活插件的时候,会在该数据库下面创建一个新的数据表出来.原理很简单,激活插件的时候运行创建数据库的代码.看下面代码: & ...
- 关于svcutil.exe
添加环境变量 name NETFX4 value C:\Program Files\Microsoft SDKs\Windows\v7.0A\bin\NETFX 4.0 Tools Server.Pr ...
- qt捕获全局windows消息(使用QAbstractNativeEventFilter,然后注册这个类)
qt 如何捕获全屏的鼠标事件,这个帖子上面主要讲述了下嵌入式qt怎么抓取系统级消息,不过从这篇文章中我也看到了希望,有个回复说winEventFilter支持这种方式,然后我就顺着这个线索找到了na ...
- WPF笔记(2.8 常用的布局属性)——Layout
原文:WPF笔记(2.8 常用的布局属性)--Layout 这一节老没意思,啰里啰唆的尽是些HTML的属性,挑几个好玩的List出来,备忘:Padding与Margin的区别:Margin指控件边界与 ...