- (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. python 用xlwt包把数据导出到excel表中

    def write_excel(): f = xlwt.Workbook() #创建工作簿 ''' 创建第一个sheet: sheet1 ''' sheet1 = f.add_sheet(u'shee ...

  2. Sicily T-primes

    DescriptionWe know that prime numbers are positive integers that have exactly two distinct positive  ...

  3. Linux-父子进程的简单同步

    int fork() 功能:创建一个子进程 返回值:0-创建成功,-1-创建进程失败,>0-创建进程成功,返回返回子进程id int wait(int * status) 功能:将调用的进程挂起 ...

  4. visual studio的包含目录配置问题

    早上将一个项目从debug x64修改到release x64,然后包含目录都是直接从debug拷贝过来的,一模一样的路径,一直说无法include,并且路径中的文件都是存在的,配置页面的releas ...

  5. XVIII Open Cup named after E.V. Pankratiev. GP of Romania

    A. Balance 不难发现确定第一行第一列后即可确定全部,列不等式单纯形求解线性规划即可. #include<cstdio> #include<algorithm> usi ...

  6. [BZOJ1045][HAOI2008]糖果传递 (环形均分纸牌)

    题意 有n个小朋友坐成一圈,每人有ai个糖果.每人只能给左右两人传递糖果.每人每次传递一个糖果代价为1. 思路 把|s[i]-s[k]|求和即可,s[i]是A的前缀和 s[k]为s数组的中位数时,总值 ...

  7. oracle直接读写ms sqlserver数据库(一)如何下载oracle database gateway for sqlserver

    想从Oracle实时同步数据到Ms Sqlserver,需要在Oracle里面直连Sqlserver进行数据的读写,可以在Oracle服务器上安装oracle database gateway for ...

  8. 认识vim 编辑器

    vim编辑器 vim编辑器的重点是光标的移动,模式切换,删除,查找,替换,复制,撤销命令的使用. vim 有三种模式: 命令模式,编辑模式,末行模式 vim打开方式: 语法: vim 文件路径 vim ...

  9. 牛刀小试之用pytorch实现LSTM

    https://www.itcodemonkey.com/article/9008.html 要看一看

  10. Module(CP343-1)Advanced system error SDB generation Error in rule file or rule file not found

    报这个故障的原因是因为安装目录下缺少三个 err文件.只要从好的目录下拷贝过来即可. C:\Program Files (x86)\SIEMENS\Step7\s7wbx\rul