While working with the Emoji Rangers Sample Code, I noticed that .redacted(reason:) seems to ignore the minimumScaleFactor() modifier - I have reproduced this behaviour with Xcode 16 and Xcode 16.1 beta 2 on iOS and on the Mac:
struct ContentView: View {
@State private var isRedacted: Bool = false
var body: some View {
VStack {
Image(systemName: "globe")
.imageScale(.large)
.foregroundStyle(.tint)
Text("Hello, world!")
.font(.largeTitle)
Toggle("Redacted", isOn: $isRedacted)
}
.padding()
.minimumScaleFactor(0.1)
.redacted(reason: isRedacted ? .placeholder : .invalidated)
}
}
As long as the minimumScaleFactor does not kick in, redacted seems to work as expected:
But then it does not:
I tried changing the order of both modifiers with no effect. Wonder if this is expected and there is a way to make it work so it preserves the scaled down layout or a bug?
Filed just in case: FB15270541 (.redacted(reason:) modifier ignores .minimumScaleFactor)
WidgetKit
RSS for tagShow relevant, glanceable content from your app on iOS and iPadOS Home Screen and Lock Screen, macOS Desktop, Apple Watch Smart Stack and Complications, and in StandBy mode on iPhone.
Posts under WidgetKit tag
200 Posts
Sort by:
Post
Replies
Boosts
Views
Activity
XCode Version 16.0 (16A242d)
iPhone 12 - iOS 18 (22A3354)
Macbook Air M1 - Sonoma 14.6.1
I am currently working on building Control Buttons for our app and I have consistently run into the same issue:
Unknown NSError The operation couldn’t be completed. (LNActionExecutorErrorDomain error 2018.)
This error can be found in the following posts:
Apple Developer Forums - Post 1
Apple Developer Forums - Post 2
Apple Developer Forums - Post 3
StackOverflow - Post 4
Github - Post 5
I've tried every single solution recommended within these posts, however nothing has worked successfully so far.
Additionally, I've tried the using .widgetUrl() on the Label() within the ControlWidgetButton like so:
ControlWidgetButton(action: JournalControlIntent()) {
Label("Open App", systemImage: "pencil.line")
.widgetURL(URL(string: "app://control/page"))
}
But this did not work either.
Using the recommended approach to open the app as seen here:
https://developer.apple.com/documentation/widgetkit/creating-controls-to-perform-actions-across-the-system#Open-your-app-with-a-control
simply won't work since we have a Flutter app with deep linking setup. Meaning the only option is launching either a deep link or universal link. Our URL scheme is setup correctly since it's currently working for our iOS Widgets & Shortcuts(which use widgetURL & openURL).
In Post 3, the accepted answer mentions that the control file must have the Target Membership with the App and Widget Targets to work. When I try using this solution the build fails without any errors(until you run it in VSCode where there are many errors about Derived Data - Deleting the derived data doesn't fix this error)
I'm wondering if I have added the Control Widget to the incorrect folder within my XCode project? Since if you use the approach of creating a Control through XCode(File > New > Target > Widget Extension > "Include Control" > Next) it creates a top level directory in the project similar to a Stickers or Watch extension.
My Control Widgets currently reside in the [App] Widgets > Control Buttons > Control Button.swift. It's then added to my main widget definition(App Widget > App_Widget.swift):
@main
struct App_Widget: WidgetBundle {
var body: some Widget {
App_Widget() // works
App_Widget_One() // works
if #available(iOSApplicationExtension 18.0, *) {
ControlButtonOne() // does not open app
ControlButtonTwo() // does not open app
}
}
}
Thank you for your help and time!
When i use Xcode16 Beta4, I finish some code
for example
@available(iOS 18.0, *)
struct Test001ControlWidget: ControlWidget {
let kind: String = "Test001ControlWidgetKind"
var body: some ControlWidgetConfiguration {
StaticControlConfiguration(kind: kind, content: {
ControlWidgetButton(action: Test001ControlAppIntent(), label: {
HStack {
Image("controlcenter_point")
Text("Test001")
}
})
})
.displayName("Test001")
}
}
@available(iOS 18.0, *)
struct Test001ControlAppIntent: AppIntent {
static let title: LocalizedStringResource = "Open Demo Some Page"
static var isDiscoverable: Bool = false
static var openAppWhenRun: Bool = true
func perform() async throws -> some IntentResult & OpensIntent {
let defaultIntent = OpenURLIntent()
guard let url = URL(string: Test001JumpType.sohuWatchPoint.jumpLink()) else { return .result(opensIntent: defaultIntent) }
return .result(opensIntent: OpenURLIntent(url))
}
}
The icon can be displayed normally and icon type is png.
And deep link also jump normally.(Note: The control widget file target membership are main app and widgetExtension)
But iOS18 RC code is no working and icon show "?"
How do I deal with these issues?
I hope to hear from you soon.
Tks a lot...
When I build my app on Xcode 16 and run it in an iOS 18 simulator The data downloaded in the app will not get to the widget. Same behaviour happens when running on a physical device. If I run the app in a iOS 17.5 simulator the widget gets and displays the data correctly.
is there a setting that I need to change that I’ve missed?
The app works perfectly on iOS 18 with a build built in Xcode 15.4
When the text is set to non-accentable, it always appears white. The background is accentable, but when the user changes the tint color to white, the text becomes invisible.
How can I make it work like in the Shortcuts widget, where the text color automatically changes based on the tint of the background, ensuring the text is always visible?
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.
Some users have reported that the app's widgets have disappeared after we updated to the latest Xcode for iOS 18 development. They are unable to find our app in the widget search, which prevents them from re-adding the widget. We were unable to reproduce this issue on our own devices during testing. Could this be a system bug? Have others encountered a similar issue?
I suppose this is a bug in compiler.
Xcode 16.0 (16A242d) - AppStore release version
When building a project from Xcode 15 in Xcode 16, an error occurs:
appintentsmetadataprocessor[12633:13677489] error: At least one halting error produced during export. No AppIntents metadata have been exported and this target is not usable with AppIntents until errors are resolved.
AppShortcut phrases may have at most one parameter, but found phrase, "Set Dark Mode ${darkMode} for Widget ${widget}" with more than one parameter: darkMode, widget
Apparently this is an Xcode bug because I have a production app with this AppShortcut and it works fine in Apple Shortcuts.
Everything is made according to the official WWDC video about AppShortcuts
https://developer.apple.com/videos/play/wwdc2022/10170
My custom control widget is show up and I can set it to Lock Screen, but it doesn't launch my app when I clicked it. any problem?
in A.swift file, code like below:
@available(iOS 18.0, *)
struct LockScreenAppLaunchWidget: ControlWidget {
var body: some ControlWidgetConfiguration {
StaticControlConfiguration(kind: "abc") {
ControlWidgetButton(action: LaunchAppIntent()) { // <-- HERE
Label("Something", systemImage: "arrow.up")
}
}
.displayName("Open app")
}
}
@available(iOS 18, *)
struct LaunchAppIntent: AppIntent {
static var title: LocalizedStringResource = "ABC"
static var description: IntentDescription? = "abcd"
static var openAppWhenRun: Bool = true
@MainActor
func perform() async throws -> some IntentResult & OpensIntent {
return .result()
}
}
I'm trying to design a homescreen widget but I am unable to properly control the padding and sizing of various components. In the four attached screenshots you can see the huge variation in padding around the outside, the change in text colour and the spacing between the text. I've boiled it down as simple as possible and attached the view as a sample file.
What I'd like to achieve is a consistent look between iPads and iPhones and ideally in the simulator too. Is there a simple way to set the padding so that all places use the same, and then scale the text so that I know that if the text fits in the simulator the same text will fit on all devices?
Device iPad 8 - 17.7
iPhone 13 Pro Max - 17.7
Xcode Canvas - iPad 13"
Simulator - iPad Pro
sampleview.txt
13"
It seems that after adding a lock screen widget in iOS 18, changing the widget settings doesn't work properly. The first setting change is applied, but after that, adjusting the settings has no effect. This issue appears to be present in other apps like Gmail as well, which suggests it might be an iOS 18 bug. Is there a solution to this problem?
Am I the only one who’s struggling with the widgets (of any size) that you make just only to have the widget be white or images not register. I have tried deleting and remaking the widget, making new widgets and restarting my phone and waiting nothings happening.
Xcode 16, iOS 18 official release. On both my phone and simulator, when I build the release build of my app, when I go to control center and select "Add a Control", springboard crashes (see attached crash log).
Somehow this does not happen in debug config, with debug config (which does have a different bundle ID but everything else is the same) I'm able to add the control widget just fine.
The widget code is taken directly from the Apple docs:
struct WidgetTestWidgetControl: ControlWidget {
static let kind: String = "com.myapp.WidgetTestWidget"
var body: some ControlWidgetConfiguration {
AppIntentControlConfiguration(
kind: Self.kind,
provider: Provider()
) { value in
ControlWidgetToggle(
"Start Timer",
isOn: value.isRunning,
action: StartTimerIntent(value.name)
) { isRunning in
Label(isRunning ? "On" : "Off", systemImage: "timer")
}
}
.displayName("Timer")
.description("A an example control that runs a timer.")
}
}
extension WidgetTestWidgetControl {
struct Value {
var isRunning: Bool
var name: String
}
struct Provider: AppIntentControlValueProvider {
func previewValue(configuration: TimerConfiguration) -> Value {
WidgetTestWidgetControl.Value(isRunning: false, name: configuration.timerName)
}
func currentValue(configuration: TimerConfiguration) async throws -> Value {
let isRunning = true // Check if the timer is running
return WidgetTestWidgetControl.Value(isRunning: isRunning, name: configuration.timerName)
}
}
}
struct TimerConfiguration: ControlConfigurationIntent {
static let title: LocalizedStringResource = "Timer Name Configuration"
@Parameter(title: "Timer Name", default: "Timer")
var timerName: String
}
struct StartTimerIntent: SetValueIntent {
static let title: LocalizedStringResource = "Start a timer"
@Parameter(title: "Timer Name")
var name: String
@Parameter(title: "Timer is running")
var value: Bool
init() {}
init(_ name: String) {
self.name = name
}
func perform() async throws -> some IntentResult {
// Start the timer…
return .result()
}
}
However in a fresh project I am able to add this widget code and it works completely fine in both debug and release. How can I fix this?
This is clearly affecting many apps and is the 'fault' of the app, see these threads:
https://www.reddit.com/r/ios/comments/1fiqrd7/ios_18_control_center_keeps_crashing_when_trying/
https://discussions.apple.com/thread/255759997?sortBy=rank
crash-log.txt
I'm trying to use a custom SVG as a SF Symbol for a .accessoryInline complication on Apple Watch but it only appear on WatchOS 11.
I even tried a fresh project and exported one of the symbols from SF Symbols app to eliminate error with custom symbol creation. On WatchOS 11 it shows correctly and colored, on WatchOS 10.5, no symbol at all.
Am I missing some setting or something? Tried different Render As options for the symbol with no luck. For corner complication, it shows it fine (Series 10 is WatchOS 11 here)
What is more weird in kinda shows that it's loading in comlication preview:
Overall can't use any image for inline complication unless I do it like this:
Image(uiImage: UIImage(named: "ImageName") ?? UIImage())
.resizable()
Which can't be colored also
Hi.
I am making my widgets ready for iOS 18 accented Home Screen widgets.
I am having issues setting the color of text to black.
This is required as I have a white button with black text and black icon.
I have tried manually, without using my Color, to set the text to .black or .white. It will always be white.
When applying the accent, I can use the .widgetAccentedRenderingMode(.fullColor) to turn the icon black, but I cannot do this for the text.
Button(intent: --intent--) {
HStack(alignment: .center) {
Text("Play")
.font(.system(size: 12, weight: .bold))
.foregroundStyle(Color("buttonAccentColor")) // Problem here, this is forced to be white, I want it to be black
Image("resume")
.renderingMode(.template)
.resizable()
.widgetAccentedRenderingMode(.fullColor) // This works
.aspectRatio(contentMode: .fit)
.frame(width: 16, height: 16)
.foregroundStyle(Color("buttonAccentColor"))
}
.padding(8)
.padding(.horizontal, 8)
}
.buttonStyle(.plain)
.background(Color("neutral100"))
.clipShape(Capsule())
Hi
Is it possible to render webview in Widget?
Basically i want to show some content of website in Widget on homescreen using webview.
I tried to use WKWebview in WidgetView, but it's not rendering .
Thanks with regards
iOSProfessionals
This is a follow up to this post about building a Control Center widget to open the app directly to a particular feature. I have it working in a sample app, but when I do the same thing in my full app I get this error:
[[com.olivetree.BR-Free::com.olivetree.BR-Free.VerseWidget:com.olivetree.BR-Free.ContinueReadingPlanControl:-]] Control action: failed with error: Error Domain=ChronoKit.InteractiveWidgetActionRunner.Errors Code=1 "(null)"
Google has nothing for any of that. Can anyone shed light on what it means?
This is my control and its action:
@available(iOS 18.0, *)
struct ContinueReadingPlanControl : ControlWidget {
var body: some ControlWidgetConfiguration {
StaticControlConfiguration(kind: "com.olivetree.BR-Free.ContinueReadingPlanControl") {
ControlWidgetButton(action: ContinueReadingPlanIntent()) {
Image(systemName: "book")
}
}
.displayName("Continue Reading Plan")
}
}
@available(iOS 18.0, *)
struct ContinueReadingPlanIntent : ControlConfigurationIntent {
static let title: LocalizedStringResource = "Continue Reading Plan"
static let description = IntentDescription(stringLiteral: "Continue the last-used reading plan")
static let isDiscoverable = false
static let opensAppWhenRun: Bool = true
@MainActor
func perform() async throws -> some IntentResult & OpensIntent {
let strUrl = "olivetree://startplanday"
UserDefaults.standard.setValue(strUrl, forKey: "StartupUrl")
return .result(opensIntent: OpenURLIntent(URL(string: strUrl)!))
}
}
Note also that I'm pulling this from Console.app, streaming the logs from my device. I don't know of a way to debug a Control Center widget in Xcode, though this thread implies that it's possible.
Using desaturated mode on an image in a widget will break any links or buttons that use the image as their 'label'.
Using the following will just open the app as if there was no link at all - therefore just using the fallback userActivity handler, or any .widgetURL() urls provided.
Link(destination: URL(string: "bug://never-works")!) {
Image("puppy")
.widgetAccentedRenderingMode(.desaturated)
}
The same goes for buttons:
Button(intent: MyDemoIntent()) {
Image("puppy")
.widgetAccentedRenderingMode(.desaturated)
}
I've tried hacky solutions like putting the link behind the image using a ZStack, and disabling hit testing on the image, but they don't work. Anything else to try?
Logged as Feedback #15152620.
When using a SwiftUI Text view with a relative date, with .minimumScaleFactor(), in a widget, the Text will always be shown at the minimum scale rather than the largest size possible. This started happening in iOS17, and is still the case in iOS18.
Therefore, if for example, you wanted to have a Text, showing a relative date in a countdown, with a "minimumScaleFactor" of 0.5, it will always show at 0.5 scale, no matter how much space there is available.
Text(.now, style: .relative)
.font(.system(size: 80, weight: .bold, design: .rounded))
.minimumScaleFactor(0.2)
^^ will always show at 0.2 scale (in a widget) even if there's space for much more.
This is only the case in widgets, not in the main app. Similarly, if you try to use "ViewThatFits" instead of "minimumScaleFactor", it will choose the smallest view, even if larger ones would fit.
Screenshot demonstrates the issue - all the countdown text views should be similarly large. This is not an issue with lack of vertical spacing causing the more flexible views to shrink - it behaves the same even if there's loads of vertical space too.
Maybe related, but trying to use ".fixedSize()" with a relative date Text view in a widget results in a completely blank widget.
Seems like a system bug rather than anything wrong in my code - I've logged it as Feedback (#15151577) with a demo project. Has anybody else come up against these issues - any solutions?
I have programmed a ControlWidgetToggle which controls a recording state in our main app, that can be on (recording) or off (not recording). The recording can also be controlled from inside the main app, and there we call ControlCenter.shared.reloadControls(ofKind: "") to update the ControlWidgetToggle state when the recording state changes. Now this all works great, except for the situation in which the user terminates the app (for example using the app switcher screen). Then of course the recording will stop. I however have no idea how to update the state of the ControlWidgetToggle in this case, it will stay in the recording state since it does not know that the recording has been stopped.
The applicationWillTerminate delegate method of the AppDelegate will not be called in such a case. Does someone has an idea how to update the state of the ControlWidgetToggle once the parent app has been terminated?