# iOS 動態通知 (Live Actiivty) 的挑戰與機會 {%hackmd @mopcon/rkdTi5NTR %} > 從這開始 ## Content - Live Activity - Implementation - Case Study ## Live Activity ### Intro. - apple 在 iOS16 的新功能 - 會出現在上面 - demo - IG限時動態 - LinePay - UberEat ### Device Support Smart Stack / Locj Screen / Dynamic Islabd - iOS 16: iPhone - iOS 17: iPad - iOS 18: Apple Watch ### Restrictions - can not access network, location - at most 5 live activities on a device - 8+4 hrs, lifetime - 啟動後8hr內可更新 - 8+4 lifetime - Payload 4KB - (unknown,官方文件沒有提供) 更新頻率 > create -> Update -> End - Local: 都可以 - Remote - create - push notification permission needed - PushToStartToken needed - IOS 17.2+ - Update - Push Notification permission needed - PushToken needed - End - Push Notification permission needed - PushToken needed ### Activity State - Active -> 直接滑掉 -> Dismissed (Invisible, can not update) - Ended: Visible, can not update ## UI Presentation > - 動態島 > - 鎖定螢幕 > - 手錶 ### Dynamic Island 3 presentation mode - Compact Mode - Minimal - Expanded - 長按動態島 - four views: leading, center, bottom, trailing - iOS 17+ 手機橫放 ### Content (Medium) - alert: 自動展開通知 - Permission Request UI - 是否authorize該App live activitiy ### Apple Watch - iOS 18+ - View: Leading, Trailing ### Recap (table) ## Implementation ### Define Live Activity - declare `ActivityAttributes` - needs to be included by both app and its extensions ### Define Live Activity UI - All presentations (content, dynamic island) should be defined - 可以給空的view, 建議不要 ### Activity Families - get state -> return different UI - iOS 18才有支援,如何同時支援iOS 18之前&之後 - provide 2 activity configurations - Apple Watch? - 把該部分的抽出來 ### Remote Operations - iOS 17.2+ - push notification permission required - keey file required - call APNs API - 保護好key - PRIORITY - 1~10,只適用於自己的app中的優先級 - ACTIVITY_PUSH_TOKEN :::success ### Remote Start Flow - get `pushToStartToken`, 涉及到網路連線 - 存到 server - 組出request - 推播到裝置, live activity - local or remote 啟動後 -> upload `pushToken` to server - If user doesn't clikc the activity - Solution: ??反正要想辦法拿到 ::: ## Case Study > Line 購物 > get line points > time limited line points activity -> Line designed a live activity ### Live Activity: time limited - 商家icon - store them! - 放到4KB的那裏面 - push tokens upload fails - Plan and Design in advance - Can NOT request new live activity if it reaches the limit - Checks status when possible Manage it remotely and locally - 想辦法讓他點進App -> clear some notifications :::info ## Live Activity - new entrance to app - limitations - variants :::