Skip to content

Conversation

@strebl
Copy link
Contributor

@strebl strebl commented Nov 5, 2025

Add Live Activities Support for iOS Push Notifications

Summary

This PR adds comprehensive support for iOS Live Activities push notifications by introducing new properties and methods to the ApnMessage class and updating the ApnAdapter to properly handle these fields when creating push notification payloads.

Changes

New Properties and Methods in ApnMessage

  • contentState(?array $contentState) - Sets the content state for live activities
  • event(?string $event) - Sets the event type for live activities
  • timestamp(?int $timestamp) - Sets the timestamp for live activities
  • attributesType(?string $attributesType) - Sets the attributes type for live activities
  • attribute(string $key, mixed $value) - Adds a single attribute for live activities
  • setAttributes(array $attributes) - Sets all attributes for live activities
  • dismissalDate(?int $dismissalDate) - Sets the dismissal date for live activities

Updates to ApnAdapter

  • Added support for adapting contentState, event, timestamp, attributesType, attributes, and dismissalDate from ApnMessage to the Pushok payload

Test Coverage

  • Added comprehensive unit tests for all new methods in ApnMessageTest
  • Added adapter tests in ApnAdapterTest to verify proper payload adaptation

Usage Example

use NotificationChannels\Apn\ApnMessage;

$message = ApnMessage::create()
    ->pushType(ApnMessage::PUSH_TYPE_LIVE_ACTIVITY)
    ->contentState([
        'status' => 'active',
        'count' => 5
    ])
    ->event('update')
    ->timestamp(1234567890)
    ->attributesType('CounterAttributes')
    ->attribute('title', 'My Custom Title')
    ->dismissalDate(now()->addMinutes(10)->timestamp);

Copy link
Collaborator

@dwightwatson dwightwatson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this.

Happy to add support for live activities - trying to find the best path forward and appreciate your help understanding the implementation.

Wondering if there is a case to have a separate "message" object for sending a live activity? If we go that path perhaps I need to break out additional message classes like Message, VoipMessage and BackgroundMessage.

$alert = null;

if ($message->pushType !== ApnMessage::PUSH_TYPE_BACKGROUND) {
if ($message->pushType !== ApnMessage::PUSH_TYPE_BACKGROUND && $message->pushType !== ApnMessage::PUSH_TYPE_LIVE_ACTIVITY) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Forgive me, as I'm a little out of touch with where APNS is at these days. How many options for push type are there? Looks like internally we have null, background and voip supported.

I wonder if these should be moved into an enum like some of the other ones in the package - ApnMessageType.


Is a liveactivity effectively a background type as well?

/**
* The attributes for live activities.
*/
public array $attributes = [];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My concern with things like this (and perhaps timestamp too) is it it's not clear that these are specific to live activities at all without reading the comment.

Is there instead a possibility that a Live Activity should be represented by a different class than an ApnMessage? Am I right in thinking that when sending a live activity update you aren't sending any of the normal ApnMessage attributes?

@dwightwatson dwightwatson merged commit 4c9dd29 into laravel-notification-channels:master Nov 6, 2025
1 check failed
@dwightwatson
Copy link
Collaborator

Thanks for this - I've merged it in and I'm going to massage a little bit. I may leave on the master branch for a bit to explore before tagging into a new release. Let me know if you run into any trouble.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants