Post not yet marked as solved
I need to use location in my widget.
Here's what I did:
Set Widget Wants Location and Privacy - Location When In Use Usage Description in my widget extension
Run the widget
The problem is that every time I run the widget for the very first time, I tap "Allow" when asked to permit access to my location and then it crashes with this:
I'm really confused why this is happening, since I'm not even doing any operation that involves anything from CoreLocation.
The second time I run the widget, works great. I can access current location and do whatever I want.
At first I thought that because of my implementation of CLLocationManagerDelegate I'm getting this, but then I removed everything related to CoreLocation from my codebase except the configurations I'm talking about above.
What am I missing?
Post not yet marked as solved
I am playing with WidgetKit but I am having a hard time understand how it works. Here is my sample code. I started with create a widget extension and add some more print to understand the life cycle:
@main
struct SampleWidget: Widget {
let kind: String = "SampleWidget"
var body: some WidgetConfiguration {
StaticConfiguration(kind: kind, provider: Provider()) { entry in
SampleWidgetEntryView(entry: entry)
.onAppear {
print("widget appear")
}
.onDisappear {
print("widget disappear")
}
}
.configurationDisplayName("My Widget")
.description("This is an example widget.")
.supportedFamilies([.systemMedium])
}
let timer = Timer.scheduledTimer(withTimeInterval: 5.0, repeats: true, block: { timer in
print("timer trigger in widget")
})
}
I would expect when adding the widget, the debug will show as:
widget appear
timer trigger in widget (every 5 seconds)
...
When I remove the widget, the debug would show:
widget disappear
timer trigger in widget should stop firing
So the first time adding the widget on the home screen, i got the debug trigger correctly. When adding the widget on the Notification Center, i would expect it to get trigger again because it's another instance of the widget, but it does not. When I removed the widget on both side, the onDisappear never get trigger and my timer trigger in widget still get print out. How does this continue to work? Should it just stop firing?
In the old Today Extension Widget, when you swipe to view widget it will trigger viewDidLoad. When you close the widget, it will trigger viewWillDisappear. Is it possible for WidgetKit behave the same way?
I understand WidgetKit extension does not run forever but SwiftUI allow us to update UI dynamically. So at what point after widget is added will it stop working? If I add a background task, when should I expect it to stop working?
Post not yet marked as solved
Hello!
I am trying to make my complication update info every second, so I could create a timer in it.
I already found a solution that helps me to create a timer
let components = DateComponents(second: 10)
let futureDate = Calendar.current.date(byAdding: components, to: Date())!
Text(futureDate, style: .timer)
but I want to make a breath timer, so I need to change it to 5 sec timer and then again to 10 sec.
Is there any solution that would allow me to update the info that shows in the new iOS 16 Lock Screen Widget in this way?
Post not yet marked as solved
I tried not calling completion in gettimeline. After about 40s, the system will call gettimeline again, but after 5 times, if completion is still not called, the widget refresh will be disordered. The set Timeline does not take effect, and the active call to WidgetCenter.shared.reloadAllTimelines() does not take effect. So now I didn't find a proper way to auto refresh.
sample code:
struct Provider: IntentTimelineProvider {
static var count = 0
func placeholder(in context: Context) -> SimpleEntry {
return SimpleEntry(date: Date(), name: "")
}
func getSnapshot(for configuration: OpenWidgetConfigIntent, in context: Context, completion: @escaping (SimpleEntry) -> ()) {
let entry = SimpleEntry(date: Date(), name: "")
completion(entry)
}
func getTimeline(for configuration: OpenWidgetConfigIntent, in context: Context, completion: @escaping (Timeline<Entry>) -> ()) {
if Self.count < 4 {
Self.count = Self.count + 1
return
} else {
Self.count = 0
}
doTimeLineCompletion(name: "Sir Isaac Newton", image: nil, completion: completion)
}
func doTimeLineCompletion(name: String, image: UIImage?, completion: @escaping (Timeline<Entry>) -> ()) {
var entries: [SimpleEntry] = []
var entry = SimpleEntry(date: Date(), name: name)
entries.append(entry)
let timeline = Timeline(entries: entries, policy: .after(Date().addingTimeInterval(TimeInterval(300))))
completion(timeline)
}
}
struct SimpleEntry: TimelineEntry {
let date: Date
let name: String
}
Post not yet marked as solved
I'm trying to build a WatchOS 9 corner complication with WidgetKit (using Xcode 14 beta 3).
I'd like my complication to look like the battery one in the bottom right corner. Here's my view:
struct HydrationProgressCorner: View {
var entry: Provider.Entry
var body: some View {
Text("\((100 * entry.progress / entry.target).rounded(.towardZero).formatted())%")
.widgetLabel {
ProgressView(value: entry.progress, total: entry.target)
.tint(.blue)
.widgetAccentable()
}
}
}
How can I get my text to follow the curvature of the watch face?
Post not yet marked as solved
Since iOS 16 Beta 1 and in iOS 16 Beta 3 as well the reloadAllTimelines() method of WidgetCenter no longer reloads the timelines if the app is backgrounded.
I’ve also filed FB10432865 a couple of weeks ago.
Post not yet marked as solved
I noticed that AsyncImage (https://developer.apple.com/documentation/swiftui/asyncimage) doesn't work in WidgetKit. Is this intentional? Is there a plan to support this?
Post not yet marked as solved
I have a Xcode project with a widget extension, Xcode, simulator and terminal are running with Rosetta (I can't change this).
When I build and run the main project, the widget does not get loaded on the widgets list, when running the widget scheme on Xcode the app crashes when loading the application on simulator. Same happens on device.
Macs with Intel silicon run it okay. Xcode without rosetta is also okay.
Xcode log window shows the following message:
SendProcessControlEvent:toPid: encountered an error: Error Domain=com.apple.dt.deviceprocesscontrolservice Code=8 "Failed to show Widget 'Gabriel.Widget-Rosetta.Widget' error: Error Domain=SBAvocadoDebuggingControllerErrorDomain Code=1 "Failed to get descriptors for extensionBundleID (Gabriel.Widget-Rosetta.Widget)" UserInfo={NSLocalizedDescription=Failed to get descriptors for extensionBundleID (Gabriel.Widget-Rosetta.Widget)}." UserInfo={NSLocalizedDescription=Failed to show Widget 'Gabriel.Widget-Rosetta.Widget' error: Error Domain=SBAvocadoDebuggingControllerErrorDomain Code=1 "Failed to get descriptors for extensionBundleID (Gabriel.Widget-Rosetta.Widget)" UserInfo={NSLocalizedDescription=Failed to get descriptors for extensionBundleID (Gabriel.Widget-Rosetta.Widget)}., NSUnderlyingError=0x600001106010 {Error Domain=SBAvocadoDebuggingControllerErrorDomain Code=1 "Failed to get descriptors for extensionBundleID (Gabriel.Widget-Rosetta.Widget)" UserInfo={NSLocalizedDescription=Failed to get descriptors for extensionBundleID (Gabriel.Widget-Rosetta.Widget)}}}
Domain: DTXMessage
Code: 1
User Info: {
DVTErrorCreationDateKey = "2022-07-06 14:45:31 +0000";
}
--
System Information
macOS Version 12.2.1 (Build 21D62)
Xcode 13.2.1 (19586) (Build 13C100)
Timestamp: 2022-07-06T15:45:31+01:00
Console shows the following message:
libc++abi: terminating with uncaught exception of type NSException
dyld4 config: DYLD_FRAMEWORK_PATH=/Users/gabriel.soria/DD/Widget-Rosetta-bhlamdqmnxdfvtapitjtbxxspnfc/Build/Products/Debug-iphonesimulator DYLD_LIBRARY_PATH=/Users/gabriel.soria/DD/Widget-Rosetta-bhlamdqmnxdfvtapitjtbxxspnfc/Build/Products/Debug-iphonesimulator DYLD_ROOT_PATH=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[_NSXPCDistantObject ___nsx_pingHost:]: unrecognized selector sent to instance 0x600003948aa0'
_LSContextInitReturningError() failed with error Error Domain=NSOSStatusErrorDomain Code=-10817 "(null)" UserInfo={_LSFunction=_LSSchemaConfigureForStore, ExpectedSimulatorHash={length = 32, bytes = 0xf6701f12 bb1a56bb bba5f39f 3f7801a6 ... f9fe6ee0 ef307d24 }, _LSLine=405, WrongSimulatorHash={length = 32, bytes = 0x9da4b2b1 56f7ac19 1a99bc21 b7ec95c2 ... c4004d14 03ef83dc }}
terminating with uncaught exception of type NSException
CoreSimulator 783.5 - Device: iPhone SE (2nd generation) (E360DB1E-33FF-45A4-926C-A6093DFB3699) - Runtime: iOS 15.2 (19C51) - DeviceType: iPhone SE (2nd generation)
Post not yet marked as solved
I’m able to select the widgets from my app on the simulator but they won’t appear on real devices. I already submitted my app with the widgets to the App Store and I already have that new version installed from the App Store, and still the widgets won’t appear on my iPhone. Is there some sort of setup I may be missing?
Post not yet marked as solved
What features are added to the lock screen widget, compared with ordinary widgets?
Post not yet marked as solved
I was working on widget and saw that on Xcode 13.4 after initializing the widget from target, If I make even minor changes in the EntryView body, it crashes when I run it 2-3 times and then only after mac restart, it works again. for each change, I have to restart Mac
I have uploaded a sample project with the issue in the stackoverflow
basically, created a new project, added Widget Extension Target. can be reproduced by anyone in 10 mins.
Steps to reproduce:
run the external widget once in simulator
in Struct ExternalWidgetEntryView, remove the HStack and one Text OR change from add another text OR change it to VStack. run it again on the same simulator. the app widget crashes on running and I see this [Image attached in the stackoverflow question]
https://stackoverflow.com/questions/72790887/static-configuration-widget-crash-on-xcode-13-4-1-springboard-crash
Not sure if there is any XCode config I can do to solve this.
Post not yet marked as solved
So this is an odd one. I just pushed a build from Xcode 14 for testing and installing that build on iOS 15 causes the app's home screen widgets to disappear. My app is no longer listed when I go to add a widget.
If I run it on iOS 16 everything works fine. If I run it from Xcode 14 to a simulator running iOS 15 everything is fine.
What is happening is on a true iOS 15 device it is failing to find a symbol in the WidgetKit framework.
Here is the output:
Symbol not found: _$s9WidgetKit22IntentTimelineProviderPAAE15recommendationsSayAA0C14RecommendationVy0C0QzGGyF
Referenced from: /private/var/containers/Bundle/Application/8B7C4700-E1FD-4174-BD13-B51FBA121B3D/WeatherViewer.app/PlugIns/WeatherWidgetExtension.appex/WeatherWidgetExtension
Expected in: /System/Library/Frameworks/WidgetKit.framework/WidgetKit
From what I understand the new "recommendation" method is not needed on iOS and is meant for WatchOS. I have this new method implemented and it's only @available(iOSApplicationExtension 16.0, *) so not sure why it's being called. Even if I remove it completely and try a new build it still has the WidgetKit crash.
Any help would be appreciated. I would love to get this back working and not have to rollback and ditch my iOS 16 additions.
Post not yet marked as solved
I've simply been following the documentation found here: Creating a Widget Extension. However, for some reason when I try to launch the extension I'm faced with the error:
WatchWidget does not define either an NSExtensionMainStoryboard or NSExtensionPrincipalClass key with a string value in the NSExtension dictionary in its Info.plist
Which is indeed correct, however I'm uncertain what it's supposed to point to?
I currently just have the WidgetFile, assets and the info.plist :)
Post not yet marked as solved
I'd like an Image subview of a lock screen widget to render as itself, and not with the multiply-like effect it gets today.
I've tried .widgetAccentable(true) and .widgetAccentable(false), but none have the appearance I'm looking for.
Is there maybe a new modifier that lets me "force" the rendering mode? Hoping there is and it's just not jumping out at me.
Thanks for your help.
Post not yet marked as solved
We are running into a major issue with building an iOS Widget. iOS Widgets are basically large informational app icons you can pin to your iPhone home screen (What is a widget?). iOS widgets were introduced in iOS 14.
We’ve finished building our iOS widget. However, when half of our users attempt to search for our widget after downloading our app, our widget is not showing up in the widget search results. For the other half, it works fine. This seems to be somewhat of a bug from Apple, as it is affects other widget apps (Apple Thread, the problem exists for large widget apps also). It seems like we are having this issue far more, percentage-wise, than other widget apps. I’ve searched through nearly every resource online (StackOverflow, etc.), which is why I’m posting a question now.
Things like deleting the app and reinstalling, restarting the phone, etc. have not been a fix either for these problematic users.
It doesn't seem to be tied to any iOS version (14, 15, etc.). As I have iOS 15, and it works fine. But, some users with iOS 15 are getting the bug.
Has anyone ran into this issue where a widget is not searchable? How did you fix it? Any resources are appreciated as I am at a major blocker right now. Since my app is primarily based on iOS widgets, this makes it basically unusable for certain users.
Post not yet marked as solved
I could make countdown on watch complication by using [.timer].
However its showing [Hour], [Minute] and [Second], and
I just want to show [Second] instead of [Hour] and [Minute].
Lets say if I set the time with [5 minutes] then
I would like to make it showing [300] instead of [5:00].
So what will be the best code I should write?
Please kindly advise.
Post not yet marked as solved
How to establish communication with multiple parameters in single intent with a parent-child relationship?
Where the output of the parent parameter will be input for the child parameter.
Post not yet marked as solved
Will there be a user interface to configure lock screen widgets like home screen widgets? This seems to be implied as possible based on the stock apps, such as the Clock app lock screen widget saying "Add a clock for a city to check the time at that location." I could not figure out how to bring up the configuration GUI: long press various places has no effect.
Post not yet marked as solved
I'm trying to add a watchOS app and watch widgets to an existing iOS project, similar to what's shown in wwdc2022-10050. The widget works fine when I select the iOS scheme, but when I switch over to the watchOS widget scheme, Xcode fails to generate a preview and gives this error. I'm not sure how to enable support for previews properly.
UnsupportedProductTypeError: Previews not supported for WeatherNewWidget Watch
Previews can be defined in applications, frameworks, Swift packages, or dynamic libraries
productType = com.apple.product-type.extensionkit-extension
buildable = WeatherNewWidget Watch.appex
Post not yet marked as solved
When using an Intents configuration with Widget Extension, the compiler will generate code for your configuration. But in Xcode 14, this generated code now contains warnings:
Method 'confirm(intent:)' with Objective-C selector 'confirmConfiguration:completion:' conflicts with method 'confirm(intent:completion:)' with the same Objective-C selector; this is an error in Swift 6
It seems that in Xcode 14 this generated code now contains async versions of its methods, but that these methods have the same objc selectors as the non async versions:
public protocol ConfigurationIntentHandling: NSObjectProtocol {
@objc(confirmConfiguration:completion:)
optional func confirm(intent: ConfigurationIntent, completion: @escaping (ConfigurationIntentResponse) -> Swift.Void)
@objc(confirmConfiguration:completion:)
optional func confirm(intent: ConfigurationIntent) async -> ConfigurationIntentResponse
@objc(handleConfiguration:completion:)
optional func handle(intent: ConfigurationIntent, completion: @escaping (ConfigurationIntentResponse) -> Swift.Void)
@objc(handleConfiguration:completion:)
optional func handle(intent: ConfigurationIntent) async -> ConfigurationIntentResponse
}
Is there a new way to handle widget configuration in Xcode 14? Or is this just a massive oversight? I have treat warnings as errors enabled (as everyone should) so this prevents my app from building.
Filed as FB10338460