- (void)addLocalNotice:(NSString *)titlepush {

if (@available(iOS 10.0, *)) {

UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];

UNMutableNotificationContent *content = [[UNMutableNotificationContent alloc] init];

// 标题

content.title = titlepush;

content.subtitle = titlepush;

// 内容

content.body = titlepush;

// 声音

// 默认声音

//    content.sound = [UNNotificationSound defaultSound];

// 添加自定义声音

content.sound = [UNNotificationSound soundNamed:@"Alert_ActivityGoalAttained_Salient_Haptic.caf"];

// 角标 (我这里测试的角标无效,暂时没找到原因)

content.badge = @1;

// 多少秒后发送,可以将固定的日期转化为时间

NSTimeInterval time = [[NSDate dateWithTimeIntervalSinceNow:10] timeIntervalSinceNow];

//        NSTimeInterval time = 10;

// repeats,是否重复,如果重复的话时间必须大于60s,要不会报错

UNTimeIntervalNotificationTrigger *trigger = [UNTimeIntervalNotificationTrigger triggerWithTimeInterval:time repeats:NO];

/*

         //如果想重复可以使用这个,按日期

         // 周一早上 8:00 上班

         NSDateComponents *components = [[NSDateComponents alloc] init];

         // 注意,weekday默认是从周日开始

         components.weekday = 2;

         components.hour = 8;

         UNCalendarNotificationTrigger *calendarTrigger = [UNCalendarNotificationTrigger triggerWithDateMatchingComponents:components repeats:YES];

         */

// 添加通知的标识符,可以用于移除,更新等操作

NSString *identifier = @"noticeId";

UNNotificationRequest *request = [UNNotificationRequest requestWithIdentifier:identifier content:content trigger:trigger];

[center addNotificationRequest:request withCompletionHandler:^(NSError *_Nullable error) {

NSLog(@"成功添加推送");

}];

}else {

UILocalNotification *notif = [[UILocalNotification alloc] init];

// 发出推送的日期

notif.fireDate = [NSDate dateWithTimeIntervalSinceNow:10];

// 推送的内容

notif.alertBody = @"你已经10秒没出现了";

// 可以添加特定信息

notif.userInfo = @{@"noticeId":@"00001"};

// 角标

notif.applicationIconBadgeNumber = 1;

// 提示音

notif.soundName = UILocalNotificationDefaultSoundName;

// 每周循环提醒

notif.repeatInterval = NSCalendarUnitWeekOfYear;

[[UIApplication sharedApplication] scheduleLocalNotification:notif];

}

}

NSString *stringInfo=[NSString stringWithFormat:@"APNS error: %@", err];

[self addLocalNotice:stringInfo];

ios APNS注册失败 本地push的更多相关文章

  1. ios推送:本地通知UILocalNotification

    Notification是智能手机应用编程中非常常用的一种传递信息的机制,而且可以非常好的节省资源,不用消耗资源来不停地检查信息状态(Pooling),在iOS下应用分为两种不同的Notificati ...

  2. iOS应用架构谈 本地持久化方案及动态部署

    转载: iOS应用架构谈 本地持久化方案及动态部署 前言 嗯,你们要的大招.跟着这篇文章一起也发布了CTPersistance和CTJSBridge这两个库,希望大家在实际使用的时候如果遇到问题,就给 ...

  3. UWP DEP0700: 应用程序注册失败。[0x80073CF9] 另一个用户已安装此应用的未打包版本。当前用户无法将该版本替换为打包版本。

    最近电脑抽风,我在[应用程序和功能]中重置了以下我的App自然灾害,居然,搞出大新闻了. 它居然从列表中消失了... vs再次编译代码的时候,提示 严重性 代码 说明 项目 文件 行 禁止显示状态 错 ...

  4. erlang -- ios apns provider -- erlang 实现

    os apns-apple notification server 与第三方provider的通信原理网上已有很多介绍,这里不再介绍,有想了解的大家可以去IOS官网https://developer. ...

  5. iOS开发中UILocalNotification本地通知实现简单的提醒功能

    这段时间项目要求做一个类似的闹钟提醒功能,对通知不太熟悉的我,决定先用到xcode自带的本地通知试试,最终成功的实现了功能,特整理分享下. 它的表现特点: app关闭的时候也能接收和显示通知. app ...

  6. k3s原理分析丨如何搞定k3s node注册失败问题

    前 言 面向边缘的轻量级K8S发行版k3s于去年2月底发布后,备受关注,在发布后的10个月时间里,Github Star达11,000颗.于去年11月中旬已经GA.但正如你所知,没有一个产品是十全十美 ...

  7. IOS开发-加载本地音乐

    IOS开发-加载本地音乐 $(function () { $('pre.prettyprint code').each(function () { var lines = $(this).text() ...

  8. 由于IPv6导致的iOS应用发布失败,是否该怪Azure?

    IPv6已经被越来越广泛的支持了,尤其是苹果强制要求iOS (确切的说是iOS 9以及后续版本)应用必须支持IPv6之后(官方宣布),更将进一步推动IPv6的使用. 不过苹果应用作为客户端强制要求IP ...

  9. iOS WebView 加载本地资源(图片,文件等)

    https://www.cnblogs.com/dhui69/p/5596917.html iOS WebView 加载本地资源(图片,文件等) NSString *path = [[NSBundle ...

随机推荐

  1. docker 安装mysql数据库 <二>

    一.下载mysql数据库 #网易镜像中心https://c.163.com/hub#/m/home/ #采用网易加速地址,不加速时下载非常的慢 docker pull hub.c..com/libra ...

  2. Java Spring Boot VS .NetCore (一)来一个简单的 Hello World

    系列文章 Java Spring Boot VS .NetCore (一)来一个简单的 Hello World Java Spring Boot VS .NetCore (二)实现一个过滤器Filte ...

  3. hibernate 保存报错 Hibernate operation: could not get next sequence value;

    错误信息: [2017-09-28 18:51:38,854]-[org.hibernate.util.JDBCExceptionReporter:101] ERROR - Numeric Overf ...

  4. spring boot 启动

    启动spring boot java -jar tuia-0.0.1-SNAPSHOT.jar --spring.profiles.active=prod 查找进程 ps aux|grep tuia- ...

  5. Ethereum(1)—— 基本介绍

    1 环境安装 安装Ethereum 协议的Go语言的最新实现. git clone https://github.com/ethereum/go-ethereum.git make all cd bu ...

  6. Codeforces 840C On the Bench dp

    On the Bench 两个数如果所有质因子的奇偶性相同则是同一个数,问题就变成了给你n个数, 相同数字不能相邻的方案数. dp[ i ][ j ]表示前 i 种数字已经处理完, 还有 j 个位置需 ...

  7. Codeforces 628F 最大流转最小割

    感觉和昨天写了的题一模一样... 这种题也能用hall定理取check, 感觉更最小割差不多. #include<bits/stdc++.h> #define LL long long # ...

  8. php代理

    有些网上接口请求需要用代理 php代码 <?php header('Access-Control-Allow-Origin:*'); $url=$_POST['urlString']; $res ...

  9. debian安装mongoDB

    wget http://fastdl.mongodb.org/linux/mongodb-linux-i686-1.8.2.tgz tar zxf mongodb-linux-i686-1.8.2.t ...

  10. POJ 2391 Ombrophobic Bovines (二分答案+floyd+最大流)

    <题目链接> 题目大意: 给定一个有$n$个顶点和$m$条边的无向图,点$i$ 处有$A_i$头牛,点$i$ 处的牛棚能容纳$B_i$头牛,每条边有一个时间花费$t_i$(表示从一个端点走 ...