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
1 Replies
431 Views
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
Posted
by singy.
Last updated
.
Post not yet marked as solved
0 Replies
360 Views
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?
Posted
by singy.
Last updated
.
Post not yet marked as solved
4 Replies
1.7k Views
I wanted to show count down timer in live activity. Since we can't use Timer in extensions, I used Text.init(timerInterval:pauseTime:countsDown:showsHours:) to show timer. But I need to show different text when the timer ends. How to achieve this behaviour?
Posted Last updated
.
Post not yet marked as solved
0 Replies
271 Views
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.
Posted Last updated
.
Post not yet marked as solved
0 Replies
308 Views
In my App I use Live Activities that are updated using Push Notifications. This works fine and the Live Activities show the correct data. BUT: The data I get with these Push Notifications contain a geo location (latitude and longitude). And for these I want to display two things: 1.) The address that I want to decode using "CLGeocoder" with function "reverseGeocodeLocation", but this function is async and I can't get the app to start any async function. 2.) I would like to display a small Map with a Pin for this location. I want to use "MKMapSnapshotter" for this. But here the same async problem :( So, is there a way to handle this? Perhaps I just use the wrong point to start the async function. I tried ".task{}" and ."onAppear{}" But both are not working :(
Posted
by Urkman.
Last updated
.
Post not yet marked as solved
1 Replies
758 Views
According to apple On devices that include an Always-On display, the system dims the screen to preserve battery life and renders Live Activities on the Lock Screen as if in Dark Mode. Use SwiftUI’s isLuminanceReduced environment value to detect reduced luminance on devices with an Always-On display and use images that look great for reduced luminance. But it seems to have no effect in live activities when displayed in the lock screen with AOD @Environment(\.isLuminanceReduced) var isLuminanceReduced Image("background1") .resizable() .aspectRatio(contentMode: .fit) .frame(height: 400) .offset(y:-40) .brightness(isLuminanceReduced ? -0.5 : 0)
Posted
by dyyi.
Last updated
.
Post marked as solved
4 Replies
1.3k Views
Hello, I noticed that the layout of compact Dynamic Island on iOS 17 is incorrect. The edge of the circle shape is unable to be aligned with the edge of Dynamic Island. However, the layout in Xcode Preview is just perfect. And this is also the same layout on previous iOS 16: If you try to workaround the issue by adding an offset to the view, it will be cropped by a misaligned circle.
Posted
by Gong.
Last updated
.
Post not yet marked as solved
1 Replies
941 Views
Hi there, This is my first time posting here. I'm working on small projects on Swift and SwiftUI now and then. I'm currently trying to develop an application that gets some bus arrival data using API and displaying them with live activities. The thing is that I'm not quite sure how frequently updates work yet. Still trying to figure out if I can update the live activity everytime the data coming right from the API changes or use push notification updates each minute passing by, but that is another thread that I'm going to focus with more details. Everytime i'm trying to deploy my app on my iphone or a simulator this error keeps popping up and I can't figure out why. Any ideas? Let me know if you need any snippet of my code. SendProcessControlEvent:toPid: encountered an error: Error Domain=com.apple.dt.deviceprocesscontrolservice Code=8 "Failed to show Widget 'com.gregorikouk.MapKitTut.BusWidgetKit' error: Error Domain=FBSOpenApplicationServiceErrorDomain Code=1 "The request to open "com.apple.springboard" failed." UserInfo={NSLocalizedFailureReason=The request was denied by service delegate (SBMainWorkspace)., BSErrorCodeDescription=RequestDenied, NSUnderlyingError=0xb1282dfe0 {Error Domain=SBAvocadoDebuggingControllerErrorDomain Code=1 "Failed to get descriptors for extensionBundleID (com.gregorikouk.MapKitTut.BusWidgetKit)" UserInfo={NSLocalizedDescription=Failed to get descriptors for extensionBundleID (com.gregorikouk.MapKitTut.BusWidgetKit)}}, FBSOpenApplicationRequestID=0xe5da, NSLocalizedDescription=The request to open "com.apple.springboard" failed.}." UserInfo={NSLocalizedDescription=Failed to show Widget 'com.gregorikouk.MapKitTut.BusWidgetKit' error: Error Domain=FBSOpenApplicationServiceErrorDomain Code=1 "The request to open "com.apple.springboard" failed." UserInfo={NSLocalizedFailureReason=The request was denied by service delegate (SBMainWorkspace)., BSErrorCodeDescription=RequestDenied, NSUnderlyingError=0xb1282dfe0 {Error Domain=SBAvocadoDebuggingControllerErrorDomain Code=1 "Failed to get descriptors for extensionBundleID (com.gregorikouk.MapKitTut.BusWidgetKit)" UserInfo={NSLocalizedDescription=Failed to get descriptors for extensionBundleID (com.gregorikouk.MapKitTut.BusWidgetKit)}}, FBSOpenApplicationRequestID=0xe5da, NSLocalizedDescription=The request to open "com.apple.springboard" failed.}., NSUnderlyingError=0xb1281d830 {Error Domain=FBSOpenApplicationServiceErrorDomain Code=1 "The request to open "com.apple.springboard" failed." UserInfo={NSLocalizedFailureReason=The request was denied by service delegate (SBMainWorkspace)., BSErrorCodeDescription=RequestDenied, NSUnderlyingError=0xb1282dfe0 {Error Domain=SBAvocadoDebuggingControllerErrorDomain Code=1 "Failed to get descriptors for extensionBundleID (com.gregorikouk.MapKitTut.BusWidgetKit)" UserInfo={NSLocalizedDescription=Failed to get descriptors for extensionBundleID (com.gregorikouk.MapKitTut.BusWidgetKit)}}, FBSOpenApplicationRequestID=0xe5da, NSLocalizedDescription=The request to open "com.apple.springboard" failed.}}} Domain: DTXMessage Code: 1 User Info: { DVTErrorCreationDateKey = "2023-10-02 21:06:04 +0000"; } -- System Information macOS Version 14.0 (Build 23A344) Xcode 15.0 (22265) (Build 15A240d) Timestamp: 2023-10-03T00:06:04+03:00
Posted Last updated
.
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 Last updated
.
Post not yet marked as solved
1 Replies
536 Views
A have a few App intents that conforms to LiveActivityStartingIntent. If there are no active LA, then any of my intents can start live activity. But if there is at least one active LA then requesting LA returns an error: "The operation couldn’t be completed. Target is not foreground" Is there a limit to only 1 LA or I do something wrong?
Posted
by AFork.
Last updated
.
Post not yet marked as solved
4 Replies
1.7k 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.
Posted Last updated
.
Post not yet marked as solved
0 Replies
390 Views
Hello team, I'm looking for advice, please, about how to track updates to Activity.pushTokenUpdates and Activity.activityStateUpdates if my app isn't running. These two async sequences work great when my app is running, but that information is just as important if, for some reason, my app isn't running. In the WWDC video Update Live Activities with push notifications, the presenter says: when the system requests a new push token for an existing activity, your app will be given foreground runtime to handle it accordingly I was hoping that my app to be launched in the background... but I don't see how that would work unless there's a new call via the AppDelegate. Follow-up question... is there any documentation for the scenarios when a push token might be replaced for a live activity? Thank-you! Matthew
Posted
by mkflint.
Last updated
.
Post not yet marked as solved
0 Replies
774 Views
I just want to know what is maximum height of dynamic island(expanded). When I just go through the documentation, it is showing 160pt. Here is url: https://developer.apple.com/design/human-interface-guidelines/live-activities#Specifications But as I observed, some of applications have more than 160pt height of dynamic island (expanded). If this is possible, how we can increase height of dynamic island. Even if we go through figma library, it is also showing more height https://www.figma.com/file/YVWH9fn64y36***6jYdks5/Dynamic-Island-iPhone-14-(Community)?node-id=0%3A1&mode=dev
Posted Last updated
.
Post not yet marked as solved
0 Replies
401 Views
In session wwdc2023-10194 Design dynamic Live Activities at 04:53, it mentioned that we should use 'content replace transition' for animating in and out graphic elements and text. The video shows some kind of animation combined with blurring and opacity changes. But I can't seem to find code for doing this in SwiftUI or UIKit. Does anyone know the API to achieve this? 🤔 Thank you for your help!
Posted Last updated
.
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 oddis98.
Last updated
.
Post not yet marked as solved
1 Replies
725 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 Last updated
.
Post not yet marked as solved
2 Replies
729 Views
How do you animate in live activities? I've seen apps been able to update around 1 fps. For example with a character looping a dance animation. How is this done? I don't think you can call Activity.update() every second. Also it wouldn't run in the background all the time anyway? Here's an example of Apple's own WWDC video with a bar animating https://imgur.com/a/yywW7a8
Posted
by dyyi.
Last updated
.