{"id":3292,"date":"2023-06-10T16:19:23","date_gmt":"2023-06-10T20:19:23","guid":{"rendered":"https:\/\/michaelrowe01.com\/?p=3292"},"modified":"2023-06-10T16:19:26","modified_gmt":"2023-06-10T20:19:26","slug":"update-live-activities-with-push-notifications","status":"publish","type":"post","link":"https:\/\/michaelrowe01.com\/index.php\/blog\/update-live-activities-with-push-notifications\/","title":{"rendered":"Update Live Activities with Push Notifications"},"content":{"rendered":"\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"660\" height=\"371\" data-attachment-id=\"3296\" data-permalink=\"https:\/\/michaelrowe01.com\/index.php\/blog\/update-live-activities-with-push-notifications\/attachment\/%ef%a3%bfwwdc23-38\/\" data-orig-file=\"https:\/\/i0.wp.com\/michaelrowe01.com\/wp-content\/uploads\/2023\/06\/%EF%A3%BFWWDC23-38.png?fit=1920%2C1080&amp;ssl=1\" data-orig-size=\"1920,1080\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"\uf8ffWWDC23-38\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/michaelrowe01.com\/wp-content\/uploads\/2023\/06\/%EF%A3%BFWWDC23-38.png?fit=660%2C371&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/michaelrowe01.com\/wp-content\/uploads\/2023\/06\/%EF%A3%BFWWDC23-38.png?resize=660%2C371&#038;ssl=1\" alt=\"\" class=\"wp-image-3296\" srcset=\"https:\/\/i0.wp.com\/michaelrowe01.com\/wp-content\/uploads\/2023\/06\/%EF%A3%BFWWDC23-38.png?resize=1024%2C576&amp;ssl=1 1024w, https:\/\/i0.wp.com\/michaelrowe01.com\/wp-content\/uploads\/2023\/06\/%EF%A3%BFWWDC23-38.png?resize=300%2C169&amp;ssl=1 300w, https:\/\/i0.wp.com\/michaelrowe01.com\/wp-content\/uploads\/2023\/06\/%EF%A3%BFWWDC23-38.png?resize=768%2C432&amp;ssl=1 768w, https:\/\/i0.wp.com\/michaelrowe01.com\/wp-content\/uploads\/2023\/06\/%EF%A3%BFWWDC23-38.png?resize=1536%2C864&amp;ssl=1 1536w, https:\/\/i0.wp.com\/michaelrowe01.com\/wp-content\/uploads\/2023\/06\/%EF%A3%BFWWDC23-38.png?w=1920&amp;ssl=1 1920w, https:\/\/i0.wp.com\/michaelrowe01.com\/wp-content\/uploads\/2023\/06\/%EF%A3%BFWWDC23-38.png?w=1320&amp;ssl=1 1320w\" sizes=\"auto, (max-width: 660px) 100vw, 660px\" \/><\/figure>\n\n\n\n<p>ActivityKit allows you to display live activities to show status and updates<\/p>\n\n\n\n<p>Preparations<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>You should understand how push notifications work.&nbsp; Your App can request a push token (APNS) so you can send it to a server before you can send push tokens.&nbsp; APNS then sends the payload to the device.<\/li>\n\n\n\n<li>There is a new APNS live activity push type &#8211; only available with Token-based connection based apps.<\/li>\n\n\n\n<li>Modify your app so it can handle push notifications &#8211; add the capability in Signing and Capabilities in Xcode<\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"660\" height=\"316\" data-attachment-id=\"3295\" data-permalink=\"https:\/\/michaelrowe01.com\/index.php\/blog\/update-live-activities-with-push-notifications\/attachment\/attributes-adventure\/\" data-orig-file=\"https:\/\/i0.wp.com\/michaelrowe01.com\/wp-content\/uploads\/2023\/06\/attributes-adventure.png?fit=1491%2C713&amp;ssl=1\" data-orig-size=\"1491,713\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"attributes-adventure\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/michaelrowe01.com\/wp-content\/uploads\/2023\/06\/attributes-adventure.png?fit=660%2C316&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/michaelrowe01.com\/wp-content\/uploads\/2023\/06\/attributes-adventure.png?resize=660%2C316&#038;ssl=1\" alt=\"\" class=\"wp-image-3295\" srcset=\"https:\/\/i0.wp.com\/michaelrowe01.com\/wp-content\/uploads\/2023\/06\/attributes-adventure.png?resize=1024%2C490&amp;ssl=1 1024w, https:\/\/i0.wp.com\/michaelrowe01.com\/wp-content\/uploads\/2023\/06\/attributes-adventure.png?resize=300%2C143&amp;ssl=1 300w, https:\/\/i0.wp.com\/michaelrowe01.com\/wp-content\/uploads\/2023\/06\/attributes-adventure.png?resize=768%2C367&amp;ssl=1 768w, https:\/\/i0.wp.com\/michaelrowe01.com\/wp-content\/uploads\/2023\/06\/attributes-adventure.png?w=1491&amp;ssl=1 1491w, https:\/\/i0.wp.com\/michaelrowe01.com\/wp-content\/uploads\/2023\/06\/attributes-adventure.png?w=1320&amp;ssl=1 1320w\" sizes=\"auto, (max-width: 660px) 100vw, 660px\" \/><\/figure>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Requesting a Push Token is an asynchronous process, so you can\u2019t request one immediately after registering your app with the pushType: .token in the above code.&nbsp; The proper way to handles is to setup a Task that awaits for the appropriate activity, etc.&nbsp;<\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"660\" height=\"178\" data-attachment-id=\"3294\" data-permalink=\"https:\/\/michaelrowe01.com\/index.php\/blog\/update-live-activities-with-push-notifications\/attachment\/screenshot-2023-06-10-at-15-55-29\/\" data-orig-file=\"https:\/\/i0.wp.com\/michaelrowe01.com\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-10-at-15.55.29.png?fit=1615%2C435&amp;ssl=1\" data-orig-size=\"1615,435\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Screenshot-2023-06-10-at-15.55.29\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/michaelrowe01.com\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-10-at-15.55.29.png?fit=660%2C178&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/michaelrowe01.com\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-10-at-15.55.29.png?resize=660%2C178&#038;ssl=1\" alt=\"\" class=\"wp-image-3294\" srcset=\"https:\/\/i0.wp.com\/michaelrowe01.com\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-10-at-15.55.29.png?resize=1024%2C276&amp;ssl=1 1024w, https:\/\/i0.wp.com\/michaelrowe01.com\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-10-at-15.55.29.png?resize=300%2C81&amp;ssl=1 300w, https:\/\/i0.wp.com\/michaelrowe01.com\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-10-at-15.55.29.png?resize=768%2C207&amp;ssl=1 768w, https:\/\/i0.wp.com\/michaelrowe01.com\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-10-at-15.55.29.png?resize=1536%2C414&amp;ssl=1 1536w, https:\/\/i0.wp.com\/michaelrowe01.com\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-10-at-15.55.29.png?w=1615&amp;ssl=1 1615w, https:\/\/i0.wp.com\/michaelrowe01.com\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-10-at-15.55.29.png?w=1320&amp;ssl=1 1320w\" sizes=\"auto, (max-width: 660px) 100vw, 660px\" \/><\/figure>\n\n\n\n<ul class=\"wp-block-list\">\n<li>In the above code we convert to Hexadecimal string for debugging purposes<\/li>\n<\/ul>\n\n\n\n<p>First push update<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>This is an http request to APNs &#8211; you must provide the following headers\n<ul class=\"wp-block-list\">\n<li>apns-push-type: live activity<\/li>\n\n\n\n<li>apns-topic: &lt;BUNDLE_ID&gt;.push-type.liveactivity<\/li>\n\n\n\n<li>apns-priority: 5 <strong><em>this is low priority, high priority is 10<\/em><\/strong><\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>Your payload is a package with appropriate values.&nbsp; In the ranger app it looks like this<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>{\n\t\u201caps\u201d: {\n\t\t\u201ctimestamp\u201d: 1685952000,\n\t\t\u201cevent\u201d: \u201cupdate\u201d,\n\t\t\u201ccontent-state\u201d: {\n\t\t\t\u201ccurrentHealthLevel\u201d: 0.941,\n\t\t\t\u201ceventDescription\u201d: \u201cPower Panda found a sword!\u201d\n\t\t}\n\t}\n}\n<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Note the timestamp is seconds since 1970, event is the action for the live activity &#8211; it should be update or end, content-state is the json package that the live activity to decide with data to be used \/ displayed.<\/li>\n\n\n\n<li>Don\u2019t set any custom encoding Strategies for your json &#8211; or the system may not function correctly<\/li>\n\n\n\n<li>You can use terminal to send info to APNS without requiring changes to your server &#8211; This is covered in the developer documentation&nbsp;<\/li>\n\n\n\n<li>If you use terminal grab the push token from the log in the step above and set an environment variable of ACTIVITY_PUSH_TOKEN with the value\n<ul class=\"wp-block-list\">\n<li>Now if you use the terminal to test your push notification it will have the correct token&nbsp;<\/li>\n\n\n\n<li>Here\u2019s a sample CURL command<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-image size-large\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"660\" height=\"324\" data-attachment-id=\"3293\" data-permalink=\"https:\/\/michaelrowe01.com\/index.php\/blog\/update-live-activities-with-push-notifications\/attachment\/screenshot-2023-06-10-at-16-07-03\/\" data-orig-file=\"https:\/\/i0.wp.com\/michaelrowe01.com\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-10-at-16.07.03.png?fit=1725%2C847&amp;ssl=1\" data-orig-size=\"1725,847\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"Screenshot-2023-06-10-at-16.07.03\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/michaelrowe01.com\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-10-at-16.07.03.png?fit=660%2C324&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/michaelrowe01.com\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-10-at-16.07.03.png?resize=660%2C324&#038;ssl=1\" alt=\"\" class=\"wp-image-3293\" srcset=\"https:\/\/i0.wp.com\/michaelrowe01.com\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-10-at-16.07.03.png?resize=1024%2C503&amp;ssl=1 1024w, https:\/\/i0.wp.com\/michaelrowe01.com\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-10-at-16.07.03.png?resize=300%2C147&amp;ssl=1 300w, https:\/\/i0.wp.com\/michaelrowe01.com\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-10-at-16.07.03.png?resize=768%2C377&amp;ssl=1 768w, https:\/\/i0.wp.com\/michaelrowe01.com\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-10-at-16.07.03.png?resize=1536%2C754&amp;ssl=1 1536w, https:\/\/i0.wp.com\/michaelrowe01.com\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-10-at-16.07.03.png?w=1725&amp;ssl=1 1725w, https:\/\/i0.wp.com\/michaelrowe01.com\/wp-content\/uploads\/2023\/06\/Screenshot-2023-06-10-at-16.07.03.png?w=1320&amp;ssl=1 1320w\" sizes=\"auto, (max-width: 660px) 100vw, 660px\" \/><\/figure>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Note you still need your authentication Token for the API based on our brearer token.&nbsp; And make sure you are using http2 to access the bearer token<\/li>\n\n\n\n<li>To debug look at device logs in Console app look at the following processes &#8211; liveactivitiesd, apsd, and chronod&nbsp;<\/li>\n<\/ul>\n\n\n\n<p>Priority and alerts<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Make sure you use the correct priority, start by using low priority &#8211; it is opportunistic and saves the users battery<\/li>\n\n\n\n<li>There is no limit to low priority updates<\/li>\n\n\n\n<li>High priority are delivered immediately, and there is a budget based on the device condition.<\/li>\n\n\n\n<li>If you have a frequent update requirement there is a \u201cRequires frequent high-priority Updates\u201d feature for apps, which get\u2019s a higher update budget, but may still be throttled&nbsp;<\/li>\n\n\n\n<li>Just add a new a new key to info.plist of NSSupportsLiveActivitiesFrequentUpdates=YES<\/li>\n\n\n\n<li>Note users can disable this&nbsp; &#8211; so check the .frequentPushesEnabled property in the ActivityAuthorizationInfo()<\/li>\n\n\n\n<li>You an add an alert object to a push notification &#8211; with&nbsp; a title, body, and sound &#8211; note you should localize this message via a localized string object.This will generate an alert on the device.&nbsp; To add custom sounds you must have it as an app resource and you can then set that in the payload.<\/li>\n<\/ul>\n\n\n\n<p>Enhancements<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Sending a push payload of \u201cevent\u201d: \u201cend\u201d &#8211; you can then add a custom dismissal-date (again in seconds since 1970).<\/li>\n\n\n\n<li>You can add a \u201cstale-date\u201d to allow a view to react to users missing an update &#8211; then update your UI to change state based on it.<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>ActivityKit allows you to display live activities to show status and updates Preparations First push update Priority and alerts Enhancements<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"hide_page_title":"","_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[2,3],"tags":[739,735,557,680],"class_list":["post-3292","post","type-post","status-publish","format-standard","hentry","category-blog","category-personal-softwareandit","tag-day-6","tag-live-activities","tag-push-notifications","tag-wwdc23"],"aioseo_notices":[],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p2aMa8-R6","jetpack-related-posts":[],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/michaelrowe01.com\/index.php\/wp-json\/wp\/v2\/posts\/3292","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/michaelrowe01.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/michaelrowe01.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/michaelrowe01.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/michaelrowe01.com\/index.php\/wp-json\/wp\/v2\/comments?post=3292"}],"version-history":[{"count":1,"href":"https:\/\/michaelrowe01.com\/index.php\/wp-json\/wp\/v2\/posts\/3292\/revisions"}],"predecessor-version":[{"id":3297,"href":"https:\/\/michaelrowe01.com\/index.php\/wp-json\/wp\/v2\/posts\/3292\/revisions\/3297"}],"wp:attachment":[{"href":"https:\/\/michaelrowe01.com\/index.php\/wp-json\/wp\/v2\/media?parent=3292"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/michaelrowe01.com\/index.php\/wp-json\/wp\/v2\/categories?post=3292"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/michaelrowe01.com\/index.php\/wp-json\/wp\/v2\/tags?post=3292"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}