ActivityKit

RSS for tag

Help people keep track of tasks and events that they care about with Live Activities on the Lock Screen, the Dynamic Island, and in StandBy.

Posts under ActivityKit tag

123 Posts
Sort by:

Post

Replies

Boosts

Views

Activity

Live Activity expanded leading/trailing regions VoiceOver focus misalignment
There seems to be a misalignment when using VoiceOver and selecting the leading/trailing regions in the expanded presentation for Live Activities. This is demonstrated with an extremely basic sample project, where the expanded region is defined by the following code: DynamicIsland { DynamicIslandExpandedRegion(.leading) { Text("Leading") } DynamicIslandExpandedRegion(.trailing) { Text("Trailing") } DynamicIslandExpandedRegion(.bottom) { Text("Bottom \(context.state.emoji)") } } Is this simply a bug or am I doing something incorrectly/is there a workaround?
2
0
378
Oct ’24
Can I fix this big difference between swiftui preview and actual watch widget layout?
Hi, working on customising my live activity Smart Stack layout for ios18. A thing that is very frustrating is that I consistently looks different for me in the Xcode preview and on the actual watch. See attached screenshots below. The sizes are different, and italic doesn't work on the watch, for example. It makes it time-consuming and unpredictable, so I was wondering if this is a known issue or if I'm doing something wrong, and also can I do anything? thanks edit: this is the layout: var body: some View { VStack(alignment: .center, spacing:4) { HStack(alignment: .center) { IconView(resource: "n-compact-w", bgColor: Color.checkedIn, padding: 2, paddingRight: 6, paddingBottom: 6) .frame(maxWidth: 25, maxHeight: 25).aspectRatio(1, contentMode: .fit) Text("Checked Out") .font(.title3).bold() } Text(status.loc) .font(.headline) .multilineTextAlignment(.center) Text(FormatUtils.getFormattedDateTime(status.time)).font(.subheadline) .multilineTextAlignment(.center).italic() } }
4
0
517
Oct ’24
live activity push channel management request return "TopicMismatch" when bundle in include capital letter
When I request channel list for bundle id "com.apnspush.LiveActivityPushDemo", the request returns "TopicMismatch". Then when I request channel list for bundle id "com.apnspush.liveactivitypush", the request return is normal. I have tried all my bundle ids that include capital letters, they all failed with "TopicMismatch". Does anyone know the reason? curl -v -X GET \ -H "authorization: bearer eyJhbGciOiJFUzI1NiIsImtpZCI6IkdZSDM5WEZMREEifQ.eyJpYXQiOjE3Mjg3MDM4MDksImlzcyI6IjNXSkdFRjI4R1kifQ.wruX6J4qaovq2X-ZlO7g0YyMWjt50g8YoMoZ4G9ZsLDI5wC8u7PFTaG05BmDvbEzLpzrK9ifwPeo5BJ2eZ3hTg" \ -H "apns-request-id: 2288cf3f-70d8-46a6-97d7-dd5d00867127" \ --http2 \ https://api-manage-broadcast.sandbox.push.apple.com:2195/1/apps/com.apnspush.LiveActivityPushDemo/all-channels Note: Unnecessary use of -X or --request, GET is already inferred. * Host api-manage-broadcast.sandbox.push.apple.com:2195 was resolved. * IPv6: (none) * IPv4: 17.138.176.4 * Trying 17.138.176.4:2195... * Connected to api-manage-broadcast.sandbox.push.apple.com (17.138.176.4) port 2195 * ALPN: curl offers h2,http/1.1 * (304) (OUT), TLS handshake, Client hello (1): * CAfile: /etc/ssl/cert.pem * CApath: none * (304) (IN), TLS handshake, Server hello (2): * (304) (IN), TLS handshake, Unknown (8): * (304) (IN), TLS handshake, Request CERT (13): * (304) (IN), TLS handshake, Certificate (11): * (304) (IN), TLS handshake, CERT verify (15): * (304) (IN), TLS handshake, Finished (20): * (304) (OUT), TLS handshake, Certificate (11): * (304) (OUT), TLS handshake, Finished (20): * SSL connection using TLSv1.3 / AEAD-AES256-GCM-SHA384 / [blank] / UNDEF * ALPN: server accepted h2 * Server certificate: * subject: C=US; ST=California; O=Apple Inc.; CN=api-manage-broadcast.sandbox.push.apple.com * start date: May 30 17:31:41 2024 GMT * expire date: Apr 10 00:00:00 2025 GMT * subjectAltName: host "api-manage-broadcast.sandbox.push.apple.com" matched cert's "api-manage-broadcast.sandbox.push.apple.com" * issuer: CN=Apple Public Server RSA CA 12 - G1; O=Apple Inc.; ST=California; C=US * SSL certificate verify ok. * using HTTP/2 * [HTTP/2] [1] OPENED stream for https://api-manage-broadcast.sandbox.push.apple.com:2195/1/apps/com.apnspush.LiveActivityPushDemo/all-channels * [HTTP/2] [1] [:method: GET] * [HTTP/2] [1] [:scheme: https] * [HTTP/2] [1] [:authority: api-manage-broadcast.sandbox.push.apple.com:2195] * [HTTP/2] [1] [:path: /1/apps/com.apnspush.LiveActivityPushDemo/all-channels] * [HTTP/2] [1] [user-agent: curl/8.7.1] * [HTTP/2] [1] [accept: */*] * [HTTP/2] [1] [authorization: bearer eyJhbGciOiJFUzI1NiIsImtpZCI6IkdZSDM5WEZMREEifQ.eyJpYXQiOjE3Mjg3MDM4MDksImlzcyI6IjNXSkdFRjI4R1kifQ.wruX6J4qaovq2X-ZlO7g0YyMWjt50g8YoMoZ4G9ZsLDI5wC8u7PFTaG05BmDvbEzLpzrK9ifwPeo5BJ2eZ3hTg] * [HTTP/2] [1] [apns-request-id: 2288cf3f-70d8-46a6-97d7-dd5d00867127] > GET /1/apps/com.apnspush.LiveActivityPushDemo/all-channels HTTP/2 > Host: api-manage-broadcast.sandbox.push.apple.com:2195 > User-Agent: curl/8.7.1 > Accept: */* > authorization: bearer eyJhbGciOiJFUzI1NiIsImtpZCI6IkdZSDM5WEZMREEifQ.eyJpYXQiOjE3Mjg3MDM4MDksImlzcyI6IjNXSkdFRjI4R1kifQ.wruX6J4qaovq2X-ZlO7g0YyMWjt50g8YoMoZ4G9ZsLDI5wC8u7PFTaG05BmDvbEzLpzrK9ifwPeo5BJ2eZ3hTg > apns-request-id: 2288cf3f-70d8-46a6-97d7-dd5d00867127 > * Request completely sent off < HTTP/2 403 < apns-request-id: 2288cf3f-70d8-46a6-97d7-dd5d00867127 < * Connection #0 to host api-manage-broadcast.sandbox.push.apple.com left intact {"reason":"TopicMismatch"}% curl -v -X GET \ -H "authorization: bearer eyJhbGciOiJFUzI1NiIsImtpZCI6IkdZSDM5WEZMREEifQ.eyJpYXQiOjE3Mjg3MDM4MDksImlzcyI6IjNXSkdFRjI4R1kifQ.wruX6J4qaovq2X-ZlO7g0YyMWjt50g8YoMoZ4G9ZsLDI5wC8u7PFTaG05BmDvbEzLpzrK9ifwPeo5BJ2eZ3hTg" \ -H "apns-request-id: 2288cf3f-70d8-46a6-97d7-dd5d00867127" \ --http2 \ https://api-manage-broadcast.sandbox.push.apple.com:2195/1/apps/com.apnspush.liveactivitypush/all-channels Note: Unnecessary use of -X or --request, GET is already inferred. * Host api-manage-broadcast.sandbox.push.apple.com:2195 was resolved. * IPv6: (none) * IPv4: 17.138.176.4 * Trying 17.138.176.4:2195... * Connected to api-manage-broadcast.sandbox.push.apple.com (17.138.176.4) port 2195 * ALPN: curl offers h2,http/1.1 * (304) (OUT), TLS handshake, Client hello (1): * CAfile: /etc/ssl/cert.pem * CApath: none * (304) (IN), TLS handshake, Server hello (2): * (304) (IN), TLS handshake, Unknown (8): * (304) (IN), TLS handshake, Request CERT (13): * (304) (IN), TLS handshake, Certificate (11): * (304) (IN), TLS handshake, CERT verify (15): * (304) (IN), TLS handshake, Finished (20): * (304) (OUT), TLS handshake, Certificate (11): * (304) (OUT), TLS handshake, Finished (20): * SSL connection using TLSv1.3 / AEAD-AES256-GCM-SHA384 / [blank] / UNDEF * ALPN: server accepted h2 * Server certificate: * subject: C=US; ST=California; O=Apple Inc.; CN=api-manage-broadcast.sandbox.push.apple.com * start date: May 30 17:31:41 2024 GMT * expire date: Apr 10 00:00:00 2025 GMT * subjectAltName: host "api-manage-broadcast.sandbox.push.apple.com" matched cert's "api-manage-broadcast.sandbox.push.apple.com" * issuer: CN=Apple Public Server RSA CA 12 - G1; O=Apple Inc.; ST=California; C=US * SSL certificate verify ok. * using HTTP/2 * [HTTP/2] [1] OPENED stream for https://api-manage-broadcast.sandbox.push.apple.com:2195/1/apps/com.apnspush.liveactivitypush/all-channels * [HTTP/2] [1] [:method: GET] * [HTTP/2] [1] [:scheme: https] * [HTTP/2] [1] [:authority: api-manage-broadcast.sandbox.push.apple.com:2195] * [HTTP/2] [1] [:path: /1/apps/com.apnspush.liveactivitypush/all-channels] * [HTTP/2] [1] [user-agent: curl/8.7.1] * [HTTP/2] [1] [accept: */*] * [HTTP/2] [1] [authorization: bearer eyJhbGciOiJFUzI1NiIsImtpZCI6IkdZSDM5WEZMREEifQ.eyJpYXQiOjE3Mjg3MDM4MDksImlzcyI6IjNXSkdFRjI4R1kifQ.wruX6J4qaovq2X-ZlO7g0YyMWjt50g8YoMoZ4G9ZsLDI5wC8u7PFTaG05BmDvbEzLpzrK9ifwPeo5BJ2eZ3hTg] * [HTTP/2] [1] [apns-request-id: 2288cf3f-70d8-46a6-97d7-dd5d00867127] > GET /1/apps/com.apnspush.liveactivitypush/all-channels HTTP/2 > Host: api-manage-broadcast.sandbox.push.apple.com:2195 > User-Agent: curl/8.7.1 > Accept: */* > authorization: bearer eyJhbGciOiJFUzI1NiIsImtpZCI6IkdZSDM5WEZMREEifQ.eyJpYXQiOjE3Mjg3MDM4MDksImlzcyI6IjNXSkdFRjI4R1kifQ.wruX6J4qaovq2X-ZlO7g0YyMWjt50g8YoMoZ4G9ZsLDI5wC8u7PFTaG05BmDvbEzLpzrK9ifwPeo5BJ2eZ3hTg > apns-request-id: 2288cf3f-70d8-46a6-97d7-dd5d00867127 > * Request completely sent off < HTTP/2 200 < apns-request-id: 2288cf3f-70d8-46a6-97d7-dd5d00867127 < * Connection #0 to host api-manage-broadcast.sandbox.push.apple.com left intact {"channels":["vtVPwIhLEe8AAG79CdMNuQ=="]}%
1
0
358
Oct ’24
Get Cache error with ActivityKit when reboot App。
We are currently experiencing the following weird issue with our iPhone app. As the title says, NSUserDefaults is losing our custom keys and values when phone is rebooted but not unlocked, and this is happening on a very specific scenario with ActivityKit. Context: We are using the NSUserDefaults in the app to store user data (e.g. username). Issue: An error occurred with no permission to access cached messages after a restart. Scenario: When receiving a Dynamic Island notification, if the phone is restarted, after unlocking the phone and tapping on the Dynamic Island to open the App, all cached information results in an error. Reasons for the error: After restarting the APP, the files are in a locked state. The Dynamic Island proactively invokes the App method. When executing the startup method and retrieving cached messages, an error occurs due to lack of permission. All storage, including files, NSUserDefaults, Keychain, and Plist retrieval, results in errors. The error message is as follows: { "errorCode": "-25308", "errorDesc": "Error Domain=com.samsoffes.sskeychain Code=-25308 "(null)"", "serviceName": "com.qunar.qunarclient8", "account": "iid" } The data returned at this time is in a protected state, [UIApplication sharedApplication].isProtectedDataAvailable. Any help or idea will be truly appreciated :)
0
0
270
Oct ’24
How can I use an image for my live activity smartstack layout?
Hello, I am updating my live activity for the new ios18 Smart Stack functionality. I got it working through the WWDC session (Bring your live activities to Apple watch). I'm doing supplementalActivityFamilies([.small]) and then a custom layout in the .small ActivityFamily However, any images I try to use in the Smart Stack just show up as grey squares. (it works on the phone live activity) I suspect it's because my app images are not moved over to the watch? Because I don't have a watch app and such no watch target? If anyone can help me understand if there's anything I can do in order to have a custom image show up on the smart stack, I'd be very grateful.
3
0
544
Oct ’24
How to disable Live Activity on Apple Watch while keeping it enabled on iPhone?
I'm using Live Activity features in my app, but I want to customize the user experience across different Apple devices. Specifically, I'd like to: Keep Live Activity enabled and functioning on the iPhone Disable or prevent Live Activity from appearing on the connected Apple Watch Is this level of device-specific control possible with Live Activity? If so, what's the best approach to implement this functionality? What I've tried: I've looked through Apple's documentation on Live Activity, but couldn't find specific information about device-level control. I've experimented with ActivityKit, but haven't found a clear way to distinguish between iPhone and Apple Watch when pushing updates.
4
0
1k
Oct ’24
Obtaining LiveActivities pushToStart token
I want to add Live Activities to my e-commerce app to show the estimated delivery ETA when an order is out for delivery, with the Live Activity initiated from the server. Issue 1: How can I consistently obtain a pushToStart token when a user logs in to my e-commerce app? Currently, I’m considering starting and ending a dummy Live Activity to retrieve the token. Is there a better way to trigger pushToStartTokenUpdates and send the token to my server? Issue 2: How do I properly invalidate the pushToStart token when a user logs out, ensuring the next user doesn’t inherit the same token? Ideally, I don't want the user to wait until the token is automatically invalidated before logging out.
2
0
476
Oct ’24
Live Activity activityBackgroundTint not using dark mode colour variant
I have defined a colour in the asset catalog of my widget extension. I am using this widget extension for my live activity. This colour has both an ‘Any’ and ‘Dark’ appearance. I am using this colour in the activityBackgroundTint modifier for my main live activity view (the ActivityPreviewViewKind is content, visible on the Lock Screen). In light mode, this works as expected, but in dark mode, the background colour is still the light mode variant. The content within the view changes according to whether the system is in light or dark mode, but the background does not. I want to avoid using just the background modifier instead of activityBackgroundTint, as this does not colour the ‘Allow Live Activities from …’ and ‘Clear’ sections, which is undesirable. I have also tried reading colorScheme from the environment and choosing the light or dark mode colour variant accordingly, but this workaround also doesn’t completely work. If you keep changing from light and dark mode (via the Settings app, not the control centre, for whatever reason), the background colour actually becomes the opposite of the expected value in this case. Is there a workaround that can help me achieve what I want, or am I simply doing something wrong? I have filed a bug report under FB15148099
1
2
441
Sep ’24
Change in iOS 18 prevents SwiftData synchronization between main app and extension
I have a Live Activity with a button that updates a SwiftData model. This used to work in iOS 17, but not on iOS 18. The reason is that in iOS 17, when you run an AppIntent from a Live Activity, the perform() method would run in the main app's process, meaning it had access to the app's ModelContainer/ModelContext. However, in iOS 18, this is no longer the case, and the perform() method of an AppIntent now runs in the extension's process. While I can still construct a new ModelContainer & ModelContext in the AppIntent's perform() method, the main app's container and context will not see these changes until the app is relaunched. How can I make this work in iOS 18 now that an AppIntent executed from an extension runs in a different process from the main app?
1
0
650
Sep ’24
After interacting with a button in the live activity, the Control widget and home screen widget did not update.
I have a button on a live activity, and I want to end the live activity and update the Control Center widgets and home screen widgets after clicking this button. So, in the perform() method of the button's LiveActivityIntent, I called the methods ControlCenter.shared.reloadAllControls() and WidgetCenter.shared.reloadAllTimelines(), but they didn't work. Home screen widgets and Control Center widgets do not refresh, resulting in a poor user experience.
1
0
360
Sep ’24
Syncing changes between main app and extension
I have an app that starts a Live Activity on a certain user action. This Live Activity contains a button that the user can tap, which updates a SwiftData model instance. However, when you return to the main app after tapping the button on the Live Activity, the views do not update to reflect the changes, even though the changes were written to the database. The underlying issue here is that the ModelContainer/ModelContext used by the AppIntent (performed from the LiveActivity when the button is tapped), are different from the instances in the main app. Meaning that while the changes are written to the underlying storage, the in-memory instances of ModelContext/ModelContainer in the main app don't get the changes from the extension, so SwiftUI doesn't update either. What is the recommended way to handle this scenario? Or is there one? :) Shared access to a SwiftData container is clearly supported through App Groups, so is there not a mechanism to ensure changes made by an extension are updated in real-time for the main app? Otherwise, it seems I would have to go through and manually rerun queries that views depend on to make sure they are showing the most recent data. This is cumbersome and error-prone. Perhaps I'm missing something? Any suggestions would be greatly appreciated.
3
0
772
Sep ’24
Live activity sample code for Swift 6?
Hi, I'm updating our app to use Xcode 16 and Swift 6 language mode. I'm stuck on updating our live activity code. I looked at the Emoji Rangers sample project and after switching it to Swft 6 mode, it has the exact same errors as our project. The main problem seems to be that Activity is not Sendable, which prevents us from passing it to child tasks to await things like activityStateUpdates and contentUpdates (those are also not Sendable). Is there any guidance on this? Updated sample code? Another project?
4
0
730
Sep ’24
How to get new push token for Live Activity using input-push-token option
The documentation doesn't state how to get the new APNs push token that is associated with a Live Activity that is started via an APNs push notification. I have been able to get the new token by listening to all instances of the Live Activities for my attribute type, but it makes me wonder how the "input-push-token" option for iOS 18 is supposed to work. Is there another way to retrieve the newly created Live Activity push token when using "input-push-token"?
1
1
550
Sep ’24
Is there any way to start a live activity from a geofence trigger?
Hello, we have an app that has a case where the user can turn on a feature that starts a timer for a thing when they arrive at a specific location. Our app also has a live activity to show the timer. Naturally, we're trying to make our live activity to start counting when the geofence triggers, but we get ActivityAuthorizationError.visibility. If an activity is already running, it's possible to turn it off. So, our question is basically if there's any way to make the geofence trigger start our live activity? Thanks
3
0
638
Oct ’24
Live Activity Does Not Appear on devices running iOS 17, built with Xcode 16
We are facing a serious issue affecting the Live Activity of the our app. If the app is built with Xcode 16 (16A242) the Live Activity does not appear on devices running iOS 17. The live activity does appear on devices running iOS 18 RC. If we build the code with Xcode 15, the Live Activity appears on iOS 17 as expected. To investigate this we also prepared a demo bare-bones project to make sure the Live Activity presence is not affected by part of the existing code. Again the issue appears even of the demo app. Is this a known issue with Xcode16/iOS 18?
8
3
2.6k
Nov ’24
Where to retrieve Live activity update token that was started with ActivityKit push notifications using push-to-start token?
I can successfully start a Live Activity using push-to-start token, but in order to update the Live Activity i need another token as stated in the docs: While the system starts the new Live Activity and wakes up your app, you receive the push token you use for updates. When the app is open, i can retrieve this update token and successfully update the Live Activity using this example code: func observeActivityPushToken() { Task { for await activityData in Activity<LiveActivityAttributes>.activityUpdates { Task { for await tokenData in activityData.pushTokenUpdates { let token = tokenData.map { String(format: "%02x", $0) }.joined() print("Push token: \(token)") } } } } } But when the app is closed, how/where do i manage to get this update token and send it to the server "when the system wakes up the app"?
2
2
543
Sep ’24
Live Activities Random Loading Spinner
Somewhat rarely, but often enough to be a problem, our live activities will entirely lock up with a frozen progress spinner and a dimmed appearance. We cannot figure out what this spinner means nor how to avoid it as it is not documented anywhere. No logs appear in Xcode nor in Console.app. We have more frequent updates enabled and are sending an update maybe once every 2 minutes, nothing that should cause us to exceed our quota. We cannot reproduce in a debugger Can we get some guidance on how to avoid this?
7
2
838
Sep ’24
How to create a custom TimeDataSource?
Hello. I am working with the iOS 18b8 and Xcode 16b6 betas, updating a Live Activity Widget to adopt the new FormatStyle variants of the SwiftUI Text views. We used to use: Text(workoutStartDate, style: .relative) and it seems with iOS 18 we can replace it with: Text(workoutStartDate, format: .relative(presentation: .numeric, unitsStyle: .wide)) The former code would auto-increment, allowing a user to look at their Live Activity and see the duration of their workout so far ticking by. The new code does provide a nice relative duration string, but it doesn't auto-increment in the Live Activity's View – I need that functionality. I also updated other Texts in the Live Activity's View to adopt the .timer and .stopwatch FormatStyles. Those auto-increment and update no problem – once I realized I needed to provide a TimeDataSource<Date>.currentDate and not a simple Date. But in this .relative case, there is no auto-incrementing, and I'm guessing it may be due to providing a Date (workoutStartDate) and not a TimeDataSource<Date> as TimeDataSource seems to be the magic to make the Text auto-increment (or it's possible this format simply doesn't support auto-increment? bummer if so since the prior way did). How can I have a TimeDataSource<Date> that vends my arbitrary date (workoutStartDate)? I dug around, didn't find anything, but I wouldn't be surprised if I was overlooking something. PS: I have tried other approaches to solve this, such as simply using a .timer or .stopwatch format. That would change the under experience under iOS 18, and we think degrade it (the relative textual representation is nicer and provides distinction from the .timer also in the same View). We could keep the former approach, despite the minor layout issues under iOS 18. I have considered additional approaches as well – and am totally open to more! Here tho, I am truly curious how one might provide a custom TimeDataSource anchored at a date we provide (perhaps dynamically). Thank you.
1
1
524
Oct ’24