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

How to trigger music playback in Widget
Hello, I have a music player application that uses MPMusicPlayerController to play Apple Music songs. Now I want to add a Widget to it that can trigger playback pause on iOS 17. How do I need to achieve this? I can get the playbackStoreID of the song on the Widget Extension and use MPMusicPlayerController setQueue(with:) to play it. How do I pass the playbackStoreID in the Widget to the main application for playback, or should I create a new MPMusicPlayerController on the Widget Extension for playback?
1
0
691
Oct ’23
WidgetConfigurationIntent @Parameter can't get value, when restart iphone.
struct ConfigurationAppIntent: WidgetConfigurationIntent { static var title: LocalizedStringResource = "Configuration" static var description = IntentDescription("Choose Server") @Parameter(title: "Server") var server :Server? } struct Provider: AppIntentTimelineProvider { func timeline(for configuration: ConfigurationAppIntent, in context: Context) async -> Timeline<WidgetServerEntry> { // when restart iphone , configuration all setting is lost. } } when restart iphone , configuration all setting is lost. but long tap widget and go to select param view, the value is still on last selected option.
1
0
288
Oct ’23
Unable to launch + Attach to Mac Widget (Sonoma + Xcode 15)
Attempting to launch a widget in Debug mode on Sonoma from Xcode 15 is failing with the following message: attach failed (Not allowed to attach to process. Look in the console messages (Console.app), near the debugserver entries, when the attach failed. The subsystem that denied the attach permission will likely have logged an informative message about why it was denied.) Looking in console I see this message: macOSTaskPolicy: (com.apple.debugserver) may not get the task control port of (MacGalleryWidget) (pid: 1851): (MacGalleryWidget) is hardened, (MacGalleryWidget) doesn't have get-task-allow, (com.apple.debugserver) is a declared debugger(com.apple.debugserver) is not a declared read-only debugger What Xcode settings should I be looking at to rectify this? I suspect I may have something that's out of whack.
0
3
698
Sep ’23
WidgetKit extenstion
Hi, I'm trying to create a macOS widget for my application. I'm following the official Apple documentation. When trying to run the widget, I get the following error: The operation could not be completed. (CHSErrorDomain error 1103.) Is there a list somewhere that explains the error codes? I thought we were past error codes in modern software development...
8
2
1.2k
Jun ’24
Error when running Live Activities
Hi there, This is my first time posting here. I'm working on small projects on Swift and SwiftUI now and then. I'm currently trying to develop an application that gets some bus arrival data using API and displaying them with live activities. The thing is that I'm not quite sure how frequently updates work yet. Still trying to figure out if I can update the live activity everytime the data coming right from the API changes or use push notification updates each minute passing by, but that is another thread that I'm going to focus with more details. Everytime i'm trying to deploy my app on my iphone or a simulator this error keeps popping up and I can't figure out why. Any ideas? Let me know if you need any snippet of my code. SendProcessControlEvent:toPid: encountered an error: Error Domain=com.apple.dt.deviceprocesscontrolservice Code=8 "Failed to show Widget 'com.gregorikouk.MapKitTut.BusWidgetKit' error: Error Domain=FBSOpenApplicationServiceErrorDomain Code=1 "The request to open "com.apple.springboard" failed." UserInfo={NSLocalizedFailureReason=The request was denied by service delegate (SBMainWorkspace)., BSErrorCodeDescription=RequestDenied, NSUnderlyingError=0xb1282dfe0 {Error Domain=SBAvocadoDebuggingControllerErrorDomain Code=1 "Failed to get descriptors for extensionBundleID (com.gregorikouk.MapKitTut.BusWidgetKit)" UserInfo={NSLocalizedDescription=Failed to get descriptors for extensionBundleID (com.gregorikouk.MapKitTut.BusWidgetKit)}}, FBSOpenApplicationRequestID=0xe5da, NSLocalizedDescription=The request to open "com.apple.springboard" failed.}." UserInfo={NSLocalizedDescription=Failed to show Widget 'com.gregorikouk.MapKitTut.BusWidgetKit' error: Error Domain=FBSOpenApplicationServiceErrorDomain Code=1 "The request to open "com.apple.springboard" failed." UserInfo={NSLocalizedFailureReason=The request was denied by service delegate (SBMainWorkspace)., BSErrorCodeDescription=RequestDenied, NSUnderlyingError=0xb1282dfe0 {Error Domain=SBAvocadoDebuggingControllerErrorDomain Code=1 "Failed to get descriptors for extensionBundleID (com.gregorikouk.MapKitTut.BusWidgetKit)" UserInfo={NSLocalizedDescription=Failed to get descriptors for extensionBundleID (com.gregorikouk.MapKitTut.BusWidgetKit)}}, FBSOpenApplicationRequestID=0xe5da, NSLocalizedDescription=The request to open "com.apple.springboard" failed.}., NSUnderlyingError=0xb1281d830 {Error Domain=FBSOpenApplicationServiceErrorDomain Code=1 "The request to open "com.apple.springboard" failed." UserInfo={NSLocalizedFailureReason=The request was denied by service delegate (SBMainWorkspace)., BSErrorCodeDescription=RequestDenied, NSUnderlyingError=0xb1282dfe0 {Error Domain=SBAvocadoDebuggingControllerErrorDomain Code=1 "Failed to get descriptors for extensionBundleID (com.gregorikouk.MapKitTut.BusWidgetKit)" UserInfo={NSLocalizedDescription=Failed to get descriptors for extensionBundleID (com.gregorikouk.MapKitTut.BusWidgetKit)}}, FBSOpenApplicationRequestID=0xe5da, NSLocalizedDescription=The request to open "com.apple.springboard" failed.}}} Domain: DTXMessage Code: 1 User Info: { DVTErrorCreationDateKey = "2023-10-02 21:06:04 +0000"; } -- System Information macOS Version 14.0 (Build 23A344) Xcode 15.0 (22265) (Build 15A240d) Timestamp: 2023-10-03T00:06:04+03:00
3
0
1.2k
Oct ’23
Core Data: Merging relevant changes between extensions and iCloud devices
I am working on an interactive widget and merging changes provided by a user over it with the app. I store my data, using Core Data. However, I noticed an issue with sync between other user's devices after that person made a change over the widget (in my case, it is completing a task). Here is my schema: Main app: it looks for relevant transactions (https://developer.apple.com/documentation/coredata/consuming_relevant_store_changes). When it found that one, the app merges changes: if transaction.author == "widget" { if let userInfo = transaction.objectIDNotification().userInfo { NSManagedObjectContext.mergeChanges(fromRemoteContextSave: userInfo, into: [taskContext]) } } Widget: If the user clicks on the checkbox in order to complete a task, using an AppIntent class, app creates an identical NSPersistentCloudKitContainer and completes the task. However, in that case, the NSPersistentCloudKitContainer of the widget does not look for changes. That works correctly. However, only in a local environment. Here's why: If I complete a task (using a widget) and launch the app on the same device, the change will be synced correctly. If I complete a task (using a widget) (on device A) and launch the app on another device (on device B), the change will not be applied (on device B), until I open the app on the device that I made the change on (on device A). If I open the app on device B after I opened it on device A (and the changed has been applied), on device A I get a remote notification with the author value = 'NSCloudKitMirroringDelegate.import', not 'widget'. The point of my issue is that the remote notifications about changes made, using widgets, does not arrive to other devices like notifications initialised by the main app. Thank you in advance!
1
1
578
Nov ’23
WidgetConfiguration with AppEnum and When clausole on AppIntent
Hi there, I'm trying to use an enum as a @Parameter for my Widget configuration: enum InteractivePlacesWidgetMode: Int, CaseIterable, AppEnum, Comparable, Equatable { typealias RawValue = Int case favourites = 0, recents, nearbyCategory, collections static var typeDisplayRepresentation: TypeDisplayRepresentation = TypeDisplayRepresentation(name: LocalizedStringResource("Mode")) static var caseDisplayRepresentations: [InteractivePlacesWidgetMode: DisplayRepresentation] = [ .favourites: DisplayRepresentation(title: LocalizedStringResource("Favorites")), .recents: DisplayRepresentation(title: LocalizedStringResource("Recents")), .nearbyCategory: DisplayRepresentation(title: LocalizedStringResource("Categories")), .collections: DisplayRepresentation(title: LocalizedStringResource("Collections")) ] static func < (lhs: InteractivePlacesWidgetMode, rhs: InteractivePlacesWidgetMode) -> Bool { lhs.rawValue < rhs.rawValue } static func == (lhs: InteractivePlacesWidgetMode, rhs: InteractivePlacesWidgetMode) -> Bool { lhs.rawValue == rhs.rawValue } } Then on the ConfigurationAppIntent I would like to show some more option only for specific cases, with the following: struct ConfigurationAppIntent: WidgetConfigurationIntent { static var title: LocalizedStringResource = "Configuration" static var description = IntentDescription("Choose what to show") @Parameter(title: LocalizedStringResource("Show"), default: .favourites) var widgetMode: InteractivePlacesWidgetMode @Parameter (title: "Category") var category: CategoryDetail? static var parameterSummary: some ParameterSummary { When(\.$widgetMode, .equalTo, .nearbyCategory) { Summary { \.$widgetMode \.$category } } otherwise: { Summary { \.$widgetMode } } } } But the widget seems to ignore the When clausole at all. Is this a limitation of the When clausole? Is there something wrong with my approach? I already used that with standard types in previous work and it seems to work quite well. Thanks in advance for your help. c.
1
0
607
Oct ’23
Complication created with WidgetKit not showing on watch face
I have a watch extension app that is used to show the complications using ClockKit. Then when we upgraded to watch OS 9, I added the WidgetKit Extension and all migration code for clockKit as well. Everything was working fine in Watch OS 9 But now when we upgraded to watch OS 10. The widgetKit based complication not at all running, I can't even see any of our complication in watch face On top of that the WidgetKit extension is not showing any debug information as well, none of the break points are executed Please let me know if anyone knows the issue
0
1
440
Oct ’23
App structure for iOS app, widgets, watchOS app & complications?
I've had to rewrite my app to get widgets working properly, and I've got this project structure: Main iOS app: Bundle identifier = com.me.myapp Contains: Widget Extension: Bundle identifier = com.me.myapp.widgets Targets iOS 17 Provides widgets to iOS Watch app: Bundle identifier = com.me.myapp.watchapp Contains: Complications Extension (a Widget Extension): Bundle identifier = com.me.myapp.watchapp.complications Targets watchOS 10 Provides widgets to watchOS On the Signing & Capabilities tab in Xcode 15, all four targets have: Provisioning Profile: Xcode Managed Profile Signing Certificate: Apple Development: My team App Groups: all use the same one: group.com.me.myapp I can build and deploy to a physical iPhone and Apple Watch, but the Watch app doesn't seem to be able to access the shared Core Data, which should be in the shared app group container. When running the main iOS app, the store location is: file:///private/var/mobile/Containers/Shared/AppGroup/189E5907-E6E4-4790-833F-06944E4FF5FF/data-model/TheDataModel When running the widget extension, the store location is: file:///private/var/mobile/Containers/Shared/AppGroup/189E5907-E6E4-4790-833F-06944E4FF5FF/data-model/TheDataModel When I run the Watch app, the store location is different: file:///private/var/mobile/Containers/Shared/AppGroup/55381E6D-410E-4322-93BA-64BD1933909E/data-model/TheDataModel How do I get the Watch app to see the Core Data store from the main app? Do I have to replicate the store to that location every time something changes in the main app? Or do I have to go back to sending massive data sets as dictionaries/data via WatchConnectivity?
1
0
956
Oct ’23
PLEASE - how do you structure an app with Widgets and Complications?
Current project structure: Main iOS app (targets iOS 17). Widget Extension (targets iOS 17). Watch app (targets watchOS 10). Complications Extension (a Widget Extension, targets watchOS 10). I did have the complications embedded within the Watch app, but you cannot have two @mains in the same target so the complications are in their own WidgetKit extension. Sadly, when you add a WidgetKit extension to your project, Xcode ALWAYS sets it as an iOS widget extension; it doesn't give you the choice to make it a watchOS extension so you have to figure it out yourself. Now, I'm hitting an issue where the main iOS app works fine, the iOS widgets work fine, the Watch app runs fine, but the complications dot show up anywhere. I can't preview them in Xcode because it says various things like: This app was not built to support this device family; app is compatible with ( 1,2 ) but this device supports ( 4 } I can't find any information on what goes where in the build settings. Can someone tell me how each bit of the project should look in the build settings, please? (There's no information anywhere in Apple's developer documentation - which is a bit weird. They've released Xcode and they have no information on the various bits. And why doesn't Xcode set up a WidgetKit extension properly when you add it? Must we all do this manually, Apple?)
2
0
976
Oct ’23
Interactive widgets should prevent repeated triggering of AppIntent
Hello everyone! I've found that on the current iOS 17.0/17.1, the Button with an AppIntent within a widget can be tapped at a high frequency. Even if the AppIntent triggered by the first tap has not finished executing, the user can still trigger the AppIntent again. This can lead to repeated or accidental operations by the user. Since there is already an invalidatableContent() API, I think the system should know when an AppIntent has not finished executing. I suggest that in this state, the system should not accept repeated taps from the user. This way, the behavior and appearance of the button would be consistent.
1
0
576
Oct ’23
Pulling my hair out with Widgets
Here's my WidgetConfigurationIntent: WidgetEventDetails is a struct conforming to AppEntity, Identifiable, Hashable. It contains all the data needed to show in a widget. Here's my placeholder, snapshot, timeline etc.: When I go to add a widget to my iPhone Home Screen I choose my app, and the small and medium widgets are displayed, and they use the data from the placeholder function correctly, i.e. a random set of data (an 'event') is returned and seen in the widget picker. I select a widget and it appears on the Home Screen, but it's now just a placeholder view, and it stays like that forever. If I hold down and edit the widget, there's no selected event, as in, I might've picked "Christmas" from the widget picker but when it gets added to the Home Screen that link is lost. So, I edit the widget and go to choose any event, and this appears for ages: When it finally displays the list of events I pick one and the widget looks this forever: I can't see what I'm doing wrong. Any ideas? If you need any more of the code, please just ask. I'm getting really frustrated with this stuff and just want it to work. I get so far with it, it all goes well, then something happens and it just breaks. And it's not my coding as I'm using git and can can go back to previous commits where stuff was working, only to find it doesn't. I'm glad iOS 17 now has this "State of Mind" logging 'cos it shows exactly how I feel developing for iOS! 🥸
2
0
674
Oct ’23
Dynamic Island lifecycle
I am implementing the live activity in my project, it is a timer live activity so I have to dismiss it after the time ends for the particular activity. so for that, I'm doing it like this : Task { await activity.end(dismissalPolicy: .after(Date().addingTimeInterval(TimeInterval(1 * time)))) } it is working fine for live activity but when I'm calling this method while creating the live activity my dynamic island is not visible. am I doing something wrong here or missing out something.
0
0
311
Oct ’23
Apple Watch watchOS10 still displays sensitive information when not being worn
Prior to watchOS10, I marked a view that I want to hide sensitive information when not being worn by using .privacySensitive() This had been working just fine. Comes watchOS10, this doesn't work anymore. Even with this simple code Text("TEST Privacy") .containerBackground(for: .widget) { Color.black } .privacySensitive() The text view is displayed even when not being worn. Has anyone experienced this? It seems like a bug to me. Any workaround? Thank you.
0
1
594
Oct ’23
Padding Issue in SwiftUI Widgets
I'm currently working on a SwiftUI widget and have run into an unexpected issue. The image displays as expected (and worked correctly on iOS16), however on iOS17 I have unwanted padding on the left and right of my background image and can't figure out the cause. The padding appears even though I haven't explicitly added any to the design. This behaviour exists even if I have a solid coloured background. It's as though the ZStack doesn't fill the entire widget of the widget space. Here's a snippet of the code I'm working with: case .systemMedium: ZStack { Image(uiImage: entry.tripImg ?? UIImage()) .resizable() .scaledToFill() Text("BG image should fill") } .frame(maxWidth: .infinity, maxHeight: .infinity) I've tried various solutions to remove the padding, but nothing seems to work. I'm not sure if it's a default SwiftUI behavior or if I've missed something in my code. Has anyone else encountered this issue with SwiftUI widgets? I'd appreciate any insights or advice on how to resolve this. Thank you in advance!
2
0
1.7k
Oct ’23
Widget AppIntent updates SwiftData container, but App UI does not refresh
I'm using the new interactive widgets to trigger an app intent (tap a widget button, swift data model updates). If I tap the widget while the app is not running, then launch the app, the views (populated by an @Query) will show the correct data. However, if the app is running before tapping the widget button, the app's @Query will not refresh and so the app shows stale data. If I quit the app and relaunch it, or otherwise trigger a refresh of the query, then the view will update. Does anyone have a way to get the app to notice when an App Intent has changed Swift Data values outside of the main app? edit: Reported as FB13278891
3
4
1.3k
Oct ’23
WatchWidget does not define either an NSExtensionMainStoryboard or NSExtensionPrincipalClass - because it can't!
Ok, weird one here. I have a widgetkit watch extension that I'm transitioning to. All code compiles clean, but when I go to install I get an error that it can't be installed on the watch because the extension does not define either a NSExtensionMainStoryboard or an NSExtensionPrincipalClass key. I don't have a storyboard for the extension as it's for the complications, so I added a principal class key. Now it won't install with the error that it defines a principal class which is not allowed for the extension point com.apple.widgetkit-extension. Huh. Well, ok, um... I guess I'll rip it out and stay with the deprecated clock kit complications, since they at least install. But this is very frustrating, and makes me think Apple wants us to go insane!
2
1
419
May ’24