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
1 Replies
245 Views
I added a spotify widget on the first page of my home screen. That widget is working fine and totally normal. On the second page of my home screen, there is another widget floating with the little minus sign like when you add or delete an app/widget on your screen. My apps sit on top of it, I can't move it, I can't delete it. Anyone dealt with this before?
Posted
by
Post not yet marked as solved
2 Replies
379 Views
Environment: iOS Version: 17.2 iOS Simulator Version: 17.2 Xcode Version: 15.2 Device: iPhone 15 Pro Max App Target Version: iOS 17.2 Preconditions: App with Live Activity feature is installed. Device/Simulator is running iOS 17.2. Steps to Reproduce: Start the app and initiate a Live Activity with text styled as .timer. Lock the device screen or switch to the lock screen view in the iOS Simulator. Observe the Live Activity on the lock screen, noting the text style. Unlock the device. This time noting the .timer changed its style. The text style of the Live Activity remains consistent both on the lock screen and after unlocking the device, maintaining its .timer style throughout its lifecycle. Frequency: Occurs every time the steps are reproduced.
Posted
by
Post not yet marked as solved
2 Replies
569 Views
⌚️Hello, I've noticed in watchOS 10 that when a complication is in the Smart Stack, the value of WCSession.isComplicationEnabled is false. I'm not sure if this is intentional or a bug. It seems trivial at first glance, but it actually affects the communication mechanism mentioned in Implementing Two-Way Communication Using Watch Connectivity. In the following two scenarios, if the user has only added the app's complication to the Smart Stack, then the watch app will not be able to communicate properly with the iOS app. Scenario 1 - WCSession.transferCurrentComplicationUserInfo() // update complications from the iOS app if WCSession.default.isComplicationEnabled { let userInfoTransfer = WCSession.default.transferCurrentComplicationUserInfo(userInfo) // ... } As described in Implementing Two-Way Communication Using Watch Connectivity, when the iOS app proactively updates the data of the watch app, since WCSession.isComplicationEnabled is false, WCSession will refuse to transfer any data. This causes the standalone complication in Smart Stack to not be updated. Scenario 2 - WKApplicationRefreshBackgroundTask When the watch app uses WKApplication.scheduleBackgroundRefresh() to periodically update data, as long as the user has added the app's complication to the watch face, the corresponding WKApplicationRefreshBackgroundTask can be executed periodically in the background to fetch data. However, if the user has only added complication to the Smart Stack, then the watch app will be completely purged, and the background task will not be executed at all. Although WCSession.isComplicationEnabled is not directly used in this scenario, its behavior appears to be the same, that is, the complication in the Smart Stack is not considered a complication by the system. Should I submit a bug report?
Posted
by
Post not yet marked as solved
0 Replies
385 Views
I am facing an issue with the .after policy in SwiftUI Timeline. The update is not occurring at the exact time I have specified; there are delays ranging from 5 minutes to 3 minutes, etc. How can I resolve this issue? What can I do to ensure that the update happens precisely at the specified time without any delay? Code Example: struct SimpleEntry: TimelineEntry { let date: Date } func getTimeline(in context: Context, completion: @escaping (Timeline<SimpleEntry>) -> Void) { // For example, a future date and time: 2024-02-01 12:00:00 let refreshDateComponents = DateComponents(year: 2024, month: 2, day: 1, hour: 12, minute: 0, second: 0) // Create a Date object using the specified date and time if let refreshDate = Calendar.current.date(from: refreshDateComponents) { // Create a SimpleEntry using the generated Date object let entry = SimpleEntry(date: refreshDate) // Create a Timeline and perform the completion with it let timeline = Timeline(entries: [entry], policy: .after(refreshDate)) completion(timeline) } // Return an empty Timeline in case of an error else { let emptyTimeline = Timeline(entries: [], policy: .never) completion(emptyTimeline) } }
Posted
by
Post not yet marked as solved
0 Replies
260 Views
I see this warning a lot in console.log when my widgets update, is it just noise or is there something I could be doing wrong in my widgets. I don't do anything explicitly with the runloop in my code, it's just regular SwiftUI to render a widget.
Posted
by
Post not yet marked as solved
1 Replies
351 Views
Whenever I try to put my choice of time zones on the MacBook clock widget, it won't show on the main widget. It will show the stock clock options. Such as Cupertino, Tokyo, Sydney, and Paris, Even though I change them inside the app the widget won't display the changes.
Posted
by
Post not yet marked as solved
8 Replies
977 Views
Hello! I'm working on the watchOS app that provides user with multiple fancy complication sets. There are about 50 widgets in our WidgetBundle now. With this amount we reached memory limit and the app crashes: Thread 1: EXC_RESOURCE (RESOURCE_TYPE_MEMORY: high watermark memory limit exceeded) (limit=15 MB) I inspected complicationExtension.appex content and find out that most volume is occupied by the executable: Localized strings (12 langs) altogether - 165 KB Assets.car - 1.1 MB Imported fonts TTF files altogether - 866 KB complicationsExtension executable file - 8.2 MB Why it takes so much space and how can it be made smaller?
Posted
by
Post not yet marked as solved
0 Replies
370 Views
I'm in process of reimplementing my app in SwiftUI and WidgetKit. So far so good, I really like that I can finally use SwiftUI views for widgets. However, I'm having issues with AccessoryInline widget on Utility watch face. My old UtilitarianLarge complication displays in full color, but AccessoryInline widget displays only in gray - it's not even widgetAccentable on Utility watch face. I receive widgetRenderingMode from the Environment, and it shows fullColor. However, no matter how I try to apply color to the image or text, both stay gray. This widget family is not documented well (as many of things in WatchOS), and Google/ChatGPT/Bing produced zero usable results. It looks like it's a bug in WIdgetKit. If it's supposed to be displayed in Accented mode only, it should report as such in widgetRenderingMode (and support WidgetAccentable). Otherwise it should display in full color, just like the old complication.
Posted
by
Post not yet marked as solved
0 Replies
301 Views
Hi, In our tests, especially when we tested the new widgets with interactions (introduced in iOS 17), we found that sometimes they can hang when fetching data from CoreData using background context. I realise that there is no reason to use background context in widgets, but in our case we were reusing logic and so there were multiple background contexts. I'm trying to find information about using background context in widgets, but I can't find it. Now we avoid using background context in widgets, but it would be interesting to know if the use of CoreData background context in widgets is not allowed or could it be a kind of bug? Perhaps this information would be useful to anyone trying to find the cause of widget hangs.
Posted
by
Post not yet marked as solved
0 Replies
200 Views
The problem is: I have some widgets at different XCode targets (as a result at different widget bundles). Bundles have different permissions, so I can't place all wisgets at the same bundle. I want to order widgets from different bundles at a custom order at Add Widget Screen. But I have different orders at different devices with different iOS versions and it is unwanted behaviour for my app. I want to have the same custom order for all widgets from different WidgetBundles
Post not yet marked as solved
0 Replies
404 Views
I have a countdown/up timer in a widget, and I want to format the timer to something more readable than the default that Text.init(myDate, style: .timer) provides. The default outputs a timer for just the hours in the date range. So, for example, a timer of 1 week, 5 hours, 12 minutes and 45 seconds will appear as 173:12:45 (which is 7 * 24 + 5 = 173) - not very user-friendly. An ideal output would be 1 week 05:12:45. Is there any way of doing that? I've tried a number of different ways using TimeInterval, DateInterval, and modding (%) values - like modding the hours count by 168 to get a number of weeks - but they're pretty much useless when there are never a set number of days or weeks in a year due to leap years. It would be great if you would provide actual code examples rather than saying to use a certain API, as I could very easily go down a rabbit hole like I have with TimeInterval and DateInterval. Thanks!
Posted
by
Post not yet marked as solved
0 Replies
322 Views
I read in official documents that there is a height range of 84-160. But when I preview, it is always fixed at a certain height. What should I do to make the height of DynamicIslandExpandedRegion grow dynamically according to the content?
Posted
by
Post not yet marked as solved
0 Replies
343 Views
we know ios support widget added through home screen by user, i want to know can ios support widget added by api like android? best wishes! https://developer.apple.com/design/human-interface-guidelines/widgets
Posted
by
Post not yet marked as solved
3 Replies
504 Views
My widget will not load on my simulator or devices with IO7 17.2 I am getting preview error "Widget needs to adopt containerBackground". The background image is called "bg" and code is below, how do I fix this issue? var body: some View { ZStack{ Image("bg") .resizable() .aspectRatio(contentMode: .fill) VStack{ Text(entry.namazName) .foregroundColor(Color.white) .font(.custom("HelveticaNeue-Medium", size: 24)) Spacer() .frame(height: 8) Text("B: " + entry.startTime) .foregroundColor(Color.white) .font(.custom("HelveticaNeue-Medium", size: 22)) Text("J: " + entry.jamatTime) .foregroundColor(Color.white) .font(.custom("HelveticaNeue-Medium", size: 22)) } } }
Posted
by
Post not yet marked as solved
1 Replies
369 Views
My guess is no... but, I have to ask. I made a widget that checks our GitHub repository for new pull requests - in an attempt to make sure PRs are addressed quicker. It works great - using GitHub's API. It's on my iPhone's Lock Screen. It definitely keeps me more on top of our pull requests! Our product manager asked if we could also send a local notification when there's a new PR. I was thinking maybe from the widget - it's updating around every 15 minutes - and if there's a new PR - then maybe it could fire a local notification. However, there's the permissions. The user has to say "OK" to them. Widget can't do that. Can it inherit the notification permissions from the parent app? Anyway - I think it is way overkill - I mean we have a widget! Why a notification as well!?!?!? I thought I'd ask... Thanks, Scott iOS 17.
Posted
by
Post not yet marked as solved
0 Replies
539 Views
Hello Apple Community, I am writing to discuss a limitation I’ve encountered with third-party alarm clock apps on iOS. As it stands, these apps are unable to function like the native Clock app, primarily due to the restrictions imposed by the operating system. Currently, third-party alarm apps rely on standard local notifications, which fire once and then cease. This means that if a user misses the initial notification, there’s no backup mechanism to ensure they are alerted. This is a significant drawback for users who rely on these apps to manage their time effectively. Moreover, some apps have found a workaround by playing a silent sound in the background to keep the app active. However, this method is not only against Apple’s guidelines but also drains the device’s battery life. I propose that Apple consider allowing third-party apps to push notifications from the background in an alarm style, with clear permissions granted by the user. This would enable users to clearly define acceptable notifications and specify an alarm-like display, providing a more personalized and effective alarm experience. By implementing this change, Apple could greatly enhance the functionality and user-friendliness of third-party alarm clock apps, ultimately benefiting the end-users and developers alike. Because this alarm feature is so important for productivity and quick responses to critical events or triggers I'm trying to see how some concepts could be reimagined if we had a little more flexibility. Apple iOS has a feature called StandBy mode that activates when an iPhone is charging and positioned on its side. This feature can be thought of as a kind of smart display for your iPhone that offers fast access to different screens of glanceable information. Always-On Display: StandBy mode can keep the display on even when the phone is locked, which is useful for an alarm app. Users can glance at the time without having to unlock their phone w/ Low-Light Adaptation Customizable Screens: StandBy mode consists of screens that can be accessed by swiping horizontally on your iPhone’s display. This could allow an alarm app to display additional information, such as route, or weather warnings. Interactive Widgets: The widget screen in StandBy mode is interactive and customizable. I look forward to hearing your thoughts on this matter. Best regards, Phil Cutting
Posted
by
Post not yet marked as solved
1 Replies
601 Views
Hey there, I'm implementing Watch Complications in an existing project, and I'm having the problem that transferCurrentComplicationUserInfo(_:) works exactly as transferUserInfo(_:) is described in the documentation, but not as it should. That is, when the WatchApp is opened, func session(_ session: WCSession, didReceiveUserInfo userInfo: [String: Any] = [:]) receives the data sent by transferCurrentComplicationUserInfo(_:). If not, the data is queued until the Watch App is opened again. In other words, transferCurrentComplicationUserInfo(_:) never wakes up the ExtensionDelegate when the Watch App is not running. Has anyone experienced the same thing and know how to fix it? More details: Testing on iPhone 11 (iOS 17.1.2) and Apple Watch SE (WatchOS 10.2) I made sure that the quota of 50 is not exhausted when I test. The WatchApp is still dual-target (I want to avoid having to migrate to single-target and SwiftUI lifecycle) Watch App code: class ExtensionDelegate: NSObject, WKExtensionDelegate, WCSessionDelegate { let session = WCSession.default override init() { super.init() if WCSession.isSupported() { session.delegate = self session.activate() } } func session(_ session: WCSession, didReceiveUserInfo userInfo: [String: Any] = [:]) { WatchWidgetSessionHandler.shared.processComplicationUserInfo(userInfo) } } IOS App code: class WatchAppDataManager: NSObject, WCSessionDelegate { override init() { super.init() let session = WCSession.default session.delegate = self session.activate() } func sendDataToWidget(for kinds: [WatchWidgetKind]) async { guard WCSession.default.activationState == .activated, WCSession.default.isComplicationEnabled else { return } let widgetsData = dataProvider.getData(for: kinds) if !widgetsData.isEmpty { WCSession.default.transferCurrentComplicationUserInfo(widgetsData) } } }
Posted
by
Post not yet marked as solved
1 Replies
299 Views
Hello, I'm researching the functionality of widgets and came across a question while reading the official documentation. According to the following link, it says, "Coordinate the corner radius of your content with the corner radius of the widget." https://developer.apple.com/design/human-interface-guidelines/widgets#Previews-and-placeholders Does this mean that the framework of the widget should have rounded corners, and it is not necessary for Views within the widget to always have rounded corners? For example, if I want to place a square image in the widget, do I need to implement it so that the image has rounded corners? If anyone knows, could you please provide some guidance? Thank you very much.
Posted
by
Post not yet marked as solved
0 Replies
465 Views
Hello, I'm working on my first app. It's also my first encounter with App Intents. I have a data structure for events that has an ID (String), a name (String), a Date and an image (Data). The user can create them in the app and they are stored with CoreData. I wanted to have a widget that would allow the user to choose from their list of events and display that event in the widget. The list should appear in the widget configuration and it would be a list of the names and (if possible) the image. I think I have found how to access the information from the widget, but I cannot figure out how to have the list appear in the configuration. I have been following this guide: https://developer.apple.com/documentation/widgetkit/making-a-configurable-widget?utm_source=pocket_saves. But that one shows hardcoded elements in the list and I haven't been able to find how to have the list change in relation to the content of the app. This is what I have made so far in the AppIntent file: import WidgetKit import AppIntents import CoreData struct EventDetail: AppEntity { static var defaultQuery: EventQuery = EventQuery() var id: String var date: Date var image: Data var title: String static var typeDisplayRepresentation: TypeDisplayRepresentation = "Event" var displayRepresentation: DisplayRepresentation { DisplayRepresentation(title: "\(id) \(title)") } } struct EventQuery: EntityQuery{ func entities(for identifiers: [EventDetail.ID]) async throws -> [EventDetail] { return fill_event_details(events_list: getEventDataIntent()) } func suggestedEntities() async throws -> [EventDetail] { fill_event_details(events_list: getEventDataIntent()).filter { $0.id != "-" } } func defaultResult() async -> EventDetail? { try? await suggestedEntities().first } } struct ConfigurationAppIntent: WidgetConfigurationIntent { static var title: LocalizedStringResource = "Select an event" static var description = IntentDescription("This is an example widget.") // An example configurable parameter. @Parameter(title: "Event") var event: EventDetail // init(events: [UserCountdowns]) { // self.event = fill_event_details(events_list: events)[0] // print("AppIntent") // print(self.event.title) // } init() { } } func fill_event_details(events_list: [UserCountdowns]) -> [EventDetail] { var entities_list: [EventDetail]? let events = getEventDataIntent() for event in events { entities_list!.append(EventDetail(id: event.id!, date: event.date!, image: event.image!, title: event.title!)) } return entities_list ?? [EventDetail(id: "-", date: Date(), image: Data(), title: "empty")] } func getEventDataIntent() -> [UserCountdowns] { let context = PersistenceController.shared.container.viewContext let request = UserCountdowns.fetchRequest() var result: [UserCountdowns]! do { result = try context.fetch(request) } catch { print(error) } return result } I have been trying a few things in the widget's code but I haven't been able to make anything work, so I don't really have anything worth sharing, I think. This is the code for the UserCountdowns structure: extension UserCountdowns { @nonobjc public class func fetchRequest() -> NSFetchRequest<UserCountdowns> { return NSFetchRequest<UserCountdowns>(entityName: "UserCountdowns") } @NSManaged public var date: Date? @NSManaged public var image: Data? @NSManaged public var title: String? @NSManaged public var id: String? } Could anyone help me with this, please? What am I missing or what would the next step be? Let me know if there is any other part of the code I should share. Thank you in advance!
Posted
by