iOS 10本地推送
来源:互联网 发布:java语言的四个特点 编辑:程序博客网 时间:2024/06/07 08:33
//// AppDelegate.m// localNotification//// Created by lcy on 17/4/17.// Copyright © 2017年 ZG. All rights reserved.//#import "AppDelegate.h"#import <UserNotifications/UserNotifications.h>@interface AppDelegate ()<UNUserNotificationCenterDelegate>@end@implementation AppDelegate- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter]; center.delegate = self; //一:请求获取通知权限(角标,声音,弹框) [center requestAuthorizationWithOptions:(UNAuthorizationOptionBadge | UNAuthorizationOptionSound | UNAuthorizationOptionAlert) completionHandler:^(BOOL granted, NSError * _Nullable error) { if (granted) { //获取用户是否同意开启通知 NSLog(@"request authorization successed!"); }else{ NSLog(@"不允许通知,到设置画面更改!!!"); } }]; [self addNotification]; return YES;}-(void)addNotification{ //第二步:新建通知内容对象 UNMutableNotificationContent *content = [[UNMutableNotificationContent alloc] init]; content.title = @"iOS10通知"; content.subtitle = @"新通知学习笔记"; content.body = @"新通知变化很大,之前本地通知和远程推送是两个类,现在合成一个了。这是一条测试通知,"; content.badge = @1; UNNotificationSound *sound = [UNNotificationSound defaultSound]; content.sound = sound; // 图片 NSString *imageFile = [[NSBundle mainBundle] pathForResource:@"sport" ofType:@"png"]; UNNotificationAttachment *imageAttachment = [UNNotificationAttachment attachmentWithIdentifier:@"iamgeAttachment" URL:[NSURL fileURLWithPath:imageFile] options:nil error:nil]; content.attachments = @[imageAttachment]; //第三步:通知触发机制。(重复提醒,时间间隔要大于60s) UNTimeIntervalNotificationTrigger *trigger1 = [UNTimeIntervalNotificationTrigger triggerWithTimeInterval:10 repeats:NO]; //第四步:创建UNNotificationRequest通知请求对象 NSString *requertIdentifier = @"RequestIdentifier"; UNNotificationRequest *request = [UNNotificationRequest requestWithIdentifier:requertIdentifier content:content trigger:trigger1]; //第五步:将通知加到通知中心 [[UNUserNotificationCenter currentNotificationCenter] addNotificationRequest:request withCompletionHandler:^(NSError * _Nullable error) { NSLog(@"Error:%@",error); }];}- (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler{ NSLog(@"前台收到通知"); completionHandler(UNNotificationPresentationOptionAlert);}- (void)applicationWillEnterForeground:(UIApplication *)application{ application.applicationIconBadgeNumber = 0;}
0 0
- iOS 10本地推送
- iOS 10本地推送
- iOS 10 本地推送UNUserNotificationCenter
- iOS-本地推送之UserNotifications(iOS 10)
- iOS推送:实现本地推送
- iOS推送:实现本地推送
- iOS推送:实现本地推送
- iOS推送:实现本地推送
- ios (推送)之本地推送
- iOS推送:实现本地推送
- ios (推送)之本地推送
- iOS推送之本地推送
- ios推送之本地推送
- ios本地推送
- iOS本地推送
- iOS 本地推送
- ios本地推送方法
- IOS本地推送处理
- C++ 内存对齐
- JAVA手册——线程简介之Runnable与Thread
- 总结:递归递推
- Win10下Python的安装及相关库的安装
- 用UltraEdit实现2个HEX文件组合成1个HEX
- iOS 10本地推送
- Linux常用的Shell命令
- 利用封装、继承对Java代码进行优化
- HDU 3709 Balanced Number
- 实例讲解OSGI开发
- Web基础之初识JavaScript
- java中的集合,迭代器的使用以及java中的异常
- Qt5中部分自带控件菜单(QLineEdit、QTextEdit右键菜单)的汉化
- RabbitMQ hello world示例