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.

WidgetKit Documentation

Posts under WidgetKit tag

311 Posts
Sort by:
Post not yet marked as solved
5 Replies
2k Views
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;} }
Posted
by
Post not yet marked as solved
34 Replies
18k Views
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)
Posted
by
Post not yet marked as solved
11 Replies
6.9k Views
Any insights on how to incorporate CloudKit (or CoreData) in the WidgetKit extension? Where in the WidgetKit api do I make the asynchronous call to load the data to be available for the TimelineProvider?
Posted
by
Post not yet marked as solved
11 Replies
8.3k Views
I'm unable to share UserDefaults with the same suiteName with newly announced iOS 14 widgetkit extension (It constantly returns nil). Is there anything that I should do apart from having same suite name for this to work? Thanks!
Posted
by
Post not yet marked as solved
4 Replies
2.1k Views
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!
Posted
by
Post not yet marked as solved
6 Replies
4.7k Views
I want a widget to use the same custom fonts that the containing app uses. I do not want multiple copies of the font files in the app bundle. I put the font files into a framework shared by the app and the widget extension. I have code to register the fonts from the framework bundle using CTFontManagerRegisterGraphicsFont. That works from the app, but it does not work from the widget extension because it requires UIKit. (At least I think that's why it doesn't seem to work from my widget extension.) Widgets cannot run UIKit code. Is there a way to programmatically register the fonts in a widget? If not is there a way I can make a UIAppFonts Info.plist entry point to a framework?
Posted
by
Post not yet marked as solved
6 Replies
957 Views
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.
Posted
by
Post marked as solved
4 Replies
2.0k Views
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 ?
Posted
by
Post not yet marked as solved
8 Replies
3k Views
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.
Posted
by
Post not yet marked as solved
6 Replies
3.2k Views
Anyone know how to solve this error? I have no idea why it's happening because I'm not using NSFileHandle or anything like that at all, my widget is super simple: makes an API call, processes it with SwiftyJSON, and displays very simple data. Thanks in advance
Posted
by
Post not yet marked as solved
10 Replies
5.3k Views
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?
Posted
by
Post not yet marked as solved
4 Replies
1.9k Views
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.
Posted
by
Post not yet marked as solved
12 Replies
9.2k Views
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.
Posted
by
Post not yet marked as solved
3 Replies
794 Views
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
Posted
by
Post not yet marked as solved
6 Replies
4.6k 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
by