WidgetKit

RSS for tag

Show relevant, glanceable content from your app on the iOS Home screen, iOS Lock screen, in macOS Notification Center, and as complications on Apple Watch.

WidgetKit Documentation

Posts under WidgetKit tag

136 Posts
Sort by:
Post not yet marked as solved
0 Replies
24 Views
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?
Posted
by Jklr.
Last updated
.
Post not yet marked as solved
0 Replies
34 Views
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?
Posted
by chuongle.
Last updated
.
Post not yet marked as solved
0 Replies
36 Views
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?
Posted Last updated
.
Post not yet marked as solved
1 Replies
141 Views
Has anyone been successful creating a widget configuration that uses any of the "Measurement" type parameters? I'm running into crashes in the Widget/Home Screen when I try to do so. I am building a widget that provides functionality to 'nearby' points of interest. I just discovered that SiriIntents support specifying a Measurement type now --> Distance. When I have my configuration "nearbyDistance" parameter type set to the measurement type of Distance, adding the widget from the widget gallery crashes it after I hit the add button and it doesn't get added. This works: This crashes the Widget Preview and doesn't add the widget to the Home Screen: Right before I add my widget, things seem to be good: As soon as I tap Add Widget, this happens: I have created a feedback for this and attached some recordings and a sysdiagnose: FB10002319
Posted
by edorphy.
Last updated
.
Post not yet marked as solved
1 Replies
196 Views
Hi, I want to query the user's current location from my widget, so I added have the 'NSWidgetWantsLocation' key in my widget's Info.plist, and added the code to find the location with CLLocationManager. But now if I launch the app for the very first time, before I even interact with the widget or do anything else, I start seeing the location permissions prompt which says "Allow <MyApp> to use your location". If I ignore it for a few seconds, the prompt goes away, but it's back the next time the app launches. It makes for a poor user experience for users who just download the app to try it out, and might not care about the widget at all. Why would this be happening? Does the widget run in the background even if the user never even launched the widget-picker mode? How would I know when the user *has* opened the widget, so I can see if I need to ask for location permissions or not? Here's what I've tried: deleting the app, and then resetting Privacy prompts (same problem) setting 'NSWidgetWantsLocation' to No stops the prompt from showing up, but defeats the purpose of finding the user's location Thanks for the help.
Posted
by zulfishah.
Last updated
.
Post not yet marked as solved
3 Replies
293 Views
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
Posted
by adysart.
Last updated
.
Post not yet marked as solved
3 Replies
249 Views
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.
Posted Last updated
.
Post not yet marked as solved
0 Replies
42 Views
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 }
Posted
by fwzhou.
Last updated
.
Post not yet marked as solved
0 Replies
97 Views
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?
Posted Last updated
.
Post not yet marked as solved
2 Replies
188 Views
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?
Posted Last updated
.
Post not yet marked as solved
0 Replies
49 Views
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?
Posted
by enricot.
Last updated
.
Post not yet marked as solved
0 Replies
69 Views
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)
Posted
by macbieoo.
Last updated
.
Post not yet marked as solved
3 Replies
729 Views
I am trying to display the default implementation of the widget in the xcode 12 beta 3 and beta 4, if I create a new project, the widget is displayed successfully, but in the project of our company, after a successful build, the simulator starts and after nothing happens. I don't see any difference in the codebase of the widget classes. Also the preview doesn't work for me, I get the following error: RemoteHumanReadableError ProcessError: Failed to launch widget extension: The operation couldn’t be completed. (Foundation._GenericObjCError error 0.) But if I create a project from scratch, then the preview works well.
Posted
by CocoaSide.
Last updated
.
Post not yet marked as solved
3 Replies
471 Views
We have a bit of a complicated build process and need to build the Widget outside of our main app and repackage since we are using a cross platform framework. I tried scripting out updating my Widget's Marketing Version but agvtool won't update the MARKETING_VERSION in the project.pbxproj file. Therefore, we end up getting these emails from Apple: ITMS-90473: CFBundleShortVersionString Mismatch - The CFBundleShortVersionString value ‘1.2.2’ of extension ‘MyiOSApp.app/PlugIns/widgetExtension.appex' does not match the CFBundleShortVersionString value ‘1.2.3' of its containing iOS application ‘MyiOSApp.app'. I run this and it says it's updating in the Widget plist (but not the project.pbxproj) so when I build with xcode via command line it doesn't update and when we submit to the App Store we get the above message from Apple: /usr/bin/agvtool new-marketing-version $(/usr/libexec/PlistBuddy -c "Print :CFBundleShortVersionString" ../My.Crossplatform.App/My.Crossplatform.App.iOS/Info.plist) Setting CFBundleShortVersionString of project ios to:    1.2.3. Updating CFBundleShortVersionString in Info.plist(s)... Cannot find "ios.xcodeproj/../YES" Updated CFBundleShortVersionString in "ios.xcodeproj/../widget/Info.plist" to 1.2.3 I've had to resort to manually updating then submitting every time. What is the correct way to update the MARKETING_VERSION in the project.pbxproj file in a CI environment using bash?
Posted Last updated
.
Post not yet marked as solved
0 Replies
80 Views
What features are added to the lock screen widget, compared with ordinary widgets?
Posted
by xuqinghao.
Last updated
.
Post not yet marked as solved
0 Replies
79 Views
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.
Posted
by subodhsah.
Last updated
.
Post not yet marked as solved
1 Replies
110 Views
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 :)
Posted
by jazerix.
Last updated
.
Post not yet marked as solved
0 Replies
103 Views
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.
Posted
by J0hn.
Last updated
.
Post not yet marked as solved
7 Replies
1.5k Views
Hi there While developing a new widget with WidgetKit, my app crashes almost immediately every time I launch the extension with the error "[NSXPCDistantObject _nsxpingHost:]: unrecognized selector sent to instance" Does anyone else have this problem? Is this due to the Xcode beta? Thanks!
Posted Last updated
.