Yes, you can remotely start an iOS Live Activity using a push notification. This feature, known as 'Push to Start', is available for devices running iOS 17.2 and later.
The process involves two main steps: register the push-to-start token, then start the activity via the API.
Step 1: Register the pushToStartToken
Recommended: let the SDK do it. Call PushwooshLiveActivities.setup(YourLiveActivityAttributes.self) (or PushwooshLiveActivities.defaultSetup() if you use DefaultLiveActivityAttributes) at startup. The SDK then listens for both push-to-start and update token updates and sends them to Pushwoosh for you, so you do not have to track tokens manually.
If you prefer to handle the token yourself, observe pushToStartTokenUpdates and pass the token to the SDK:
func getPushToStartToken() {
if #available(iOS 17.2, *) {
Task {
for await data in Activity<LiveActivityAttributes>.pushToStartTokenUpdates {
let token = data.map { String(format: "%02x", $0) }.joined()
print("Activity PushToStart Token: \(token)")
// Send the pushToStart token to Pushwoosh
Pushwoosh.LiveActivities.sendPushToStartLiveActivity(token: token)
}
}
}
}
The SDK provides these methods for sending the token (neither is async or throwing):
static func sendPushToStartLiveActivity(token: String)static func sendPushToStartLiveActivity(token: String, completion: @escaping (Error?) -> Void)
Step 2: Start the Live Activity via API
Once the token is registered with Pushwoosh, start the Live Activity with a POST request to https://api.pushwoosh.com/json/1.3/startLiveActivity.
{
"request": {
"application": "XXXXX-XXXXX",
"auth": "YOUR_AUTH_API_TOKEN",
"notifications": [
{
"content": "Message",
"title": "Title",
"live_activity": {
"event": "start",
"content-state": {
"data": {
"emoji": "dynamic data"
}
},
"attributes-type": "DefaultLiveActivityAttributes",
"attributes": {
"data": {
"name": "static data"
}
}
},
"devices": [
"XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"
],
"live_activity_id": "your_activity_id"
}
]
}
}
Use the same live_activity_id later with /updateLiveActivity to update or end the activity.
Comments
0 comments
Please sign in to leave a comment.