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.

ActivityKit Documentation

Posts under ActivityKit tag

88 Posts
Sort by:
Post not yet marked as solved
11 Replies
6.2k Views
Is it possible to load an image from remote in the Live Activity using ActivityKit? I tried various different methods, but none of them are working including: AsyncImage Pre-fetching the image in the App and passing that image to Activity as a Data through the context when starting the activity and converting Data back to the Image
Posted
by
Post not yet marked as solved
19 Replies
5.8k Views
I had a timer app, it played white noise after starting the timer. so my app is running in the background with background audio, and the timer is perfect for display with live activity. However, when I test my code with a real device, I find calling await activity.update(using: contentState) when app is running in the background does not work at all. the code executes, but the live activity won't get updated. After some experiments, I find: if the app is running in the background with background location or Picture-in-picture mode, the app can update live activity when running in the background. If the app is running in the background with audio playing, it will work on simulator, but not on a real device. I submit a feedback: FB11683922 (Can't update Live Activity from app with ActivityKit when app is running in the background with background audio playing.) My code is like: func startLiveActivity() { // Prepare content state and attributes.     do {       self.activity = try Activity.request(attributes: activityAttributes, contentState: initialContentState) // Play audio so app can keep running in the background.       try playAudio()     } catch (let error) {       print("Error requesting Live Activity \(error.localizedDescription).")     }   } private func playAudio() throws {     try AVAudioSession.sharedInstance().setCategory(.playback, options: .mixWithOthers)     try AVAudioSession.sharedInstance().setActive(true)     if self.player == nil {       if let url = Bundle.main.url(forResource: "Forest", withExtension: "m4a") {         player = try AVAudioPlayer(contentsOf: url)         player?.numberOfLoops = -1       }     }     player?.stop()     player?.currentTime = 0     player?.play()   } after the timer stops, the code will execute, but the live activity won't get updated.   func updateActivity(){     Task {       if let activity = self.activity { // Prepare content state         await activity.update(using: contentState)       }     }   }
Posted
by
Post not yet marked as solved
4 Replies
1.6k Views
I have created a live activity that supports both light and dark mode, and are using the isLuminanceReduced environment variable to display the dark mode version on the always on display for the iPhone 14 Pro. However it seems that this variable is not true when I switch to the Sleep Mode focus state. Even though the Lock Screen gets just as dark, it still shows the light mode version of the activity, which results text being very hard to read. Any idea on what to do to display the dark mode version here? Or a way to have text that looks good in both light and dark screens?
Posted
by
Post not yet marked as solved
3 Replies
1.6k Views
Is there any way a live activity could be started from a shortcut? The example live activities (ordering a ride share, viewing sports scores etc) are good fits for shortcuts and live activities but I'm not able to start a live activity from a shortcut using the new app intents framework. Is it possible to start a live activity from an app intent shortcut?
Posted
by
Post not yet marked as solved
3 Replies
1.3k Views
I have app that shows live activity and countdown till a date... VStack { Text("Countdown till You finish your homework")  Text(countdownTime, style: .timer) } After the time up, the live activity countup, the solution is to update the live activity via backgroundTask and this not always working, really apple sometimes fire the backgroundTask after hours. Another solution is to set dismissalPolicy: .after(countdownTime), but once I did that the dynamic island not working and the activity status is ended after right calling... await activity.end(using: state, dismissalPolicy: .after(countdownTime)) Can anyone help please, users feed back is why you we still see the old task on live activity. How come I can not update live activity? and how come if you set dismissalPolicy .after apple changes the activity status to ended and stop showing the dynamic island?
Posted
by
Post not yet marked as solved
2 Replies
2.4k Views
Hello, i am implementing Live Activity and facing a problem setting custom color for widget background. I have a dedicated catalogue of colors for WidgetExtension each having light/dark variant. The problem is, however, that widget's view changes color variants (any/dark) according to system settings, but not system background & text of widget set via .activityBackgroundTint(_:) and activitySystemActionForegroundColor(_:) Both widget background and system button texts remain in light variant no matter what system setting was when starting Live Activity. Later, i was able to kinda force LA background color by checking color scheme in my widget view (yellow and brown for test purposes) .activityBackgroundTint(colorScheme == .light ? Color.surface. : Color.brown) this would force Live Activity background to have expected color from start. BUT when i later change appearance in system settings Live Activity behaves weirdly, as if it was caching previous color I provided. I installed 16.2 beta in hope that it was fixed, but noticed this behaviour 👇 system in light mode: LA start, LA background is light set system to dark: LA background light set system to light: LA background dark ❗️ set system to dark: do not pull notification center, do not look at LA, instead immediately 👇 set system to light: LA background light Is there any way around this? 🙏
Posted
by
Post not yet marked as solved
1 Replies
1.5k Views
I used ProgressView to display a countdown progress bar in a Live Activity. However, I found that since iOS 16.2, ProgressView(timerInterval:countsDown:) does not update properly in the following situations. on Dynamic Island (either Expanded or CompactLeading/Trailing) on the Locked Screen, after the display is turned off (isLuminanceReduced == true) In these situations, the ProgressView for the countdown is always displayed at 100% and does not automatically update with the time. The problem only occurs in iOS 16.2. And it's confusing for users. Will it be fixed please?
Posted
by
Post not yet marked as solved
4 Replies
1.6k Views
I'm implementing a Timer in my app and I want the countdown to show up as a Live Activity. It works, but I get a very weird expanding effect on the Text view. The screenshots below show the issue, I can't tell if it's a bug or if I'm doing something wrong. My goal is to shrink the live activity black area so that it's a smaller, more reasonable size. There's no reason for it to be as large as it is on the trailing side. The Live Activity code (very basic):   } dynamicIsland: { context in        } compactTrailing: { // Important bit is here            Text(Date(), style: .timer)        }    } Which renders like this, with a lot of space after the timer: Adding a background color shows the view is expanding: Text(Date(), style: .timer)     .background(.red) And if I replace the timer with a standard text view, then no issue: Text("Hello")        .background(.red) Getting out of live activities and showing a standard timer view, there is no expansion issue: struct TestView: View {     var body: some View {         Text(Date(), style: .timer)             .background(.red)     } } So... I'm stumped. Any advice is appreciated.
Post not yet marked as solved
1 Replies
704 Views
Hi, We have integrated LA in our app. We have noticed that sometimes LA won't update although APNs is giving 200. To debug this we have enabled LA along side push notifications. Noticed getting push notifications on time but LA is not updating. Not sure how to debug this? Is there anyone who has scaled LA successfully? Thanks
Posted
by
Post not yet marked as solved
1 Replies
1.1k Views
I'm trying to get push tokens for Live Activities but I am getting the same token twice, Why is that? Is there any other way to get the token just once, so I can hit the API to save the token. Here's the code: Task { for await data in runningActivity.pushTokenUpdates { let myToken = data.hexString self.count += 1 print("Count \(self.count)\n" + myToken) } Output: Count 1 80dc21086f81.........646d7084805dc Count 2 80dc21086f81.........646d7084805dc I can't seem to understand why this is happening, and some times it takes significantly longer to get the tokens. Am I doing anything wrong? Please do share your thoughts. Thank you!
Posted
by
Post marked as solved
2 Replies
857 Views
I have a state in my app that is connected to a Live Activity. When the state is true, the Live Activity is active, and when it is false, the Live Activity is ended. I have noticed, though, that if a user starts the Live Activity (by changing the state to true), then force quits the app, then reopens the app and changes the state to false, the Live Activity is not ended / removed from the lock screen. Is there any way to fix this? Since there is no problem ending the Live Activity if the user doesn't force quit the app, it seems as though the Live Activity may be somehow connected to the specific instance of the app. Is there a way to not have the Live Activity connected to the only active instance of the app, but be able to have it ended by any future instance of the app?
Posted
by
Post not yet marked as solved
0 Replies
392 Views
We guide our users to perform specific actions within our service using a timer, similar to interval training. Even when the user enters the background, they should receive a TTS notification and the live activity screen should be updated upon timer completion. Additionally, the user should be able to transition to the next timer at a specific time, even if they don't perform an action (which also requires TTS and live activity updates). Currently, the only thing we can control is scheduling a notification in advance. To enable background TTS notifications and control of live activity, we are considering using background notifications. However, they are irregular and more unstable in battery optimization situations, so we're wondering if there's a way to implement the desired functionality on iOS.
Posted
by
Post not yet marked as solved
0 Replies
441 Views
I am passing a group of apps that the user did not select to the ManagedSettingsStore. I write it like this I then block the user from using this group of apps. ManagedSettingsStore().shield.applicationCategories = ShieldSettings.ActivityCategoryPolicy.all(except:familyActivitySelection.applicationTokens) This problem occurs when you select three or more categories in the FamilyActivityPicker. For example, if you select only the Education category, only the apps in the Education category will be available, but if you add the Productivity/Lifestyle category to the selected categories, all apps in the iPhone will be available. This problem occurs whether the number of categories to select is four or five. Perhaps IOS is not generating the exact set of apps when it generates the set.
Posted
by
Post not yet marked as solved
0 Replies
411 Views
Hey there, I'm using live activities in my iOS app. All setups are done and the live activities feature is working fine. But I'm facing a problem with tracking the live activities. When an update is received on the device by token-based push, How can we track it? When a user tap on an activity at the lock screen it launches the App, So can we track the user's click? I'm stuck in the middle of it. Please help me out. Thanks.
Posted
by
Post not yet marked as solved
0 Replies
359 Views
I am already in put the Live Activity to my project, and when I run the project, the live activity can create and I can get the activity id, but it not displaying on the Lock Screen,
Posted
by
Post not yet marked as solved
0 Replies
558 Views
Hello, I'm working on a tracking app for professionals. I want to integrate a Live Activity that automatically launches in the background when the user begins to drive, providing all the necessary inputs for the driver. However, based on my understanding of the documentation, it seems that launching the Live Activity only from the foreground is possible. Are there no other alternatives available?
Posted
by
Post not yet marked as solved
1 Replies
1.2k Views
I want my live activity to show "in 3 min" text, and for it to be updated automatically every minute. I saw I could do: Text(date, style: .relative) but sadly it include seconds too: 3 min, 2 sec. Is there a way for me to remove the seconds? There are many examples for this use case in the "Design dynamic Live Activities" session from WWDC23, especially at 11:35. How are they implementing that?
Posted
by