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

95 Posts
Sort by:

Post

Replies

Boosts

Views

Activity

Dynamic Island lifecycle
I am implementing the live activity in my project, it is a timer live activity so I have to dismiss it after the time ends for the particular activity. so for that, I'm doing it like this : Task { await activity.end(dismissalPolicy: .after(Date().addingTimeInterval(TimeInterval(1 * time)))) } it is working fine for live activity but when I'm calling this method while creating the live activity my dynamic island is not visible. am I doing something wrong here or missing out something.
0
0
294
Oct ’23
Live Activity minimal presentation is cut off in iOS 17+
Hey there, I have noticed that my Live Activity's minimal presentation sometimes gets cut off when there is another app's Live Activity present. I tried adjusting the view in a number of ways, but it always seems to get cut off I'm just curious if this is a known issue with iOS 17, or if there is a potential workaround. This issue did not occur on iOS 16, and I've even updated to iOS 17.1 and the issue is still present. The view code is identical Here's the code that goes inside my minimal presentation ProgressView(timerInterval: Date.now...context.attributes.endDate, countsDown: true) { EmptyView() } currentValueLabel: { EmptyView() } .tint(.accent) And here is what ends up happening. I've also seen this with some of Apple's own Live Activities, so I'm assuming this is an iOS bug?
0
0
391
Oct ’23
Including a staleDate in Live Activity request causes activity to be disabled with loading spinner
When I try to initiate a Live Activity using the iOS 16.2 API for it, which includes the staleDate, when the staleDate has passed, rather than transitioning my Live Activity to its special ended state, the Live Activity presumably crashes because it looks disabled with a loading spinner on top My ActivityAttributes struct is fairly simple, and the code that displays the "ended" state is itself not crashing, so unsure if I am doing something wrong Here is the code for my ActivityAttributes: struct TimerActivityAttributes: ActivityAttributes { enum TimerType: Codable { case rest, work } public struct ContentState: Codable & Hashable { var isEnded: Bool } let endDate: Date let exerciseName: String? let timerType: TimerType init(endDate: Date, exerciseName: String? = nil, timerType: TimerType = .rest) { self.endDate = endDate self.exerciseName = exerciseName self.timerType = timerType } } Here is the code that activates the Live Activity: private func startLiveActivityNew( attributes: TimerActivityAttributes, contentState: TimerActivityAttributes.ContentState ) { guard let endDate else { return } let activityContent = ActivityContent(state: contentState, staleDate: endDate) do { ActivityManager.shared.activity = try Activity.request( attributes: attributes, content: activityContent ) } catch (let error) { print("Caught an error: \(error.localizedDescription)") } } Here is the code I use to determine whether to display the ended state (to maintain compatibility with iOS 16.1): private func isEnded(context: ActivityViewContext<TimerActivityAttributes>) -> Bool { if #available(iOS 16.2, *) { if context.state.isEnded || context.isStale { return true } } else if context.state.isEnded { return true } return false } And this is what happens after staleDate has passed. I'm just not sure if I'm missing anything in my implementation
1
0
551
Oct ’23
Live activity push token update condition
In this link, there is a description of live activity push token update: "The push token for a Live Activity may change throughout its duration. When your app receives a new token, it receives foreground runtime to process the updated token. Keep track of the push token for each Live Activity. Additionally, invalidate an outdated token on your server when you receive an updated token to successfully send subsequent updates." Our application did implement the solution to prepare for push token update. But so far, we don't see any occurrence of push token update from our backend records. The pushtokenupdates sequence only return the token once after live activity starts and does not emit more value afterward. Could you share a bit more on the condition for push token update? Under what circumstances will this happen? Thank you!
1
0
647
Nov ’23
Hello, I show image url on live activity not working on Device, but it show on simulator. Help me, i miss two weeks. Thanks
struct NetworkImage: View { let url: URL? var body: some View { Group { if let url = url, let imageData = try? Data(contentsOf: url), let uiImage = UIImage(data: imageData) { Image(uiImage: uiImage) .resizable() } else { Image("league") } } } } NetworkImage(url: URL(string: context.attributes.imageGame)) .aspectRatio(contentMode: .fill) .frame(width: 35, height: 35) .clipShape(Circle())
0
0
380
Nov ’23
Using dynamic island and picture in picture together
We are implementing new Live Activities in our app (we are a live shopping app). We also have PIP however i've noticed that when I start a live activity, then go into picture in picture, the dynamic island does not show the activity we've created for it. I can only see the activity on the lock screen widget while the audio for the videos plays. Is there any way to get the dynamic island to work with an app that is also in picture in picture? If there is and I'm doing something wrong, I can post some code. But from what I see, these don't seem to be compatible unfortunately :(
0
0
573
Nov ’23
Live Activity Interactivity & Background
Hi, I've been looking through the documentation for Live Activities and Activity Kit but I can't seem to get the answer to my question through the documentation. I have 2 questions: Is it possible to have a button on the live activity that shows & hides a certain element on the live activity? Is it possible to update the background color of the live activity? Thanks in advance, Sasri Product Designer
0
0
336
Nov ’23
Issue starting Live Activities with ActivityKit push notifications
Hi all, I'm trying to implement starting Live Activities with push notifications according to this article: https://developer.apple.com/documentation/activitykit/starting-and-updating-live-activities-with-activitykit-push-notifications I'm using Xcode 15.1 beta 3, I have run my tests on a physical device with iOS 17.2 as well as the simulator with iOS 17.2 My problem is I can't seem to be able to get the pushToStartToken needed to start the live activities. I have subscribed to the pushToStartTokenUpdates but I never get any updates. Here is the code I used: Task { do { for try await data in Activity<DailyGoalActivityAttributes>.pushToStartTokenUpdates { let token = data.map {String(format: "%02x", $0)}.joined() print("Activity token: \(token)") } } catch { print(error) } } Any help would be greatly appreciated. Thanks, HS
11
4
3.1k
May ’24
Live activity pushTokenUpdates not emitting any token
We are using the below getPushToken() function to retrieve live activity token. However there are cases in production such that await activity.getPushToken() never finish. i.e. have logs of start event and no return or end event, the code path stuck at the guard statement. Do anyone face same issue and if can advise what can go wrong and how best to handle such cases? // log start event guard let pushToken = await activity.getPushToken(), !pushToken.isEmpty else { // log return event return } // log end event extension Activity { public func getPushToken() async -> String? { for await data in pushTokenUpdates { return data.map { String(format: "%02x", $0) }.joined() } return nil } }
0
0
316
Nov ’23
APNS returns 200 - Device did not receive Live Activities update
Hello! Currently we are reviewing an issue whereby our users were obtaining Live Activities update, but somehow at the end, there were Live Activity updates that were not properly received by the device. For example: 20 Live Activity updates sent to device, 17 were properly received, however the last 3 were not properly received (as can be seen by the UI of it not updating). So far we have looked into a few root causes highlighted on the forums and on stackoverflow: Timestamp of APNS (every one of the APNS has a different timestamp) 200 is seen from the APNS side, which is why we were confused by the push notification did not arrive on the device side Looking into our logs, its unfortunately not covered enough to tell us when this had been received Some questions here: Is there a way we could log every Live Activity / Push Notification received from APNS? (for all scenario, app on lock screen, app in background) Anyway to track a push notification's lifecycle? I know the Push Notification Console tool is useful for debug usage, but we wanted to see if there's something similar for production usage as well.
0
0
457
Dec ’23
iOS 17 Live activity animations
I've been trying to implement an animation for my live activity. The animation is just rotating an image back and forth a bit and offsetting it up and down a bit. It'll give an airplane icon a subtle effect of "flying". Similar to the waveform animation in Apple Music, ie it's there for a it of visual flair. The documentation here states that withAnimation is ignored so I'm not entirely sure how these "constantly animating" effects are achieved. It seems like animations can only occur as transitions between states but it seems like overkill for my use-case of just wanting to animate a tiny bit of UI. Any advice would be greatly appreciated
0
0
449
Dec ’23
How exactly do I get push tokens from a Live Activity that was started remotely?
In iOS 17.2+, we have a new feature that lets you use a push notification to start a Live Activity. The docs mention this: While the system starts the new Live Activity and wakes up your app, you receive the push token you use for updates. How exactly does this work? I don’t see any listeners/delegate methods that trigger when you receive a start event. Since I need to extract the push tokens from a specific instance, how do I get that instance? I can call Activity<MyType>.activities to see all running Live Activities, but assuming my end user has multiple instances running, how do I locate the instance that was started remotely?
2
0
611
Dec ’23
DeviceTokenNotForTopic
Some users couldn't receive push notifications, and APNS returned a 'DeviceTokenNotForTopic' error. Upon validation using Apple's tool, I found that some tokens are identified as VoIP push tokens, and some as Live Activity (LA) push tokens. When attempting to send a normal alert push using these VoIP/LA push tokens, it didn't work and returned a 'DeviceTokenNotForTopic' error. These tokens were obtained from Apple's delegate function 'didRegisterForRemoteNotificationsWithDeviceToken.' It's unexpected to receive VoIP/LA push tokens from this event, but this issue is occurring, and I've observed it specifically in iOS 17 users. This problem is not universal and is happening only for some users. Please take note that our app support VoIP Push, Live Activity Push and Normal Push notification. Could this be an iOS 17 bug? Any advice on this matter would be appreciated. Thanks.
1
0
1.4k
Dec ’23