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
368 stars 119 forks source link

adds keys that support live activities #162

Closed jolamar closed 1 year ago

jolamar commented 1 year ago

Proposed solution to issue #161

edamov commented 1 year ago

@jolamar Thank you for PR! It was added in 0.15.3

yetdog commented 1 year ago

This is AWESOME - only one question - given that content-state is a nested item ( like alert), how do you leverage $push->setContentState to assign the desired (and number of) key/values?

edamov commented 1 year ago

Hmm... Please check the example in the bottom of this comment - https://github.com/edamov/pushok/issues/161#issuecomment-1431778344 Is that what you want to achieve?

yetdog commented 1 year ago

Exactly - I had been using the individual methods thus far, but this is great. Thanks again Artur (and PR legend!)

jolamar commented 1 year ago
$payload = Payload::create()
            ->setTimestamp(Carbon::now()->timestamp)
            ->setEvent('update')
            ->setRelevanceScore(75.0)
            ->setStaleDate(Carbon::now()->addMinutes(60)->timestamp)
            ->setContentState(['ourScore' => 54, 'opponentScore' => 23]);

Content state can be anything you defined in your LiveActivityAttributes (Swift). So passing in an array should be enough. Here is how they define the key in the docs https://developer.apple.com/documentation/usernotifications/setting_up_a_remote_notification_server/generating_a_remote_notification#2943363

The updated or final content for a Live Activity. The content of this dictionary must match the data you describe with your custom ActivityAttributes implementation. For more information, see Updating and ending your Live Activity with remote push notifications.

jolamar commented 1 year ago

in Token.php we also need to add the pushtype for live activities ApnsTopic. I'll get another PR out for this but in case you need it now.

public function generateApnsTopic(string $pushType)
    {
        switch ($pushType) {
            case 'voip':
                return $this->appBundleId . '.voip';

            case 'liveactivity':
                return $this->appBundleId . '.push-type.liveactivity';

            case 'complication':
                return $this->appBundleId . '.complication';

            case 'fileprovider':
                return $this->appBundleId . '.pushkit.fileprovider';

            default:
                return $this->appBundleId;
        }
    }

Details here https://developer.apple.com/documentation/usernotifications/setting_up_a_remote_notification_server/sending_notification_requests_to_apns