用戶點擊了一個 Action(如贊、踩、關注、甚至評論等)

WWDC 2017 Session筆記 - Session 708 推送消息新功能和最佳實踐(Best Practices and What’s New in User Notifications)

 

 

本地和推送通知使您的應用程序可以經過顯示消息並接受用戶的操做,播放獨特的聲音或更新應用程序圖標上的徽章,使用戶及時瞭解相關內容。服務擴展功能使您的應用程序可以在顯示以前解密並擴充推送通知內容。瞭解什麼是新功能,並得到有關在您的應用程序中實施用戶通知的專家建議。api

Best Practices and What’s New in User Notifications

Content

之前只能展現一條文字,如今能夠有 title 、subtitle 以及 body 了 Alt text 代碼示例:session

//Local Notification
UNMutableNotificationContent *content = [[UNMutableNotificationContent alloc] init];
content.title = @"Introduction to Notifications";
content.subtitle = @"Session 707";
content.body = @"Woah! These new notifications look amazing! Don’t you agree?";
content.badge = @1;

//Remote Notification
{
"aps" : {
    "alert" : { 
         "title" : "Introduction to Notifications", 
         "subtitle" : "Session 707",         
         "body" : "Woah! These new notifications look amazing! Don’t you agree?"
                },
    "badge" : 1
        },
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18

Notification Management

完全掌控整個推送週期: * Local Notification 經過更新 request * Remote Notification 經過新的字段 apns-collapse-idapp

經過以前的 addNotificationRequest: 方法,在 id 不變的狀況下從新添加,就能夠刷新原有的推送。ide

NSString *requestIdentifier = @"sampleRequest"; 
UNNotificationRequest *request = [UNNotificationRequest requestWithIdentifier:requestIdentifier content:newContent trigger:newTrigger1]; 
[center addNotificationRequest:request withCompletionHandler:^(NSError * _Nullable error) { }];
  • 1
  • 2
  • 3

Notification Actions

在 iOS 10 中,能夠容許推送添加交互操做 action,這些 action 可使得 App 在前臺或後臺執行一些邏輯代碼。而且在鎖屏界面經過 3d-touch 觸發。如:推出鍵盤進行快捷回覆,該功能以往只在 iMessage 中可行。Notification Actions 在 iOS 8 引入,快捷回覆在 iOS 9 引入,在 iOS 10 中,這些 API 被統一。動畫

Hidden Notificaition Content

例子:系統信息appurl

用戶能夠經過Setting統一配置是否顯示詳情, 先開放apispa

能夠配置identifier, 顯示信息的類別.net

Service Extendsion

有時間限制地執行一段代碼設計

先發送視頻url, 本地下載後做爲attachment後再展現, 有下載不成功的狀況, 有一系列異常的回調3d

能夠在手機「接收到推送以後、展現推送以前」對推送進行處理,更改、替換原有的內容。

使用它,原有發送推送的 payload 能夠徹底不變,而在客戶端對接收到的內容(只有一條字符串)進行加工,從而適配 iOS 10 的展現效果(標題+副標題+內容)。

Different from silent notifications

Notification Content

iOS 10 新增的另外一項 Extension,用於徹底自定義推送展現的 UI 界面,響應 Actions 的同時刷新該 UI。簡單的說就是你能夠把須要推送的內容(好比一條完整的新聞快訊,包括多條文字+圖片的組合)所有放到一條推送裏,用戶點擊了一個 Action(如贊、踩、關注、甚至評論等),在推送裏馬上刷新 UI(如展現加星動畫、評論內容等)。

特色

  • 須要添加 Notification content extension
  • 徹底自定義 UI
  • 推送 UI 不能響應觸摸、點擊、滑動等任何手勢
  • 能夠響應 notification actions ####NotificationViewController.h/m
  • 繼承自 UIViewController,並實現了 UNNotificationContentExtension 協議。
  • 能夠在 viewDidLoad 裏定製你想要的 UI
  • 在 didReceiveNotification 方法裏接收推送內容,而後各類處理邏輯、傳值、展現 UI 等等。當點擊了 actions,也會走到這裏,而且包含一個 action 的字段,判斷點擊了哪一個 action 進而相應的更新你的 UI。 ###Content Extension 有一個獨立的ViewController, 能夠本身定製Notification使用3D Touch展開後的UI和內容 ###User Input Customization Alt text Media buttons :play pause

Action :可定製, 例如點贊, 評論

Custom Input View:整個底部的空間能夠定製一個View

小結

感受 Notification Content 的功能極其強大,有了它以後連 App 都不須要再啓動了的樣子(只要能合理的設計展現內容和操做),省去了用戶每次爲了一項簡單操做都要進行「啓動 App - 操做 - 切換到多任務界面 - 退出 App」這樣的繁瑣過程。本來用戶看到推送可能不太有意願去查看詳細內容,如今他只須要很簡單的操做就能快速的查看,大幅提高用戶點擊通知的意願 究其如此便捷的緣由,Notification Service Extension 和 Notification Content 都是獨立於項目的 target,收到推送後,系統會單獨運行這兩個 target,徹底不會在此時去啓動 App 並執行 App 中大量的代碼,童鞋們在調試的時候也能夠注意這一點。

相關文章
相關標籤/搜索