WidgetKit

RSS for tag

Show 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

WidgetKit TimelineProvider calling timeline() continuously
A newly created Widget extension, with the default code created by Xcode will continuously call the timeline() function while the widget is being debugged. Code provided below: import WidgetKit import SwiftUI struct Provider: TimelineProvider { &#9;&#9;public typealias Entry = SimpleEntry &#9;&#9;public func snapshot(with context: Context, completion: @escaping (SimpleEntry) -> ()) { &#9;&#9;&#9;&#9;NSLog("getting snapshot") &#9;&#9;&#9;&#9;let entry = SimpleEntry(date: Date()) &#9;&#9;&#9;&#9;completion(entry) &#9;&#9;} &#9;&#9;public func timeline(with context: Context, completion: @escaping (Timeline&lt;Entry&gt;) -> ()) { &#9;&#9;&#9;&#9;NSLog("getting timeline") &#9;&#9;&#9;&#9;var entries: [SimpleEntry] = [] &#9;&#9;&#9;&#9;let currentDate = Date() &#9;&#9;&#9;&#9;for hourOffset in 0 ..< 5 { &#9;&#9;&#9;&#9;&#9;&#9;let entryDate = Calendar.current.date(byAdding: .hour, value: hourOffset, to: currentDate)! &#9;&#9;&#9;&#9;&#9;&#9;let entry = SimpleEntry(date: entryDate) &#9;&#9;&#9;&#9;&#9;&#9;entries.append(entry) &#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;NSLog("\(entries)") &#9;&#9;&#9;&#9;let timeline = Timeline(entries: entries, policy: .atEnd) &#9;&#9;&#9;&#9;completion(timeline) &#9;&#9;} } struct SimpleEntry: TimelineEntry { &#9;&#9;public let date: Date } struct PlaceholderView : View { &#9;&#9;var body: some View { &#9;&#9;&#9;&#9;Text("Placeholder View") &#9;&#9;} } struct SampleWidgetEntryView : View { &#9;&#9;var entry: Provider.Entry &#9;&#9;var body: some View { &#9;&#9;&#9;&#9;VStack { &#9;&#9;&#9;&#9;&#9;&#9;Text(entry.date, style: .time) &#9;&#9;&#9;&#9;} &#9;&#9;} } @main struct SampleWidget: Widget { &#9;&#9;private let kind: String = "SampleWidget" &#9;&#9;public var body: some WidgetConfiguration { &#9;&#9;&#9;&#9;StaticConfiguration(kind: kind, provider: Provider(), placeholder: PlaceholderView()) { entry in &#9;&#9;&#9;&#9;&#9;&#9;SampleWidgetEntryView(entry: entry) &#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;.configurationDisplayName("My Widget") &#9;&#9;&#9;&#9;.description("This is an example widget.") &#9;&#9;} }
5
0
2.3k
Oct ’23
Debugging WidgetKit install error "Failed to get descriptors for extensionBundleID"
I'm trying to create an iOS 14 WidgetKit widget. It's compiling, but when I try to run it, on either simulator or device, I get the error below: Any suggestions on how to debug this? Details SendProcessControlEvent:toPid: encountered an error: Error Domain=com.apple.dt.deviceprocesscontrolservice Code=8 "Failed to show Widget 'com.myapp.dev.WidgetKitExtension' error: Error Domain=SBAvocadoDebuggingControllerErrorDomain Code=1 "Failed to get descriptors for extensionBundleID (com.myapp.dev.WidgetKitExtension)" UserInfo={NSLocalizedDescription=Failed to get descriptors for extensionBundleID (com.myapp.dev.WidgetKitExtension)}." UserInfo={NSLocalizedDescription=Failed to show Widget 'com.myapp.dev.WidgetKitExtension' error: Error Domain=SBAvocadoDebuggingControllerErrorDomain Code=1 "Failed to get descriptors for extensionBundleID (com.myapp.dev.WidgetKitExtension)" UserInfo={NSLocalizedDescription=Failed to get descriptors for extensionBundleID (com.myapp.dev.WidgetKitExtension)}., NSUnderlyingError=0x7fc0b0d12540 {Error Domain=SBAvocadoDebuggingControllerErrorDomain Code=1 "Failed to get descriptors for extensionBundleID (com.myapp.dev.WidgetKitExtension)" UserInfo={NSLocalizedDescription=Failed to get descriptors for extensionBundleID (com.myapp.dev.WidgetKitExtension)}}} Domain: DTXMessage Code: 1- System Information macOS Version 10.15.5 (Build 19F101) Xcode 12.0 (17177)
34
0
20k
Dec ’23
Variable WidgetBundle Configurations possible?
I am trying to implement a variable configuration for my WidgetBundle. For example, I would like to have a widget only available for certain customers. The general idea would be some like this like: @main struct Widgets: WidgetBundle {     @WidgetBundleBuilder     var body: some Widget { if Membership.active? { WidgetA() WidgetB() WidgetPremium()     } else { WidgetA() WidgetB() } } } I realize that this particular syntax is invalid, but I've tried all manner of Function builder syntaxes I could think of to make something like this work but haven't been able to get any to work for widgets. In SwiftUI we have the conditional function builders, but I can't quite discover if they don't exist here or I'm just missing them. Is this type of configurability possible? Thank you!
4
1
2.3k
Aug ’23
Widget timeline policy not working
I want to create a widget that updates every 15 minutes. Here is my code: public func timeline(with context: Context, completion: @escaping (Timeline&lt;Entry&gt;) -> ()) {     let currentDate = Date() print("@@timeline update. \(currentDate)")     let next = Calendar.current.date(byAdding: .minute, value: 15, to: currentDate)!     let entry = FavoriteEntry(date: currentDate, item: mock_favorite)     let timeline = Timeline&lt;FavoriteEntry&gt;(entries: [entry], policy: .after(next))     completion(timeline)   } Result: timeline update. 2020-07-19 07:11:27 +0000 2020-07-19 16:11:28.005325+0900 FavoriteExtension[12206:3240076] libMobileGestalt MobileGestaltCache.c:38: No persisted cache on this platform. @@timeline update. 2020-07-19 07:11:28 +0000 @@timeline update. 2020-07-19 07:11:28 +0000 @@timeline update. 2020-07-19 07:11:28 +0000 But My widget is not updated since it was first created. Please let me know what I did wrong.
6
0
1.1k
Oct ’23
can I get current location in widgetKit
As far as I can tell in my app I am requesting current location in the app and in the widget the same, but I am not ever seeing my widget make the network call the I would expect if current location was successful. I have the same info plist permissions for usage and request for access in both the app and the widget ( runs the same shared code ). My question is does widgetKit work to get core location similar to the the way that today extensions work. or do I need to cache it from the phone app and hope its been updated ?
4
0
2.3k
Oct ’23
getTimeline called twice on load
When I run my widget from xcode I see getTimeline is called twice for some reason. It's called the first time, then after it returns a timeline it's called again. The logs have the following message: "-[EXSwiftUI_Subsystem beginUsing:withBundle:] unexpectedly called multiple times." It takes about 0.5 seconds for the first getTimeline call to return so it doesn't seem like the OS should try to call this method again so quickly (my timeline entries all have times in the future so they shouldn't request the widget to load immediately) Is this a bug, or expected? Seems to happen every time I run the widget.
8
1
3.3k
Sep ’23
Updating Widgets from StaticConfiguration to IntentConfiguration Requires Re-Installation
I'm updating my widget from StaticConfiguration to IntentConfiguration. When I do so, existing widgets installed within simulators and on my iPhone device either show a blank screen or a placeholder screen and fail to initialize. Is there a safe way to upgrade my widget configuration? I would hate to break the widget for our existing users and force them to manually reinstall.
9
0
2.2k
Jun ’24
Widget SwiftUI previews failure when adding a dependency
Repro steps: Create new project Create WidgetKit extension (verify that previews work) Create dummy framework (verify that previews still work) Link dummy framework to the widget extension At that point, preview stops working with the following error: "RemoteHumanReadableError ProcessError: Failed to launch widget extension: The operation couldn’t be completed. (CHSErrorDomain error 1050.)" What can I do to make this work?
10
1
5.8k
Sep ’23
SwiftUI: WidgetKit Gradient Bug
I'm trying to make a gradient for Widgets and using 2 blue colors (#0091f1 and #0054f3) but the Widget background looks green. I've set up colors via Assets.xcassets and then using the following code: LinearGradient(gradient: Gradient(colors: [Color("color1"), Color("color2")]), startPoint: .top, endPoint: .bottom) For the common iOS target the gradient looks right (blue) and for the Widgets extension it's green. Could you help me to figure out why this is happening? The link - https://github.com/maximbilan/SwiftUI-WidgetKit-Gradient-Issue to the example with screenshots.
4
0
2k
Aug ’23
"No options were provided for this parameter" in Edit Widget menu
I had to create a separate thread for the problem I'm facing with WidgetKit. Environment: Xcode 12.0.1 iOS 14.0 App targeting iOS 10 Widget targeting iOS 14 Intents Extension targeting iOS 10 • I have created Intents Extension. • Created Intents Definition file in Widget target, added it to all the three targets (app, widget, intents extension).  • Declared conformance to the intent handling protocol in IntentHandler (Intents Extension). • Set up Intent Timeline Provider in Widget target.  • Added Siri to the app capabilities. If I go to Edit widget -> tap on a dynamic option it says: No options were provided for this parameter. Intents Extension provides data, but I'm not sure how iOS wires the Intents Extension and widget. From what I see I'm sure that my code inside IntentsHandler.swift is never called.
12
1
9.6k
Aug ’23
iOS14 Widget Crash
I found a lot of widget crashes in the AppStore, looking at the call stack crashes should be in the widget initialization phase, and there is not an execution to the project code, what is the cause of this problem? The crashing system is iOS14 and iOS14.2 This is a few related crashes: Exception Type:&#9;EXC_BREAKPOINT (SIGTRAP) Exception Codes: 0x0000000000000001, 0x00000001e79e1424 Termination Signal: Trace/BPT trap: 5 Termination Reason: Namespace SIGNAL, Code 0x5 Terminating Process: exc handler [318] Triggered by Thread:&#9;0 Thread 0 name: Thread 0 Crashed: 0&#9; WidgetKit&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9; 0x00000001e79e1424 closure #1 in WidgetExtensionContext.getDescriptors(completion:) + 176 (WidgetExtensionContext.swift:88) 1&#9; WidgetKit&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9; 0x00000001e79e13bc closure #1 in WidgetExtensionContext.getDescriptors(completion:) + 72 (WidgetExtensionContext.swift:88) 2&#9; WidgetKit&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9; 0x00000001e79e0844 thunk for @escaping @callee_guaranteed () -> () + 20 (<compiler-generated>:0) 3&#9; libdispatch.dylib&#9;&#9;&#9;&#9;&#9;&#9; 0x00000001a8235298 _dispatch_call_block_and_release + 24 (init.c:1454) 4&#9; libdispatch.dylib&#9;&#9;&#9;&#9;&#9;&#9; 0x00000001a8236280 _dispatch_client_callout + 16 (object.m:559) 5&#9; libdispatch.dylib&#9;&#9;&#9;&#9;&#9;&#9; 0x00000001a82185b8 _dispatch_main_queue_callback_4CF$VARIANT$armv81 + 856 (inline_internal.h:2548) 6&#9; CoreFoundation&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9; 0x00000001a84f580c CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE + 12 (CFRunLoop.c:1790) 7&#9; CoreFoundation&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9; 0x00000001a84efcc4 __CFRunLoopRun + 2480 (CFRunLoop.c:3118) 8&#9; CoreFoundation&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9; 0x00000001a84eeddc CFRunLoopRunSpecific + 572 (CFRunLoop.c:3242) 9&#9; Foundation&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9; 0x00000001a8884158 -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 228 (NSRunLoop.m:374) 10&#9;Foundation&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9; 0x00000001a88b5264 -[NSRunLoop(NSRunLoop) run] + 88 (NSRunLoop.m:399) 11&#9;libxpc.dylib&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9; 0x00000001a8138748 _xpc_objc_main + 684 (main.m:265) 12&#9;libxpc.dylib&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9; 0x00000001a813a938 xpc_main + 176 (init.c:1198) 13&#9;Foundation&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9; 0x00000001a88b7468 -[NSXPCListener resume] + 300 (NSXPCListener.m:448) 14&#9;PlugInKit&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9; 0x00000001b7829d68 -[PKService run] + 396 (PKService.m:186) 15&#9;PlugInKit&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9; 0x00000001b78299d8 +[PKService main] + 572 (PKService.m:115) 16&#9;PlugInKit&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9; 0x00000001b782a160 +[PKService _defaultRun:arguments:] + 20 (PKService.m:233) 17&#9;ExtensionKit&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9; 0x00000001e9cea994 EXExtensionMain + 80 (EXExtensionMain.m:23) 18&#9;Foundation&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9; 0x00000001a89f1ccc NSExtensionMain + 192 (NSExtensionMain.m:13) 19&#9;libdyld.dylib&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9; 0x00000001a83845c4 start + 4 Thread 1: 0&#9; libsystem_pthread.dylib&#9;&#9;&#9; 0x00000001a829086c start_wqthread + 0 Thread 2: 0&#9; libsystem_pthread.dylib&#9;&#9;&#9; 0x00000001a829086c start_wqthread + 0 Thread 3: 0&#9; libsystem_pthread.dylib&#9;&#9;&#9; 0x00000001a829086c start_wqthread + 0 Thread 4: 0&#9; libsystem_pthread.dylib&#9;&#9;&#9; 0x00000001a829086c start_wqthread + 0
3
1
940
Sep ’23
agvtool doesn't update extension Marketing Version
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?
6
1
5.2k
Oct ’23
App crashes when trying to run widget extension - M1 Mac with Rosetta
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)
1
0
1.2k
Jan ’24