edamov / pushok

PHP client for Apple Push Notification Service (APNs) - Send push notifications to iOS using the new APNs HTTP/2 protocol with token-based (JWT with p8 private key)
MIT License
378 stars 120 forks source link

Live Activities Supported? #161

Closed yetdog closed 1 year ago

yetdog commented 1 year ago

Hi there. Been using this library to great success the past few years - love it - thank you so much!

I was wondering if Live Activities were supported in the payload structure already, or if modifications are required?

thanks much!

jolamar commented 1 year ago

I'm also wondering this. I think the Payload will need to be updated to support live activities https://github.com/edamov/pushok/blob/master/src/Payload.php#L33

{
    "aps": {
        "timestamp": 1168364460,
        "event": "update",
        "relevance-score": 75.0,
        "stale-date": 1650998941,
        "content-state": {
            "driverName": "Anne Johnson",
            "estimatedDeliveryTime": 1659416400
        },
        "alert": {
            "title": "Delivery Update",
            "body": "Your pizza order will arrive soon.",
            "sound": "example.aiff" 
        }
    }
}

https://developer.apple.com/documentation/activitykit/updating-and-ending-your-live-activity-with-activitykit-push-notifications

You can see the payload keys have expanded to include support for live activities: https://developer.apple.com/documentation/usernotifications/setting_up_a_remote_notification_server/generating_a_remote_notification#2943363

So I imagine the new Payload would look something like this:

Payload::create()
    ->setTimestamp(Carbon::now()->timestamp)
    ->setEvent('update')
    ->setRelevanceScore(75.0)
    ->setStaleDate(Carbon::now()->addMinutes(60)->timestamp)
    ->setContentState([
       'driverName' => 'Anne Johnson', 
       'estimatedDeliveryTime' => Carbon::now()->addMinutes(5)->timestamp
      ])
     ->setAlert($alert);
yetdog commented 1 year ago

Correct - I actually hacked this in myself, but mine is more primitive as I created a new class called ContentState - but manually added the field names as they align with my app. Im sure it can be written to be dynamic and definable in the script code, but I didn't go that far.

edamov commented 1 year ago

It was added in 0.15.3