Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for starting a Live Activity with input-push-token on iOS 18 #1079

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public abstract class ApnsPayloadBuilder {
private boolean preferStringRepresentationForAlerts = false;

private LiveActivityEvent event = null;
private Integer inputPushToken = null;

private Instant timestamp = null;

Expand Down Expand Up @@ -131,6 +132,7 @@ public abstract class ApnsPayloadBuilder {
private static final String ATTRIBUTES_TYPE_KEY = "attributes-type";
private static final String ATTRIBUTES_KEY = "attributes";
private static final String CONTENT_STATE_KEY = "content-state";
private static final String INPUT_PUSH_TOKEN_KEY = "input-push-token";

public static final String[] EMPTY_STRING_ARRAY = new String[0];

Expand Down Expand Up @@ -769,7 +771,7 @@ public ApnsPayloadBuilder addCustomProperty(final String key, final Object value
*
* @return a reference to this payload builder
*
* @see #setAttributes(Map)
* @see #setAttributes(Map)
* @see <a href="https://developer.apple.com/documentation/activitykit/starting-and-updating-live-activities-with-activitykit-push-notifications#Construct-the-payload-that-starts-a-Live-Activity">
* Construct the payload that starts a Live Activity</a>
* @see <a href="https://developer.apple.com/documentation/activitykit/activityattributes">ActivityKit - ActivityAttributes</a>
Expand All @@ -789,7 +791,7 @@ public ApnsPayloadBuilder setAttributesType(final String attributesType) {
*
* @return a reference to this payload builder
*
* @see #setAttributesType(String)
* @see #setAttributesType(String)
* @see <a href="https://developer.apple.com/documentation/activitykit/starting-and-updating-live-activities-with-activitykit-push-notifications#Construct-the-payload-that-starts-a-Live-Activity">
* Construct the payload that starts a Live Activity</a>
* @see <a href="https://developer.apple.com/documentation/activitykit/activityattributes/contentstate">ActivityKit - ContentState</a>
Expand Down Expand Up @@ -856,6 +858,19 @@ public ApnsPayloadBuilder setTimestamp(final Instant timestamp) {
return this;
}

/**
* <p>Sets the flag to wake up the app and receive a push token to send updates to the started Live Activity.</p>
Copy link
Owner

Choose a reason for hiding this comment

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

A couple comments here:

  1. If this is a single paragraph, I don't think we need <p> tags.
  2. While this isn't incorrect, I do think there's more of the story we can and should tell for callers. In particular: this is for establishing a new channel for live activities, and it's intended for iOS 18 and newer. If it's helpful to you, I'd be happy to suggest specific wording!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry for the delay! I have updated the Javadoc to provide a bit more info. If the changes are fine, otherwise I'm open for any suggestions. In general, I don't like rehashing info from the source (Apple docs in this case), since from the outside most of the time it feels like trying to documenting undocumented behavior.

*
* @return a reference to this payload builder
*
* @see <a href="https://developer.apple.com/documentation/activitykit/starting-and-updating-live-activities-with-activitykit-push-notifications">
* Starting and updating Live Activities with ActivityKit push notifications</a>
*/
public ApnsPayloadBuilder setInputPushToken() {
ifrins marked this conversation as resolved.
Show resolved Hide resolved
this.inputPushToken = 1;
return this;
}

/**
* <p>Sets a dismissal timestamp for Live Activity notifications. According to Apple's documentation:</p>
*
Expand Down Expand Up @@ -964,6 +979,10 @@ protected Map<String, Object> buildPayloadMap() {
aps.put(STALE_DATE_KEY, this.staleDate.getEpochSecond());
}

if (this.inputPushToken != null) {
aps.put(INPUT_PUSH_TOKEN_KEY, this.inputPushToken);
}

final Map<String, Object> alert = new HashMap<>();
{
if (this.alertBody != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,15 @@ void testAddContentStateProperty() {
assertEquals(subMap, serializedContentState.get(keyForMapValue));
}

@Test
void setInputPushToken() {
this.builder.setInputPushToken();

final Map<String, Object> aps = this.extractApsObjectFromPayloadString(this.builder.build());

assertEquals(1L, aps.get("input-push-token"));
}

@SuppressWarnings("unchecked")
private Map<String, Object> extractApsObjectFromPayloadString(final String payloadString) {
final Map<String, Object> payload;
Expand Down