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种推送通知 ● ...
随机推荐
- cocos2dx Menu
---恢复内容开始--- cocos2dx 3.0以后 Menu相关回调函数使用不同.现在列出当前版本可使用的方法. 看见一个说的很仔细的博客,博客源地址 http://blog.sina.com.c ...
- struts2 result的type属性
目前只使用过以下3种,都是直接跳转到另一个action chain: 写法:<result name="success" type="chain"> ...
- 移动端Web开发笔记
最近写的一个移动端项目:上海 地铁指路通,之间遇到的一些问题,记录下来(以后会不断补充的): 1. 丰富的页面Meta: 1.1: 控制显示区域各种属性: <meta content=" ...
- [0] Tornado Todo 开篇
参考自: python: tornado例子 Github地址:tornado_todo 开发环境: Python包的安装: 首先安装 pip: sudo apt-get install python ...
- Scala学习文档-列表的使用
注:列表是不可变的,不能通过赋值改变列表的元素 列表具有递归结构,数组是连续的 scala里的列表类型是协变的? --> scala中的逆变与协变 分治原则 //自定义实现:::操作符 def ...
- window系统查看端口被哪个进程占用
---恢复内容开始--- 1.在cmd窗口运行 netstat -ano | findstr 1099 找到进程PID 8408 杀死进程:taskkill -F -PID 8408 2.另外还找到进 ...
- log4c 编译安装简单小结(ubuntu12)
1 下载源码,解压 (假定解压到了当前用户的根目录下,位置是~/log4c-1.2.3) 2 编译安装log4c(指定--prefix极其重要,如果没有指定到/usr下会有一堆麻烦事,还有,不能按照他 ...
- 【转】ubuntu安装ftp服务器
原文网址:https://wiki.archlinux.org/index.php/Very_Secure_FTP_Daemon_(%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96% ...
- C# 通过线程更新UI
摘自:http://msdn.microsoft.com/zh-cn/library/ms171728(en-us,VS.80).aspx 关键代码(form中增加): delegate void S ...
- Spiral Matrix 解答
Question Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in ...