Post not yet marked as solved
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 {
		public typealias Entry = SimpleEntry
		public func snapshot(with context: Context, completion: @escaping (SimpleEntry) -> ()) {
				NSLog("getting snapshot")
				let entry = SimpleEntry(date: Date())
				completion(entry)
		}
		public func timeline(with context: Context, completion: @escaping (Timeline<Entry>) -> ()) {
				NSLog("getting timeline")
				var entries: [SimpleEntry] = []
				let currentDate = Date()
				for hourOffset in 0 ..< 5 {
						let entryDate = Calendar.current.date(byAdding: .hour, value: hourOffset, to: currentDate)!
						let entry = SimpleEntry(date: entryDate)
						entries.append(entry)
				}
				NSLog("\(entries)")
				let timeline = Timeline(entries: entries, policy: .atEnd)
				completion(timeline)
		}
}
struct SimpleEntry: TimelineEntry {
		public let date: Date
}
struct PlaceholderView : View {
		var body: some View {
				Text("Placeholder View")
		}
}
struct SampleWidgetEntryView : View {
		var entry: Provider.Entry
		var body: some View {
				VStack {
						Text(entry.date, style: .time)
				}
		}
}
@main
struct SampleWidget: Widget {
		private let kind: String = "SampleWidget"
		public var body: some WidgetConfiguration {
				StaticConfiguration(kind: kind, provider: Provider(), placeholder: PlaceholderView()) { entry in
						SampleWidgetEntryView(entry: entry)
				}
				.configurationDisplayName("My Widget")
				.description("This is an example widget.")
		}
}
I want help in giving a refreshing policy that refreshes once a day.
Post not yet marked as solved
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)
Post not yet marked as solved
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?
Post not yet marked as solved
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!
Post not yet marked as solved
Hey,
Is it possible to only offer a certain amount of widget functionality to users who have purchased an in-app purchase or are ongoing subscribers?
Thanks!
Post not yet marked as solved
Hi y'all, I'm trying to create an Intent Extension that updates a widget, but I can't get the widget to update unless the app is in the foreground. Right now I'm using .continueInApp, but that's not such a great UX...
Has anyone experienced this? I've submitted it as FB7845957
Post not yet marked as solved
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!
Post not yet marked as solved
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?
Post not yet marked as solved
I want to create a widget that updates every 15 minutes.
Here is my code:
public func timeline(with context: Context, completion: @escaping (Timeline<Entry>) -> ()) {
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<FavoriteEntry>(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.
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 ?
Post not yet marked as solved
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.
Post not yet marked as solved
Sometime, when I open the Widget Gallery, function getSnapshot(for:in:completion:) in TimelineProvider is not called. Is this a feature or a bug? When is this function called?
Thank you.
Post not yet marked as solved
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
Post not yet marked as solved
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?
Post not yet marked as solved
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.
Post not yet marked as solved
It is noted that configurationDisplayName and description for iOS 14 Home Widget is not changing based on localization values added. How Apple's native apps doing the localization for the same.
Post not yet marked as solved
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.
Post not yet marked as solved
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:	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:	0
Thread 0 name:
Thread 0 Crashed:
0	 WidgetKit										 0x00000001e79e1424 closure #1 in WidgetExtensionContext.getDescriptors(completion:) + 176 (WidgetExtensionContext.swift:88)
1	 WidgetKit										 0x00000001e79e13bc closure #1 in WidgetExtensionContext.getDescriptors(completion:) + 72 (WidgetExtensionContext.swift:88)
2	 WidgetKit										 0x00000001e79e0844 thunk for @escaping @callee_guaranteed () -> () + 20 (<compiler-generated>:0)
3	 libdispatch.dylib						 0x00000001a8235298 _dispatch_call_block_and_release + 24 (init.c:1454)
4	 libdispatch.dylib						 0x00000001a8236280 _dispatch_client_callout + 16 (object.m:559)
5	 libdispatch.dylib						 0x00000001a82185b8 _dispatch_main_queue_callback_4CF$VARIANT$armv81 + 856 (inline_internal.h:2548)
6	 CoreFoundation								 0x00000001a84f580c CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE + 12 (CFRunLoop.c:1790)
7	 CoreFoundation								 0x00000001a84efcc4 __CFRunLoopRun + 2480 (CFRunLoop.c:3118)
8	 CoreFoundation								 0x00000001a84eeddc CFRunLoopRunSpecific + 572 (CFRunLoop.c:3242)
9	 Foundation										 0x00000001a8884158 -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 228 (NSRunLoop.m:374)
10	Foundation										 0x00000001a88b5264 -[NSRunLoop(NSRunLoop) run] + 88 (NSRunLoop.m:399)
11	libxpc.dylib									 0x00000001a8138748 _xpc_objc_main + 684 (main.m:265)
12	libxpc.dylib									 0x00000001a813a938 xpc_main + 176 (init.c:1198)
13	Foundation										 0x00000001a88b7468 -[NSXPCListener resume] + 300 (NSXPCListener.m:448)
14	PlugInKit										 0x00000001b7829d68 -[PKService run] + 396 (PKService.m:186)
15	PlugInKit										 0x00000001b78299d8 +[PKService main] + 572 (PKService.m:115)
16	PlugInKit										 0x00000001b782a160 +[PKService _defaultRun:arguments:] + 20 (PKService.m:233)
17	ExtensionKit									 0x00000001e9cea994 EXExtensionMain + 80 (EXExtensionMain.m:23)
18	Foundation										 0x00000001a89f1ccc NSExtensionMain + 192 (NSExtensionMain.m:13)
19	libdyld.dylib								 0x00000001a83845c4 start + 4
Thread 1:
0	 libsystem_pthread.dylib			 0x00000001a829086c start_wqthread + 0
Thread 2:
0	 libsystem_pthread.dylib			 0x00000001a829086c start_wqthread + 0
Thread 3:
0	 libsystem_pthread.dylib			 0x00000001a829086c start_wqthread + 0
Thread 4:
0	 libsystem_pthread.dylib			 0x00000001a829086c start_wqthread + 0
Post not yet marked as solved
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?