亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb

首頁 > 系統 > iOS > 正文

iOS10 推送最新特性研究

2020-07-26 03:13:13
字體:
來源:轉載
供稿:網友

最近在研究iOS10關于推送的新特性, 相比之前確實做了很大的改變,總結起來主要是以下幾點:

 1.推送內容更加豐富,由之前的alert 到現在的title, subtitle, body
 2.推送統一由trigger觸發
 3.可以為推送增加附件,如圖片、音頻、視頻,這就使推送內容更加豐富多彩
 4.可以方便的更新推送內容 

import 新框架

添加新的框架 UserNotifications.framework

 

#import <UserNotifications/UserNotifications.h> 

注冊推送 

在設置通知的時候,需要先進行注冊,獲取授權
iOS10 所有通知都是通過UNUserNotificationCenter來管理,包括遠程通知和本地通知

  //iOS8以下  [application registerForRemoteNotificationTypes:UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound];  //iOS8 - iOS10  [application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert | UIUserNotificationTypeSound | UIUserNotificationTypeBadge categories:nil]];  //iOS10  UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];  [center requestAuthorizationWithOptions:(UNAuthorizationOptionAlert | UNAuthorizationOptionBadge | UNAuthorizationOptionSound) completionHandler:^(BOOL granted, NSError * _Nullable error) {  }

獲取用戶設置 

iOS10 提供了獲取用戶授權相關設置信息的接口getNotificationSettingsWithCompletionHandler: , 回調帶有一個UNNotificationSettings對象,它具有以下屬性,可以準確獲取各種授權信息

authorizationStatus
soundSetting
badgeSetting
alertSetting
notificationCenterSetting
lockScreenSetting
carPlaySetting
alertStyle 

像下面的方法,點擊allow

   UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];  [center requestAuthorizationWithOptions:(UNAuthorizationOptionAlert | UNAuthorizationOptionBadge | UNAuthorizationOptionSound) completionHandler:^(BOOL granted, NSError * _Nullable error) {     if (granted) {        //點擊允許        NSLog(@"注冊通知成功");        [center getNotificationSettingsWithCompletionHandler:^(UNNotificationSettings * _Nonnull settings) {        NSLog(@"%@", settings);        }];      } else {        //點擊不允許        NSLog(@"注冊通知失敗");      }    }];

打印信息:   *<UNNotificationSettings: 0x174090a90; authorizationStatus: Authorized, notificationCenterSetting: Enabled, soundSetting: Enabled, badgeSetting: Enabled, lockScreenSetting: Enabled, alertSetting: NotSupported, carPlaySetting: Enabled, alertStyle: Banner>* 

注冊APNS, 獲取token 

iOS10, 注冊APNS和獲取token的方法還和之前一樣
application: didFinishLaunchingWithOptions:調用 registerForRemoteNotifications方法
 [[UIApplication sharedApplication] registerForRemoteNotifications]; 

在代理方法application: didRegisterForRemoteNotificationsWithDeviceToken:中獲取token

 - (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken NS_AVAILABLE_IOS(3_0){    NSLog(@"deviceToken:%@",deviceToken);  }- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error NS_AVAILABLE_IOS(3_0){    NSLog(@"didFailToRegisterForRemoteNotificationsWithError:%@",error);  } 

設置處理通知的action 和 category 

在iOS8以前是沒有category這個屬性的;
在iOS8注冊推送,獲取授權的時候,可以一并設置category, 注冊的方法直接帶有這個參數;
在iOS10, 需要調用一個方法setNotificationCategories:來為管理推送的UNUserNotificationCenter實例設置category, category又可以對應設置action;

 //設置category//UNNotificationActionOptionAuthenticationRequired 需要解鎖//UNNotificationActionOptionDestructive 顯示為紅色//UNNotificationActionOptionForeground  點擊打開appUNNotificationAction *action1 = [UNNotificationAction actionWithIdentifier:@"action1" title:@"策略1行為1" options:UNNotificationActionOptionForeground];UNTextInputNotificationAction *action2 = [UNTextInputNotificationAction actionWithIdentifier:@"action2" title:@"策略1行為2" options:UNNotificationActionOptionDestructive textInputButtonTitle:@"comment" textInputPlaceholder:@"reply"]; //UNNotificationCategoryOptionNone //UNNotificationCategoryOptionCustomDismissAction 清除通知被觸發會走通知的代理方法 //UNNotificationCategoryOptionAllowInCarPlay    適用于行車模式UNNotificationCategory *category1 = [UNNotificationCategory categoryWithIdentifier:@"category1" actions:@[action2,action1] minimalActions:@[action2,action1] intentIdentifiers:@[] options:UNNotificationCategoryOptionCustomDismissAction];UNNotificationAction *action3 = [UNNotificationAction actionWithIdentifier:@"action3" title:@"策略2行為1" options:UNNotificationActionOptionForeground];UNNotificationAction *action4 = [UNNotificationAction actionWithIdentifier:@"action4" title:@"策略2行為2" options:UNNotificationActionOptionForeground];UNNotificationCategory *category2 = [UNNotificationCategory categoryWithIdentifier:@"category2" actions:@[action3,action4] minimalActions:@[action3,action4] intentIdentifiers:@[] options:UNNotificationCategoryOptionCustomDismissAction];[[UNUserNotificationCenter currentNotificationCenter] setNotificationCategories:[NSSet setWithObjects:category1,category2, nil]]; 

設置通知內容 

因為iOS10遠程通知與本地通知統一起來了,通知內容屬性是一致的,不過遠程推送就需要在payload進行具體設置了,下面以本地通知為例,介紹關于UNNotificationContent的內容
官網上明確說明了,我們是不能直接創建UNNotificationContent的實例的, 如果我們需要自己去配置內容的各個屬性,我們需要用到UNMutableNotificationContent
看一下它的一些屬性:
attachments          //附件
badge                //徽標
body                 //推送內容body
categoryIdentifier   //category標識
launchImageName      //點擊通知進入應用的啟動圖
sound               //聲音
subtitle            //推送內容子標題
title               //推送內容標題
userInfo           //遠程通知內容

UNMutableNotificationContent *content = [[UNMutableNotificationContent alloc] init];  content.title = @"Test";  content.subtitle = @"1234567890";  content.body = @"Copyright © 2016年 jpush. All rights reserved.";  content.badge = @1;  NSError *error = nil;  NSString *path = [[NSBundle mainBundle] pathForResource:@"718835727" ofType:@"png"];  UNNotificationAttachment *att = [UNNotificationAttachment attachmentWithIdentifier:@"att1" URL:[NSURL fileURLWithPath:path] options:nil error:&error];  if (error) {    NSLog(@"attachment error %@", error);  }  content.attachments = @[att];  content.categoryIdentifier = @"category1”; //這里設置category1, 是與之前設置的category對應  content.launchImageName = @"1-Eb_0OvtcxJXHZ7-IOoBsaQ";UNNotificationSound *sound = [UNNotificationSound defaultSound];content.sound = sound;

 

通知觸發器 

UNNotificationTrigger
iOS 10觸發器有4種
 •UNPushNotificationTrigger 觸發APNS服務,系統自動設置(這是區分本地通知和遠程通知的標識)
 •UNTimeIntervalNotificationTrigger 一段時間后觸發
 •UNCalendarNotificationTrigger 指定日期觸發
 •UNLocationNotificationTrigger 根據位置觸發,支持進入某地或者離開某地或者都有

 //十秒后UNTimeIntervalNotificationTrigger *trigger1 = [UNTimeIntervalNotificationTrigger triggerWithTimeInterval:10 repeats:NO];//每周日早上8:00NSDateComponents *component = [[NSDateComponents alloc] init];component.weekday = 1;component.hour = 8;UNCalendarNotificationTrigger *trigger2 = [UNCalendarNotificationTrigger triggerWithDateMatchingComponents:component repeats:YES];//圓形區域,進入時候進行通知CLLocationCoordinate2D cen = CLLocationCoordinate2DMake(80.335400, -90.009201);CLCircularRegion *region = [[CLCircularRegion alloc] initWithCenter:cen                               radius:500.0 identifier:@“center"];region.notifyOnEntry = YES; //進入的時候region.notifyOnExit = NO;  //出去的時候UNLocationNotificationTrigger *trigger3 = [UNLocationNotificationTrigger  triggerWithRegion:region repeats:NO]; 

添加通知 / 更新通知

 1.創建一個UNNotificationRequest類的實例,一定要為它設置identifier, 在后面的查找,更新, 刪除通知,這個標識是可以用來區分這個通知與其他通知
 2.把request加到UNUserNotificationCenter, 并設置觸發器,等待觸發
 3.
如果另一個request具有和之前request相同的標識,不同的內容, 可以達到更新通知的目的

  NSString *requestIdentifer = @"TestRequest";  UNNotificationRequest *request = [UNNotificationRequest requestWithIdentifier:requestIdentifer content:content trigger:trigger1];  //把通知加到UNUserNotificationCenter, 到指定觸發點會被觸發  [center addNotificationRequest:request withCompletionHandler:^(NSError * _Nullable error) {  }]; //在另外需要更新通知的地方UNMutableNotificationContent *newContent = [[UNMutableNotificationContent alloc] init];newContent.title = @"Update";newContent.subtitle = @"XXXXXXXXX";newContent.body = @"Copyright © 2016年 jpush. All rights reserved.";UNTimeIntervalNotificationTrigger *trigger1 = [UNTimeIntervalNotificationTrigger triggerWithTimeInterval:3 repeats:NO]; UNNotificationRequest *request = [UNNotificationRequest requestWithIdentifier:@"TestRequest" content:newContent trigger:trigger1];[[UNUserNotificationCenter currentNotificationCenter] addNotificationRequest:request withCompletionHandler:^(NSError * _Nullable error) {}];

 

獲取和刪除通知 

這里通知是有兩種狀態
 •Pending 等待觸發的通知
 •Delivered 已經觸發展示在通知中心的通知

 //獲取未觸發的通知[[UNUserNotificationCenter currentNotificationCenter] getPendingNotificationRequestsWithCompletionHandler:^(NSArray<UNNotificationRequest *> * _Nonnull requests) {  NSLog(@"pending: %@", requests);}];//獲取通知中心列表的通知[[UNUserNotificationCenter currentNotificationCenter] getDeliveredNotificationsWithCompletionHandler:^(NSArray<UNNotification *> * _Nonnull notifications) {  NSLog(@"Delivered: %@", notifications);}]; //清除某一個未觸發的通知 [[UNUserNotificationCenter currentNotificationCenter] removePendingNotificationRequestsWithIdentifiers:@[@"TestRequest1"]]; //清除某一個通知中心的通知 [[UNUserNotificationCenter currentNotificationCenter] removeDeliveredNotificationsWithIdentifiers:@[@"TestRequest2"]]; //對應的刪除所有通知[[UNUserNotificationCenter currentNotificationCenter] removeAllPendingNotificationRequests];[[UNUserNotificationCenter currentNotificationCenter] removeAllDeliveredNotifications];

 delegate 

<UNUserNotificationCenterDelegate> 

iOS10收到通知不再是在application: didReceiveRemoteNotification:方法去處理, iOS10推出新的代理方法,接收和處理各類通知(本地或者遠程)

 - (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler {  //應用在前臺收到通知  NSLog(@"========%@", notification);}- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler {  //點擊通知進入應用  NSLog(@"response:%@", response);}

最后 

下一篇文章繼續介紹關于富媒體推送的 UNNotificationServiceExtension 和 Notification content extension, 未完待續。。。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb
日韩电影免费在线观看中文字幕| 成人做爽爽免费视频| 欧美又大又粗又长| 97精品在线视频| 亚洲第一区第一页| 国产精品视频中文字幕91| 欧美视频专区一二在线观看| 欧美激情国内偷拍| 久久91精品国产| 日韩日本欧美亚洲| 久久久久久18| 亚洲成人精品视频在线观看| 精品日韩美女的视频高清| 中文字幕亚洲在线| 日韩中文字幕网址| 中文字幕日韩av综合精品| 亚洲xxxx做受欧美| 日本一区二区在线播放| 国产欧亚日韩视频| 亚洲天堂av在线播放| 精品香蕉一区二区三区| 国产91精品久久久| 在线成人激情视频| 成人淫片在线看| 日韩免费av一区二区| 日韩色av导航| 欧美性极品xxxx娇小| 亚洲sss综合天堂久久| 国产精品免费久久久| 欧美xxxx做受欧美| 日韩国产精品亚洲а∨天堂免| 欧美黑人极品猛少妇色xxxxx| xxxxx成人.com| 欧美色xxxx| 久久久久久国产免费| 欧美电影电视剧在线观看| 7777kkkk成人观看| 91免费看片在线| 亚洲一区二区三区在线视频| 欧美美女操人视频| 亚洲欧美国产精品va在线观看| 91成人福利在线| 国产999在线观看| 精品久久久久久亚洲国产300| 在线国产精品播放| 日韩av一区在线观看| 一本色道久久88综合亚洲精品ⅰ| 亚洲在线免费视频| 久久成人国产精品| 亚洲精品小视频| 日韩精品视频免费专区在线播放| 国产91在线播放| 91精品久久久久久久久久久久久久| 日韩av在线一区二区| 97超碰蝌蚪网人人做人人爽| 欧美亚洲视频一区二区| 日韩精品电影网| 成人两性免费视频| 日韩av片永久免费网站| 狠狠做深爱婷婷久久综合一区| 国产91免费看片| 日韩在线观看视频免费| 国产91免费看片| 欧美精品999| 国产欧美日韩丝袜精品一区| 亚洲精品v天堂中文字幕| 永久免费看mv网站入口亚洲| 亚洲精品98久久久久久中文字幕| 国产精品羞羞答答| 成人免费看吃奶视频网站| 在线观看国产成人av片| 亚洲国产美女精品久久久久∴| 日韩av中文字幕在线免费观看| 91极品女神在线| 在线观看精品自拍私拍| 这里只有精品在线观看| 成人午夜激情免费视频| 欧美国产精品va在线观看| 国内精品视频久久| 日韩精品在线观看一区| 精品伊人久久97| 国产精品678| 国产精品爽爽ⅴa在线观看| 亚洲欧美日韩国产成人| 日本91av在线播放| 午夜精品免费视频| 久久久久日韩精品久久久男男| 久久精品一本久久99精品| 久久久国产精品一区| 欧美做爰性生交视频| 久久福利视频导航| 庆余年2免费日韩剧观看大牛| 国产精品第100页| 成人精品在线视频| 57pao成人国产永久免费| 韩剧1988在线观看免费完整版| 91精品视频免费观看| 欧美福利视频在线| 亚洲片国产一区一级在线观看| 精品一区二区三区四区在线| 日韩在线观看免费高清完整版| 中文字幕av一区二区三区谷原希美| 91久久久久久久久久久| 国产精品专区第二| 最新日韩中文字幕| 亚洲精品国产精品乱码不99按摩| 欧美性高潮床叫视频| 97人人模人人爽人人喊中文字| 欧美激情视频网址| 18性欧美xxxⅹ性满足| 欧美成人亚洲成人| 成人妇女淫片aaaa视频| 久久视频在线直播| 一区二区三区无码高清视频| 日韩中文理论片| 亚洲一区亚洲二区| 97成人精品视频在线观看| 茄子视频成人在线| 国产69精品久久久久久| 国产亚洲精品久久久久久牛牛| 精品国产乱码久久久久久婷婷| 91久久精品美女| 一个人看的www欧美| 欧美激情久久久| xvideos成人免费中文版| 97久久精品视频| 在线播放精品一区二区三区| 亚洲精品国产拍免费91在线| 中文字幕久久亚洲| 7m精品福利视频导航| 久久久女人电视剧免费播放下载| 国产精品成人免费视频| 色青青草原桃花久久综合| 国产精品嫩草视频| 精品人伦一区二区三区蜜桃免费| 国产精品久久久久久久久久东京| 国产精品久久97| 欧美自拍大量在线观看| 日韩欧美在线网址| 国产成人精品日本亚洲| 高清在线视频日韩欧美| 91精品国产91久久久久久不卡| 日本中文字幕不卡免费| 欧美成人精品不卡视频在线观看| 97久久精品人人澡人人爽缅北| 亚洲成人激情图| 久久久久久久久电影| 久久成人18免费网站| 国产一区二区在线免费视频| 国产精品高潮呻吟久久av黑人| 久久国产加勒比精品无码| 成人av电影天堂| 国产在线高清精品| 国产一区二中文字幕在线看| 成人黄色在线播放| 日本高清不卡在线| 国产午夜精品免费一区二区三区| 美日韩精品视频免费看| 97婷婷大伊香蕉精品视频| 精品久久久久久久久久久久久久| 92看片淫黄大片看国产片| 色偷偷88888欧美精品久久久| 亚洲情综合五月天| 欧美大胆在线视频|