I'm trying to develop a Live Activity Extension. The problem is, I can't get pushToStartToken
. I'm able to get it when I start a Live Activity, but I can't when I don't start a Live Activity.
This function successfully generates the token:
private func startNewLiveActivity() async { guard #available(iOS 16.2, *) else { return } let attributes = MyWidgetAttributes( homeTeam: "Badger", awayTeam: "Lion", date: "12/09/2023" ) let initialContentState = ActivityContent( state: MyWidgetAttributes.ContentState( homeTeamScore: 0, awayTeamScore: 0, lastEvent: "Match Start" ), staleDate: nil ) guard let activity = try? Activity.request( attributes: attributes, content: initialContentState, pushType: .token ) else { return } if #available(iOS 17.2, *) { Task { for await data in Activity< MyWidgetAttributes>.pushToStartTokenUpdates { let token = data.map { String(format: "%02x", $0) }.joined() // THE DESIRED pushToStartToken TOKEN IS GENERATED HERE } } } for await data in activity.pushTokenUpdates { let token = data.map { String(format: "%02x", $0) }.joined() // I send token to server here. } }
But when I try to get pushToStartToken
separately, without creating a live activity, it doesn't return any value:
private func getPushToStartToken() async { guard #available(iOS 17.2, *) else { return } Task { for await data in Activity<MyWidgetAttributes>.pushToStartTokenUpdates { let token = data.map { String(format: "%02x", $0) }.joined() // THIS DOESN'T GENERATE ANY TOKENS SINCE THE ACTIVITY IS NOT CREATED } } }