- (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. James Munkres Topology: Theorem 16.3

    Theorem 16.3 If \(A\) is a subspace of \(X\) and \(B\) is a subspace of \(Y\), then the product topo ...

  2. Metaphor of topological basis and open set

    The definition of topological basis for a space $X$ requires that each point $x$ in $X$ is contained ...

  3. 使用Type.MakeGenericType,反射构造泛型类型

    有时我们会有通过反射来动态构造泛型类型的需求,该如何实现呢?举个栗子,比如我们常常定义的泛型委托Func<in T, out TResult>,当T或TResult的类型需要根据程序上下文 ...

  4. python全栈开发day111-flask路由及其参数,Flask配置,蓝图,几个装饰器、闪现、send_file、jsonify

    1.endpoint参数,解决视图函数重名问题(包括装饰后重名问题) http://www.cnblogs.com/eric-nirnava/p/endpoint.html 每个应用程序app都有一个 ...

  5. PSO:利用PSO+ω参数实现对一元函数y = sin(10*pi*x) ./ x进行求解优化,找到最优个体适应度—Jason niu

    x = 1:0.01:2; y = sin(10*pi*x) ./ x; figure plot(x, y) title('绘制目标函数曲线图—Jason niu'); hold on c1 = 1. ...

  6. JS对象的拷贝

    1:对数据进行备份的时候,如果这个数据是基本的数据类型,那么很好办,通过赋值实现复制即可. 赋值与浅拷贝的区别 var obj1 = { 'name' : 'zhangsan', 'age' : '1 ...

  7. leetcode刷题第一日<两数和问题>

    开始就用到了c++的哈希表是真的恶心,首先学习一波基础知识 https://blog.csdn.net/u010025211/article/details/46653519 下面放下大佬的代码 cl ...

  8. linux操作笔记记录

    export https_proxy=https://10.10.2.91:8888export http_proxy=http://10.10.2.91:8888 桥接模式:需要配一个静态ip,可以 ...

  9. C# SortedDictionary以及SortedList的浅谈

    msdn叙述:The SortedDictionary<TKey, TValue> generic class is a binary search tree with O(log n) ...

  10. 设计模式之架构型MVC,MVP,MVVM模式

    一.MVCMVC,Model View Controller,是软件架构中最常见的一种设计模式,简单来说就是通过Controller的控制去操作Model层的数据,并且返回给view层展示.View跟 ...