I'm currently seeing that OS gets a new push-to-start token immediately after receiving the first notification.
Should my server immediately invalidate the push-to-start token upon usage?
Or invalidating the push-to-start token should only be done if my iOS device gets a new one and then I have to send it back to my server.
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
I have an ongoing activity in progress.
Think of:
a delivery in progress
house internet reboot in progress
some water / electricity / internet / tv outage.
(food) order processing
I want to show a persistent toast message above the tab bar, across all tabs and screens across the app. It could take 15 minutes until the activity is finished.
Obviously there's a challenge of:
accessibility
content overlaying with each other
extra engineering effort.
What we've thought of doing is:
Option1: show a toast message, but when a modal is presented then it presents on top of the toast message. The toast message no longer updates itself. Once the modal is finished, then the toast message re-appears and continues to update.
Option2: keep the toast message across all tabs and modals and work through the challenges mentioned
Question:
What are some other design approaches that could be taken to persist an ongoing activity (much like 'Live Activity', but just across the app when it's in foreground) or what are some design reasons that the two options considered are bad?
Confusion
Based on the fact that the subscription is requested on a Activity type, I assumed that the push-to-start tokens would be different. But the push-to-start token for WidgetExtensionAttributes and WidgetExtensionAttributesOther were identical. This is misleading.
The code below prints identical tokens even though the name of the token and their underlying schema are different.
Code Sample
func getTokens() {
Task {
if let data = Activity<func getTokens() {
Task {
if let data = Activity<WidgetExtensionAttributes>.pushToStartToken {
print("exists:", data.hexadecimalString)
} else {
print("requesting pushToStartToken")
for await ptsToken in Activity<WidgetExtensionAttributes>
.pushToStartTokenUpdates {
let ptsTokenString = ptsToken.hexadecimalString
print("new:", ptsTokenString)
}
}
}
Task {
if let data = Activity<WidgetExtensionAttributesOther>.pushToStartToken {
print("other exists:", data.hexadecimalString)
} else {
print("other requesting pushToStartToken")
for await ptsToken in Activity<WidgetExtensionAttributesOther>
.pushToStartTokenUpdates {
let ptsTokenString = ptsToken.hexadecimalString
print("other new:", ptsTokenString)
}
}
}
}>.pushToStartToken {
print("exists:", data.hexadecimalString)
} else {
print("requesting pushToStartToken")
for await ptsToken in Activity<WidgetExtensionAttributes>
.pushToStartTokenUpdates {
let ptsTokenString = ptsToken.hexadecimalString
print("new:", ptsTokenString)
}
}
}
Task {
if let data = Activity<WidgetExtensionAttributesOther>.pushToStartToken {
print("other exists:", data.hexadecimalString)
} else {
print("other requesting pushToStartToken")
for await ptsToken in Activity<WidgetExtensionAttributesOther>
.pushToStartTokenUpdates {
let ptsTokenString = ptsToken.hexadecimalString
print("other new:", ptsTokenString)
}
}
}
}
Activity Types
struct WidgetExtensionAttributesOther: ActivityAttributes {
public struct ContentState: Codable, Hashable {
var age: Int
}
var addresses: [String]
}
struct WidgetExtensionAttributes: ActivityAttributes {
public struct ContentState: Codable, Hashable {
var emoji: String
}
var name: String
}
Docs
After much investigation I noticed the wording of the docs kind of hint that the push-to-start token is per ActivityKit as it says:
An asynchronous sequence you use to observe changes to the token for starting a Live Activity with an ActivityKit push notification.
But docs and the API don't align well.
Questions
Is it correct that the push-to-start token is per app? If so then is there a reason that that API designers decided to still have to pass a specific type and not just make a request without passing a type?
Should I maybe file a radar?
Is it correct to say push-to-start is per app, while update tokens are per instance. i.e. if I have two soccer matches, then unless the push-to-start token was refreshed by the OS, then both would use the same push-to-start token, however each match would have a unique update token?
I've been reading this question: https://developer.apple.com/forums/thread/701945 and watching the videos on background tasks
But can't arrive to a concrete solution.
Q1: Are there any tips (or sample app) on how to handle a launch in background in a streamlined way? How to have a shared code that is ran for both 'launch in background' & 'launch in foreground'?
Specifically the case I'm talking about is:
You set up some observance of some OS callback at a Foo screen of your app. Example app should request and then send push-to-start live activity tokens to server. Or setup location tracking.
App is then suspended and then later terminated but is eligible for relaunch
App is then launched in background because it has requested a push-to-start live activity token or an update for location tracking.
User DOES NOT go back to screen Foo.
So at this point app is no longer tracking / listening to updates for token update or location changes.
How should I architecture my code for this? I'm trying to see if there's a an approach where I can avoid having multiple places in code where I do the same thing. Currently what I'm doing is as such:
Q2: Is it then correct to say that anytime you've launched your app, whether it's in foreground or background then you must immediately match 'all observations done by the previous app launch'?
Like store items in UserDefaults and upon launch retrieve them and do:
handleGeneralAppLaunchFlow()
// ALSO
if defaults.contains("didLastLaunchSetupLiveActivtiyTokenObservance") {
for await ptsToken in Activity<EmojiRangers> .pushToStartTokenUpdates {
...
}
}
if defaults.contains("didLastLaunchSetupLocationTracking") {
locationManager = CLLocationManager()
locationManager?.delegate = itsDelegate
locationManager?.allowsBackgroundLocationUpdates = true
locationManager?.showsBackgroundLocationIndicator = true
locationManager?.startUpdatingLocation()
}
// Other checks for prior observance setup
Q3: Actually I think even if app is launched in foreground then because you may not end up at screen Foo again, then you must setup things regardless of app state and just based on prior observations set. Right?
Q4: And then later if the user ever made it again to screen Foo, then we just skip the re-do of the observance, or maybe to just keep things simple, we'd just redo without over-engineering things?
I tried to mark my questions with Q1- Q4.
I tried dragging an apns file for a live activity into my simulator to begin a Live Activity.
It didn't do anything. I didn't see it mentioned in the wwdc videos either. So I'm wondering if this experience is not yet developed, or maybe I'm doing something incorrectly?
Can you please post the sample code?