Hi there,
I'm adding a new widget using the new WidgetConfigurationIntent which takes a number of parameters, including one which conforms to AppEntity. It is defined as an optional.
When the user is configuring the widget, after one of the suggested entities is chosen, there is no way to return to a state where this value is nil. Is this possible? I'd like the user to be able to select "None" for this parameter. For now, I'm using a bool to determine whether the AppEntity parameter is used.
Thanks!
Widgets & Live Activities
RSS for tagDiscuss how to manage and implement Widgets & Live Activities.
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
I have developed a Widget Extension with editable dynamic options.
`struct ModelQuery: EntityStringQuery {
public var allModels:[ModelEntity] {
// from App Groups UserDefaults
let models = SharedDataManager.getModelList()
// 检查原始数据是否为空,避免转换后的数据异常
guard !models.isEmpty else {
return []
}
let entites = models.map{ModelEntity(from: $0)}
return entites
}
func entities(for identifiers: [ModelEntity.ID]) async throws -> [ModelEntity] {
let models = allModels
if models.isEmpty {
return []
}
// 尝试匹配ID
let matchedEntities = identifiers.compactMap { id in
models.first { $0.id == id }
}
// 如果没有匹配到任何实体,返回默认的第一个站点
if matchedEntities.isEmpty && !models.isEmpty {
return [models[0]]
}
return matchedEntities
}
func entities(matching string: String) async throws -> [ModelEntity] {
let stations = allModels
if stations.isEmpty {
return []
}
if string.isEmpty {
return stations
}
let lowercasedString = string.lowercased()
let filteredStations = stations.filter { station in
station.name.lowercased().contains(lowercasedString)
}
if filteredStations.isEmpty {
return []
}
return filteredStations
}
func suggestedEntities() async throws -> [ModelEntity] {
return allModels
}
}`
Below is how it looks when functioning properly
However, when I tested it on iOS 26, occasional "Failed to Load" errors or unknown errors occurred. The same issues did not appear on iOS 17 or iOS 18.
import AppIntents
struct AddTodoIntent: AppIntent {
static var title: LocalizedStringResource = "Add Todo"
static var openAppWhenRun: Bool = true
func perform() async throws -> some IntentResult & ProvidesDialog {
.result(dialog: "New todo added successfully.")
}
}
struct ViewTodosIntent:AppIntent {
static var title: LocalizedStringResource = "View Todos"
func perform() async throws -> some IntentResult & ProvidesDialog {
.result(dialog: "Here are your todos...")
}
}
struct TodoAppShortcuts: AppShortcutsProvider {
static var appShortcuts: [AppShortcut] {
AppShortcut(
intent: AddTodoIntent(),
phrases: ["\(.applicationName) Add a new todo"],
shortTitle: "New Todo",
systemImageName: "plus.circle"
)
AppShortcut(
intent: ViewTodosIntent(),
phrases: ["\(.applicationName) Show my todoso"],
shortTitle: "Show todos",
systemImageName: "plus.app"
)
}
}
when we used, it wrong
How did i can do it success?
When I set Alarm with fixed schedule(Alarm.Schedule.fixed(date))
LiveActivityIntent just work inconsistently
it sometimes call perfrom but cannot call other's
such as NotificationCenter.default.post
it just work fine with relativeSchedule but not for fixed schedule
i want to know why it happen
tested code is under below
struct StopIntent: LiveActivityIntent {
static var supportedModes: IntentModes = [.foreground(.immediate)]
func perform() throws -> some IntentResult {
guard let id = UUID(uuidString: alarmID) else {
NotificationCenter.default.post(name: .Alarm.stoped, object: alarmDataString)
throw TestAlarmManager._Error.badAlarmID
}
Task { @MainActor in
try TestAlarmManager.shared.stopAlarm(id)
NotificationCenter.default.post(name: .Alarm.stoped, object: alarmDataString)
}
return .result()
}
static var title: LocalizedStringResource = "Stop"
static var description = IntentDescription("Stop an alert")
@Parameter(title: "alarmID")
var alarmID: String
@Parameter(title: "alarmDataString")
var alarmDataString: String
init(alarmID: UUID, alarmDataString: String) {
self.alarmID = alarmID.uuidString
self.alarmDataString = alarmDataString
}
init() {
self.alarmID = ""
self.alarmDataString = ""
}
}
My widget has a background color set, but after the system sets custom transparency, my widget displays a blank space. I would like to solve this problem by obtaining the system's custom transparency settings and then setting the background color transparency, or do you have a better way to solve this problem
Topic:
App & System Services
SubTopic:
Widgets & Live Activities
We currently have the need to develop Smart Island. We need to identify whether the current mobile phone supports Smart Island. At present, the solution we can think of is to maintain a model list if the current phone is in the white list, it supports Smart Island. But we think this method is not good enough. Is there a better solution to support identification? In addition, will the later models support smart Island?
Topic:
App & System Services
SubTopic:
Widgets & Live Activities
Create a static widget kit based widget for watchKit. Use swiftUI and an image.
IE on 42mm you can import a 141x141 image at 2x. Import a 141x141 image in the widget and load it in swiftUI.
In watchOS 11.x simulator the image will allow up to the size for X Large circles, and on os26, it will not load and complain the image is too large and report the area for the smaller circle, IE 89x89 @ 2x for 41mm
Also submitted a "feedback" ticket FB20506200
This is a big issue b/c the size difference for X large circles v the smaller circles is really large.
To get existing images to load I am having to resize them down 75-80% on OS26 in the X Large complication.
Hi,
We need Wallet Boarding Pass Live Activity style countdown inside Live Activity.
Requirements
Show only hours+minutes (no seconds ever).
Format examples (Turkish locale concept):
T > 60 min: "1sa 14d" (HHh MMm)
T < 60 min: "58d"
At exactly zero show a single final zero value (e.g. "0d").
Do NOT show seconds or any upward (elapsed) counting after zero.
When remaining time < 0 immediately replace display with status text (e.g. "ON TIME").
Never display negative or increasing elapsed time.
Discovered Current Timer Methods (Observed)
Method 1 (Text(date, style: .relative)):
After reaching target it continues counting UP (should stop).
Seconds appear automatically once remaining < 1 hour.
Method 2 (Text(date, style: .timer)):
After reaching target it continues counting UP (should stop).
Seconds are always visible from start.
Method 3 (Text(timerInterval: Date.now ... targetDate, countsDown: true)):
Stops at target (no upward counting) but seconds are always visible; cannot limit to single zero then freeze before status swap.
Requested Enhancement
Provide a behavior where the countdown displays hours+minutes, renders a single zero-minute value at the boundary (no seconds), then transitions to supplied status text.
Request
Public API or configuration to:
Select displayed units (hours, minutes only).
Stop automatic updating after rendering the zero frame (prevent upward counting).
Prevent post-target elapsed counting (no positive re-growth).
Allow immediate swap-to-text after zero (remaining < 0) while permitting a single zero display at the boundary.
Why
Align UX with Wallet; need predictable single zero then status, no seconds, no elapsed confusion.
Thank you.
Watching WWDC video: https://developer.apple.com/videos/play/wwdc2023/10185/?time=481
It says:
So when encoding your content state, do not set any custom encoding strategies. Otherwise, your JSON will be mismatched, and the system will fail to update your Live Activity
So I'm just wondering if using JSONDecoder is allowed for decoding apps payloads for the UI of a Live Activity? Or is there a performance hit for this?
I have an app that has a Core Data store for dates with descriptions that I'd like to present in a widget with countdown calculations. In the app I have a button that just equates an active calculation to the currently selected item in the database (using an EnvironmentObject). I gather I can't use this mechanism inside a widget, right?
The user could put tons of items into the database - so I'm sure I don't want to have an editable widget allowing them to pick. I suppose I could create an intent and allow an independent entering from the app - but that seems rather user hostile since they've already entered it for the app - and I'm still trying to support iOS15 which doesn't support that.
I did create an App Group and have the Core Data store available from within the widget, but I don't see how to allow the user to choose which date is active. I also want multiple widgets to be able to point to different dates. Any help would be appreciated. Thanks!
Hi,
My iOS app's home screen widget content was implemented to base on the preferred language of my main app (e.g. my app has the following preferred language options with this order English, Japanese, Traditional Chinese, Korean, Simplify Chinese).
Say the main app is currently using English as their preferred language, I can change the preferred language in the iOS Settings -> Apps -> My App -> Preferred Language.
My widget's content will respect to the preferred language option that I selected with only exception if I switch back to English language and my Widget's content won't get updated. The Main app content is always update with respect to the selected preferred language.
My app and widget is working without any issue in iOS 18.
Other things that I had discovered during my testing under iOS 26, the "first" language appeared in my preferred language always being the issue (e.g. if the first language is Japanese , once I change to other languages and than switch back to Japanese, my widget content won't respect to this but the main app content are ok).
Any one has a similar issues regarding the preferred language?
Topic:
App & System Services
SubTopic:
Widgets & Live Activities
Tags:
Internationalization
Localization
Im having trouble enabling Live Activities in a new app. The option is not available in Xcode or in the developer portal. Is there something I have to do to activate this option?
Topic:
App & System Services
SubTopic:
Widgets & Live Activities
I'm currently testing this on a physical device (12 Pro Max, iOS 26). Through shortcuts, I know for a fact that I am able to successfully trigger the perform code to do what's needed. In addition, if I just tell siri the phrase without my unit parameter, and it asks me which unit, I am able to, once again, successfully call my perform. The problem is any of my phrases that I include my unit, it either just opens my application, or says "I can't understand"
Here is my sample code:
My Entity:
import Foundation
import AppIntents
struct Unit: Codable, Identifiable {
let nickname: String
let ipAddress: String
let id: String
}
struct UnitEntity: AppEntity {
static var typeDisplayRepresentation: TypeDisplayRepresentation {
TypeDisplayRepresentation(
name: LocalizedStringResource("Unit", table: "AppIntents")
)
}
static let defaultQuery = UnitEntityQuery()
// Unique Identifer
var id: Unit.ID
// @Property allows this data to be available to Shortcuts, Siri, Etc.
@Property var name: String
// By not including @Property, this data is NOT used for queries.
var ipAddress: String
var displayRepresentation: DisplayRepresentation {
DisplayRepresentation(
title: "\(name)"
)
}
init(Unit: Unit) {
self.id = Unit.id
self.ipAddress = Unit.ipAddress
self.name = Unit.nickname
}
}
My Query:
struct UnitEntityQuery: EntityQuery {
func entities(for identifiers: [UnitEntity.ID]) async throws -> [UnitEntity] {
print("[UnitEntityQuery] Query for IDs \(identifiers)")
return UnitManager.shared.getUnitUnits()
.map { UnitEntity(Unit: $0) }
}
func suggestedEntities() async throws -> [UnitEntity] {
print("[UnitEntityQuery] Request for suggested entities.")
return UnitManager.shared.getUnitUnits()
.map { UnitEntity(Unit: $0) }
}
}
UnitsManager:
class UnitManager {
static let shared = UnitManager()
private init() {}
var allUnits: [UnitEntity] {
getUnitUnits().map { UnitEntity(Unit: $0) }
}
func getUnitUnits() -> [Unit] {
guard let jsonString = UserDefaults.standard.string(forKey: "UnitUnits"),
let data = jsonString.data(using: .utf8) else {
return []
}
do {
return try JSONDecoder().decode([Unit].self, from: data)
} catch {
print("Error decoding units: \(error)")
return []
}
}
func contactUnit(unit: UnitEntity) async -> Bool {
// Do things here...
}
}
My AppIntent:
import AppIntents
struct TurnOnUnit: AppIntent {
static let title: LocalizedStringResource = "Turn on Unit"
static let description = IntentDescription("Turn on an Unit")
static var parameterSummary: some ParameterSummary {
Summary("Turn on \(\.$UnitUnit)")
}
@Parameter(title: "Unit Unit", description: "The Unit Unit to turn on")
var UnitUnit: UnitEntity
func perform() async throws -> some IntentResult & ProvidesDialog {
//... My code here
}
}
And my ShortcutProvider:
import Foundation
import AppIntents
struct UnitShortcuts: AppShortcutsProvider {
static var appShortcuts: [AppShortcut] {
AppShortcut(
intent: TurnOnUnit(),
phrases: [
"Start an Unit with \(.applicationName)",
"Using \(.applicationName), turn on my \(\.$UnitUnit)",
"Turn on my \(\.$UnitUnit) with \(.applicationName)",
"Start my \(\.$UnitUnit) with \(.applicationName)",
"Start \(\.$UnitUnit) with \(.applicationName)",
"Start \(\.$UnitUnit) in \(.applicationName)",
"Start \(\.$UnitUnit) using \(.applicationName)",
"Trigger \(\.$UnitUnit) using \(.applicationName)",
"Activate \(\.$UnitUnit) using \(.applicationName)",
"Volcano \(\.$UnitUnit) using \(.applicationName)",
],
shortTitle: "Turn on unit",
systemImageName: "bolt.fill"
)
}
}
Topic:
App & System Services
SubTopic:
Widgets & Live Activities
Tags:
Siri and Voice
Intents
App Intents
I'm having problems with my released app with iOS & WatchOS 26 support.
I've added AppIntentConfiguration support in the WatchOS app such that users can configure the complication. My complications also support multiple families and so I have slightly different configuration options available if its in the .accessoryRectangular slot or the .accessoryCircular one.
This works fine on Apple Watch when editing the Watch face. Here you can then select the configuration options fine and they are correct for the different variants.
However on iOS when configuring in the Apple Watch app on iPhone, the different complication size is ignored and the same configuration options are offered meaning they are wrong for one of them.
I created a sample project, here is the app intent code:
struct TestWidgetConfigurationIntent: AppIntent, WidgetConfigurationIntent {
static var title: LocalizedStringResource = "New Widgets with Configuration"
static var description = IntentDescription("Lots of stuff.")
static var isDiscoverable: Bool { return false}
init() {}
func perform() async throws -> some IntentResult {
return .result()
}
@Parameter(title: "Enable More Detail", default: true)
var moreDetail: Bool
@Parameter(title: "Enable Other Parameter", default: true)
var otherParameter: Bool
static var parameterSummary: some ParameterSummary {
When(widgetFamily: .equalTo, .accessoryRectangular) {
Summary("Test Info") {
\.$moreDetail
\.$otherParameter
}
} otherwise : {
Summary("Test Info") {
\.$moreDetail
}
}
}
}
In WatchOS you get the correct configuration options:
In iOS you do not, you get the same configuration option regardless of which family size you select:
This could be a bug so I've filed feedback FB20328319. Otherwise if anyone has insights, it would be very appreciated. This is all tested on the current iOS 26.0 and WatchOS 26.0 versions. Thanks!
Topic:
App & System Services
SubTopic:
Widgets & Live Activities
Tags:
WatchKit
watchOS
WidgetKit
App Intents
Appears during code compilation Provisioning profile "iOS Team Provisioning Profile: ..*" doesn't include the com.apple.developer.ActivityKit entitlement, Has anyone encountered or resolved a similar issue where the ActiveKit feature was not found in the developer's identifier, despite not being activated in the developer's system?
Topic:
App & System Services
SubTopic:
Widgets & Live Activities
I noticed that with iOS 18, when adding a widget to the Control Center, there is now some "grouping system". I'm interested in the Capture group, which contains native widgets from Apple as well as third party apps like Instagram and Blackmagic cam, widgets in this group open the camera. My widget also opens the camera in my app, how can I add it to this group?
Topic:
App & System Services
SubTopic:
Widgets & Live Activities
Tags:
SwiftUI
WidgetKit
App Intents
Appears during code compilation Provisioning profile "iOS Team Provisioning Profile: ..*" doesn't include the com.apple.developer.ActivityKit entitlement, Has anyone encountered or resolved a similar issue where the ActiveKit feature was not found in the developer's identifier, despite not being activated in the developer's system?
Topic:
App & System Services
SubTopic:
Widgets & Live Activities
Appears during code compilation Provisioning profile "iOS Team Provisioning Profile: ..*" doesn't include the com.apple.developer.ActivityKit entitlement, Has anyone encountered or resolved a similar issue where the ActiveKit feature was not found in the developer's identifier, despite not being activated in the developer's system?
Topic:
App & System Services
SubTopic:
Widgets & Live Activities
There seems to be a long running issue with WidgetKit where some users don't see the widget when trying to add to their Home Screen. (even after opening the app for the first time).
I have been able to reproduce myself intermittently, and typically restarting the phone or re-installing the app fixes the problem. However, some of my users have encountered this and end up requesting refunds because they think the app is broken.
Has anybody else experienced this issue?
Would be great to get this bug resolved as it's frustrating for users.
Documentation seems to say that privacySensitive is supposed to redact on the lockScreen. I've disabled "Allow Access when locked" for "Lock Screen Widgets" just in case. It does not work for me. If I add "redacted(reason:) into the view hierarchy it redacts all the content all the time including on the home screen. I've read articles. I gone through a lot of documentation. None of them seem to give the magic formula for redacting sensitive content on the lock screen.
I'm using iOS 18.7 on a real iPhone 14 Pro Max.