iOS10 之后使用才有效果

1.在 AppDelegate.m 文件里面添加下面的方法。

- (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler {

    completionHandler(UNNotificationPresentationOptionBadge
|UNNotificationPresentationOptionSound
|UNNotificationPresentationOptionAlert);
}

2. 对content添加属性的方式实现。

               UNMutableNotificationContent *content = [[UNMutableNotificationContent alloc] init];
content.body = @"本地通知--content";
content.title = @"本地通知--title";
content.sound = [UNNotificationSound defaultSound];
content.badge = @(msgArr.count);
//10之后的系统可以设置在前台显示
[content setValue:@(YES) forKeyPath:@"shouldAlwaysAlertWhileAppIsForeground"];
// 触发模式
UNTimeIntervalNotificationTrigger *trigger = [UNTimeIntervalNotificationTrigger triggerWithTimeInterval:1 repeats:NO]; // 创建本地通知
NSString *requestIdentifer = [NSString stringWithFormat:@"TestRequestww1%u",arc4random() % 1000];
UNNotificationRequest *request = [UNNotificationRequest requestWithIdentifier:requestIdentifer content:content trigger:trigger]; //把通知加到UNUserNotificationCenter, 到指定触发点会被触发
[[UNUserNotificationCenter currentNotificationCenter] addNotificationRequest:request withCompletionHandler:^(NSError * _Nullable error) { }];

iOS APP 在前台时弹出本地通知的更多相关文章

  1. iOS8无法弹出本地通知?

    最近在看<iOS编程(第4版)>(就是Big Nerd Ranch用的那本教材).这本书写的不错,推荐一下,写的很细致,循序渐进,不能不赞一下外国人写书的思路,确实跟国人不同.之前学And ...

  2. ios兼容 input输入时弹出键盘框 页面整体上移键盘框消失后在ios上页面不能回弹的问题

    前端h5混合开发手机端ios  当有input输入时,手机下方弹出键盘使页面上移,当输入完成,键盘消失后页面显示回到原位,但实际不能点击(可点击上方区域,有反应),也就是说实际是没有回弹. 解决办法: ...

  3. 解决IOS safari在input focus弹出输入法时不支持position fixed的问题

    该文章为转载 我们在做移动web应用的时候,常常习惯于使用position:fixed把一个input框作为提问或者搜索框固定在页面底部.但在IOS的safari和webview中,对position ...

  4. Android在初始化时弹出popwindow的方法

     http://blog.csdn.net/sxsboat/article/details/7340759 Android中在onCreate()时弹出popwindow,很多人都有过类似的需求吧,但 ...

  5. Android定位&地图&导航——基于百度地图,实现自定义图标绘制并点击时弹出泡泡

    一.问题描述 上一次我们使用百度地图实现基本的定位功能,接下来我们继续实现搜索和定位,并使用LocationOverlay绘制定位位置,同时展示如何使用自定义图标绘制并点击时弹出泡泡 如图所示: 二. ...

  6. Visual Studio2012打开时弹出“遇到异常:这可能是由某个扩展导致的”错误的解决办法

    Visual Studio2012打开时弹出"遇到异常:这可能是由某个扩展导致的"错误的解决办法: 具体问题如下: 分析原因:网上搜集了以下,出现异常的原因是安装了第三方控件,然后 ...

  7. loadrunner录制时弹出invalid application path!please check if application exists对话框

    问题:oadrunner录制时弹出invalid application path!please check if application exists对话框 原因:IE浏览器地址不对,需要手动重新选 ...

  8. [转]Android在初始化时弹出popwindow的方法 .

    转自:http://blog.csdn.net/sxsboat/article/details/7340759 留个人备用0.0 Android中在onCreate()时弹出popwindow,很多人 ...

  9. 解决在IE里预览时弹出:为了有利于保护安全性......

    用Dreamweaver做网页,在IE里预览时弹出这个:为了有利于保护安全性,Internet Explorer 已限制此网页运行可以访问计算机的脚本或ActiveX控件. 在页面顶部加段代码就可以了 ...

随机推荐

  1. Halcon 2D测量

    * This program shows how to detect the edges of a diamond * with subpixel accuracy and calculate the ...

  2. Java知多少(5) Java开发环境的搭建

    要进行Java开发,首先要安装JDK(Java Development Kit,Java开发工具箱). JDK 是一系列工具的集合,这些工具是编译Java源码.运行Java程序所必需的,例如JVM.基 ...

  3. 数据中心内负载均衡-ECMP的使用分析

    背景 数据中心的网络拓扑通常采用CLOS结构,主机之间常存在多条路径.数据中心为满足吞吐量敏感型流量的需求会提供大量的带宽资源.那么利用数据中心这种网络拓扑已知,路径资源.带宽资源丰富的特性,可以更好 ...

  4. Go语言_range(范围)理解

    一.Go语言中的range Go 语言中 range 关键字用于 for循环中迭代数组(array).切片(slice).链表(channel)或集合(map)的元素: 在数组和切片中它返回元素的索引 ...

  5. 树莓GPIO &&python

      from http://www.cnblogs.com/xiaobo-Linux/p/8969324.html 命令行控制LED灯  echo 12 > /sys/class/gpio/ex ...

  6. 【12月26日】A股滚动市盈率PE最低排名

    深康佳A(SZ000016) - 滚动市盈率PE:1.47 - 滚动市净率PB:0.98 - 滚动年化股息收益率:4.97% - 消费电子产品 - 深康佳A(SZ000016)的历史市盈率走势图 华菱 ...

  7. [Python] 07 - Statements --> Functions

    故事背景 一.阶级关系 1. Programs are composed of modules.2. Modules contain statements.3. Statements contain ...

  8. orcal数据库基本操作

    1.连接 SQL*Plus system/manager 2.显示当前连接用户 SQL> show user 3.查看系统拥有哪些用户 SQL> select * from all_use ...

  9. Navicat -- Oracle -- 错误锦集

    ORA:connection to server failed,probable Oracle Net admin error 解决的方案是: oci.dll的版本不对  从 http://www.o ...

  10. Spring.NET依赖注入框架学习--实例化容器常用方法

    Spring.NET依赖注入框架学习---实例化容器常用方法 本篇学习实例化Spring.NET容器的俩种方式 1.通过XmlObjectFactory创建一个Spring.NET容器 IResour ...