Post not yet marked as solved
I've reached a point where I can no longer make any progress diagnosing the issues that have popped up with Apple Watch development support. To hopefully help draw attention and focus to the severity of this problem, I'm gathering all related threads into this single thread.
Summary of problems
There are several, possibly related, issues at play:
Xcode is not discovering Apple Watches. This means it's not possible to deploy apps to Apple Watches that aren't already provisioned with Xcode. I've confirmed this behavior with a watch running watchOS 10.0.
The logging profile for watchOS has expired. It's no longer possible to pull logs via Console from Apple Watches.
AppIntent-based complications on watchOS 10.5 no longer load, staying stuck in a "placeholder" state. This can be reproduced with the Backyard Birds demo app.
It's no longer possible to debug widget extensions on Apple Watch hardware.
Feedback submitted
FB13758427: No longer able to connect to Apple Watch from Xcode
I was attempting to test another regression related to AppIntents no longer working on watchOS 10.5. To confirm the behavior had regressed since earlier versions of watchOS, I set up one of my older Apple Watches that is still running watchOS 10.0.
After wiping the watch and repairing it with one of my test devices (iPhone 11 Pro, iOS 17.4.1), I’m unable to get the Apple Watch to appear in Xcode’s Devices & Simulators manager. The phone is connected via USB cable, and the phone appears as a Connected phone, but the watch does not appear. My Apple Watch Ultra that I use as my daily driver does appear as a remote device (the globe icon is next to it), but the Apple Watch 10.0 does not appear.
Details about the older watch:
Version: 10.0 21R5341c
Model: A2478
Not being able to test on other Apple Watches is severely limiting my ability to isolate and confirm the regression in AppIntent support that can be reproduced in the Backyard Birds demo app.
Note that the 10.0 watch does actually appear in the Console app, but with a warning sign next to it. The 10.0 watch also appears twice. Clicking the warning sign does not reveal any information about why the warning is appearing, but after ~5 seconds I do get the following error in Console.app: “The user has not responded to the pairing request on 'Headless’ Respond to the Trust prompt on the device.” There is no trust prompt on the device.
FB13756074: WatchOS logging profile is no longer valid
https://developer.apple.com/bug-reporting/profiles-and-logs/?platform=watchos is no longer valid. See attached error that occurs when attempting to install the profile onto my Apple Watch Ultra.
It seems that without this I’m unable to get any logs off of my Apple Watch, which is making testing/development quite difficult.
FB13758450: AppIntent-based widgets no longer render on watchOS 10.5
AppIntent-based complications no longer get beyond a placeholder state on watchOS. This can be reproduced with the Backyard Birds demo app, which uses AppIntent-based widget configurations for the watchOS complications. AppIntent-based complications did appear to work in previous versions of watchOS 10, but I’m unable to confirm this with a 10.0 Watch I have due to FB13758427.
To reproduce
deploy the attached unmodified Backyard Birds app to a watch running watchOS 10.5.
add a Backyard Birds complication to a watch face.
Expected behavior: the widget shows live data
Actual behavior: the complication never leaves a placeholder state. See the attached screenshot for the state the widget is stuck in.
FB13758490: PacketLogger no longer logs packets
PacketLogger used to log BTLE packets as they were received and transmitted on a macOS machine. Since updating to 14.5 Beta (23F5064f) however, PacketLogger no longer logs packets on macOS at all. Upon starting a new session, the interface remains empty.
PacketLogger is still able to log packets from a connected iOS device.
Related threads
Apple Watch cannot reconnect
WatchOS Sysdiagnose Profile is no longer
XCode 15 can't run on iOS 17 devices. Previous preparation error: An error occurred while communicating with a remote process.. The connection was invalidated.
Post not yet marked as solved
I'm working on an app that has the following structure:
MyApp
MyWidgetExtension
MyWatchKitApp
-- MyWatchKitAppExtension
---- MyWatchKitAppWidgetExtension
Both MyWidgetExtension and MyWatchKitAppWidgetExtension were developed using a shared MyWidgetBundle defined as follows:
@main
struct MyWidgetBundle : WidgetBundle
However, I'm running into an issue when attempting to run this on devices with iOS 14. I get an error stating "App extensions must define either NSExtensionMainStoryboard or NSExtensionPrincipalClass keys in the NSExtension dictionary in their Info.plist."
Interestingly, if I remove MyWatchKitAppWidgetExtension, the app installs just fine. But, if I add NSExtensionPrincipalClass or NSExtensionMainStoryboard, when I try to distribute the app to TestFlight, I receive an error stating "Unexpected key NSExtensionPrincipalClass found in extension Info.plist".
I'm at a loss as to how to resolve this issue. Does anyone have any suggestions or insights?
Post not yet marked as solved
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!
Xcode: Version 15.0 beta 2 (15A5161b)
iPhone: iOS 17.0 (21A5268h)
Run from Xcode to Simulator or my iPhone, build successfully, install failed with the same error:
My widget extension target info.plist file looks like the image below, and it worked find with all the previous Xcode version.
After adding the key NSExtensionPrincipalClass like this:
I can install my app to simaltor and my device, however, when archive and upload to the App Store (for TestFlight testing), i got another error (the first one is related to this issue, the second i could not figure out what it is):
Post not yet marked as solved
如何自定义开发表盘模版,不是表盘组件,比如设置背景图片,调整各个表盘组件的位置
Post not yet marked as solved
I recently raised this post explaining how I couldn't seem to get watchOS 9 complications to work, and I've figured out a partial fix.
The original post details the issues with complications - and some are still valid - but this fix applies to both my complications and Home Screen / Lock Screen widgets.
I was following the various WWDC 2020/2022 videos and the Emoji Rangers sample code, adding bits here and there, and assuming they were completely valid. Sadly, this bit of code in the widget's dynamic intents IntentTimelineProvider getTimeline really just banjaxed everything:
// Create entries for one day, 15 minutes apart
let currentDate = Date()
for minuteOffset in stride(from: 0, to: 60 * 60 * 24, by: 15) {
let entryDate = Calendar.current.date(byAdding: .minute, value: minuteOffset, to: currentDate)!
entries.append(EventEntry(date: entryDate, event: event))
}
If I remove that, and generate a different timeline with specific dates and times (for example: now, in 10 mins, in 2 hours, in a day, etc.) the complications appear correctly, as do Home Screen and Lock Screen widgets.
The outstanding issues with complications are:
The previews all use the same data, but getSnapshot() is supposed to return the data specific to that event from the configuration, i.e. if let theId = configuration.event?.identifier. "Christmas" is correct, but "Gallery Opening" is using Christmas's data.
Once I've selected the event I want to use in a complication the edit screen shows it as totally blank, not even a placeholder:
I hope this little fix works for you guys. And, if you know how to fix the above issues, let me know.
(iOS 16.1 beta 1, Xcode 14.1 beta 1)
Post not yet marked as solved
My app has two static widgets. In the widget extension, I have the following code:
import WidgetKit
import SwiftUI
import ItemWidgetsKit
@main
struct ItemWidgetsBundle: WidgetBundle {
var body: some Widget {
RecentSavesWidget()
RecommendationsWidget()
}
}
the rest of the code, including the two Widget implementations, the TimelineProvider, etc, are in the imported ItemsWidgetKit, which is a library inside a Swift Package containing several libraries.
These two widgets work as expected.
Now I am adding a configurable widget, and the code above changes like so:
import WidgetKit
import SwiftUI
import ItemWidgetsKit
@main
struct ItemWidgetsBundle: WidgetBundle {
@WidgetBundleBuilder var body: some Widget {
makeWidgets()
}
func makeWidgets() -> some Widget {
if #available(iOS 17.0, *) {
return WidgetBundleBuilder.buildBlock(RecentSavesWidget(), TopicRecommendationsWidget())
} else {
return WidgetBundleBuilder.buildBlock(RecentSavesWidget(), RecommendationsWidget())
}
}
}
TopicRecommendationsWidget is similar to RecommendationsWidget except that it lets you choose a topic to display recommendations for, by long pressing and selecting an intent.
I followed the same approach of the other two widgets, and put the code inside ItemWidgetsKit
This time, though, the widget does not work, and it only loads the placeholder; in fact, in the AppIntentTimelineProvider implementation (see below) only placeholder(in:) gets ever called
@available(iOS 17.0, *)
public struct TopicTimelineProvider: AppIntentTimelineProvider {
public func placeholder(in context: Context) -> TopicEntry {
return TopicEntry(date: Date(), content: TopicContent.sampleContent)
}
public func snapshot(for configuration: TopicIntent, in context: Context) async -> TopicEntry {
return TopicEntry(date: Date(), content: configuration.topicEntity.topic)
}
public func timeline(for configuration: TopicIntent, in context: Context) async -> Timeline<TopicEntry> {
let entry = TopicEntry(date: Date(), content: configuration.topicEntity.topic)
return Timeline(entries: [entry], policy: .never)
}
}
for more context, here's the code for the configurable Widget implementation (that resides inside ItemWidgetsKit
@available(iOS 17.0, *)
public struct TopicRecommendationsWidget: Widget {
let kind: String
public init() {
self.kind = WidgetKind.topicRecommendations // a string stored elsewhere
}
public var body: some WidgetConfiguration {
AppIntentConfiguration(kind: kind, intent: TopicIntent.self, provider: TopicTimelineProvider()) { entry in
TopicWidgetContainerView(entry: entry)
}
.configurationDisplayName("New Recommendations")
.description("Select a Topic")
.supportedFamilies([.systemMedium, .systemLarge])
}
}
Any Idea why this happens and what would be the solution to this problem?
Thank you
Post not yet marked as solved
TLDR; Can I have a widget without a Timeline?
My previous watch app had a complication. Simply so it can be added to the watch face for a quick launch of the app. However now seeing that method is deprecated in favour of widgets. Can I add a widget without the need for all the Timeline as all I want is a button on the watch face to launch into my app. No data is updated over time so no need for all the extra timeline code.
Post not yet marked as solved
Before iOS 16.1 my app was woking good, if the user set the app language to other language than his device language, my app, widget + extensions all use this language...
After iOS 16.1 if user set the app language to other language than his device language, my app works with this language but the widget + extensions works with the device language, not my app language...
For Example:
@Environment(\.locale.languageCode) private var userLocal
before iOS 16.1 userLocal would be the app local, after iOS 16.1 it return the device local
Any idea why Apple did that? is this a bug?
How to set the widget language to match my app language now? even set .environment(\.locale, dose not work when use Strings(table: because it's still get the bundle that match device language.
Post not yet marked as solved
I'm building complications using WidgetKit and SwiftUI. The complications work, but the previews don't appear right away when applying the .watchface.
How can I ensure the complication previews show up immediately when a user adds the watch face?
Any guidance is appreciated.
Post not yet marked as solved
My background audio app stops updating its Live Activity after the iPhone locks, and doesn't resume updating the activity after tapping the screen or even after FaceID unlocks the device (without opening the lock screen).
My live activity requests a ContentState update & iOS updates the content for the activity as below:
Task{
log.debug("LiveActivityManager.updateLiveActivity() with new ContentState")
await liveActivity.update( ActivityContent(state:contentState, staleDate:nil) )
}
Below what my log looks like:
<<<<SWIPE LOCK SCREEN DOWN>>>>
DEBUG: LiveActivityManager.updateLiveActivity() with new ContentState
iOS: Updating content for activity 0A519263-1E46-4BB6-BA4F-F3DDBC081AB4
DEBUG: LiveActivityManager.updateLiveActivity() with new ContentState
iOS: Updating content for activity 0A519263-1E46-4BB6-BA4F-F3DDBC081AB4
<<<<PRESS LOCK BUTTON->Lock iPhone>>>>
INFO: --------protectedDataWillBecomeUnavailableNotification--------
DEBUG: LiveActivityManager.updateLiveActivity() with new ContentState
iOS: Updating content for activity 0A519263-1E46-4BB6-BA4F-F3DDBC081AB4
DEBUG: LiveActivityManager.updateLiveActivity() with new ContentState
DEBUG: LiveActivityManager.updateLiveActivity() with new ContentState
DEBUG: LiveActivityManager.updateLiveActivity() with new ContentState
<<<<LOOK AT & TAP LOCK SCREEN->Unlock iPhone without swiping up>>>>
INFO: --------protectedDataDidBecomeAvailableNotification-----------
DEBUG: LiveActivityManager.updateLiveActivity() with new ContentState
DEBUG: LiveActivityManager.updateLiveActivity() with new ContentState
DEBUG: LiveActivityManager.updateLiveActivity() with new ContentState
As shown in the log, normally iOS updates the content for my activity after my liveActivity.update request.
This works fine in the Dynamic Island and when after switching apps and swiping down to see the lock screen without locking the phone.
However, once I lock the phone, iOS stops updating the Live Activity content, and doesn't resume updates until after the app regains the foreground at least once.
Has anyone else encountered this behavior? Is this a setting that I'm missing, or a bug?
Post not yet marked as solved
I'll preface this to say that I'm not 100% sure this is all accurate, but I wanted to share this problem I was seeing developing a widget for a SwiftUI app in case it helps someone else get to a solution faster.
Two weeks ago I released a version of an app which contained a brand new widget. For the kind property of the widget's configuration I just used something generic: AppWidget.
Last week we wanted to add an additional widget into the app and I realized that I ought to make the kind be a little more specific. So I renamed the first kind from AppWidget to DailyPromptWidget ... and made the second widget use a kind named DailyCheckInWidget.
Then, we started seeing issues where the widget wasn't responding to taps and would eventually go blank. I could add in a new widget to the home screen and that'd work fine. Searching the Internet for ideas yielded nothing.
I connected my iPhone to my Mac and launched the Console app and then started tapping on the non-responsive widget. I discovered a few output messages like this:
Timeline[my.bundle.id::my.bundle.id.widgetid:AppWidget:systemMedium::338.00/158.00/21.60:(null)]--CD0C49416486::0xc46382000) Unable to create CHUISWidgetLaunchRequest without a effectiveContainerBundleIdentifier
I was able to reproduce the issue by renaming the bundle ID of the widget (and leaving the working widget on the home screen). Tapping it gave the same exact error.
Another error, which clued me in more:
Content load failed: unable to find or unarchive file for key: [my.bundle.id.widgetid:AppWidget:systemMedium::338.00/158.00/21.60:(null)] on no host. The session may still produce one shortly. Error: Using url `file:///private/var/mobile/Containers/Data/PluginKitPlugin/012DB9D2-07F7-4383-9CCE-B040652B7999/SystemData/com.apple.chrono/placeholders/AppWidget/systemMedium----338.00w--158.00h--21.60r--0f--0.00t-0.00l-0.00b0.00t.chrono-timeline` ... Error Domain=NSCocoaErrorDomain Code=4 "The file "systemMedium----338.00w--158.00h--21.60r--0f--0.00t-0.00l-0.00b0.00t.chrono-timeline" doesn't exist." UserInfo={NSFilePath=/private/var/mobile/Containers/Data/PluginKitPlugin/012DB9D2-07F7-4383-9CCE-B040652B7999/SystemData/com.apple.chrono/placeholders/AppWidget/systemMedium----338.00w--158.00h--21.60r--0f--0.00t-0.00l-0.00b0.00t.chrono-timeline, NSUnderlyingError=0x3025a1d10 {Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"}}
So, I tried finding those files in the simulator data on my Mac. Inside the placeholders/ directory are directories with the names of all the widget kind I had used (the old and the new). Inside those named kind directories are, what look to be, files representing each timeline entry.
It appears that if you change the kind string in your widget's configuration, the widget you've added to your home screen does not get updated and will continue looking for the old timeline entry files in the original kind directory.
The solution? Either don't rename the kind once you've released it on the App Store, or instruct customers to remove the widget and add it back after they've installed your app update.
It'd be nice if an app update would also update the kind directory name.
Post not yet marked as solved
How can I implement a feature in my iOS and watchOS app to prompt users to download it when they try to apply a custom watch face shared from my app, as shown in the example image? We're using WidgetKit for Complications.
Post not yet marked as solved
iOS app with Home Screen and Lock Screen widgets written in Swift/SwiftUI. I've never been able to get widgets to work properly. It's more pronounced on Lock Screen widgets, so let's try that method first...
The app stores data in Core Data as an Event. They're read into my model and stored as WidgetEventDetails structs:
struct WidgetEventDetails: AppEntity, Identifiable, Hashable {
public var eventId: String
public var name: String
public var date: Date
public var id: String {
eventId
}
This all works absolutely fine in the iOS app, and each one is unique based on the eventId.
When I go to add a Lock Screen widget, I customise the Lock Screen, tap in the section to add a widget, and my widgets appear correctly and are selectable: (bottom right, says "1y 28w 1d")
So, I tap it and it appears in the widgets section:
But it appears as "17w 6d", which is a different event entirely. Notice how the one in the selectable widgets has changed to "15w 5d", and the one I tapped (1y 28w 1d) is nowhere to be seen.
So, I tap the one in the top row (17w 6d) to select an event, and this appears, suggesting that the event is the "Edinburgh & Glasgow 2024-02" event:
But that event is actually only a day away (1d), so that's not the one I selected at all.
I tap the list and see these events:
I select "Las Vegas 2024", which is 17w 3d away, and this is shown:
17w 6d is a different event, not Las Vegas 2024.
So, I tap it again and see this. The "Loading" text appears for ages, but occasionally does show the full list, as before:
I select "Edinburgh & Glasgow 2024-02" which is 1d away, and I see this again:
So, I resign myself to hoping it'll just figure itself out, and I tap "Done":
"17w 6d" again :(
I finish customising, and exit the customisation screen. I show the Lock Screen, and I see this:
Why doesn't this work?
Here's the code:
@main
struct WidgetExtensionBundle: WidgetBundle {
@WidgetBundleBuilder
var body: some Widget {
WidgetExtension()
}
}
struct WidgetExtension: Widget {
var body: some WidgetConfiguration {
AppIntentConfiguration(kind: kWidgetKind, intent: WidgetEventIntent.self, provider: WidgetEventTimelineProvider()) { entry in
WidgetEntry(entry: entry)
.environment(modelData)
}
.configurationDisplayName(NSLocalizedString("AddingWidget_Title", comment: "Adding the Widget"))
.description(NSLocalizedString("AddingWidget_Description", comment: "Adding the Widget"))
.supportedFamilies([.accessoryCircular, .accessoryInline, .accessoryRectangular, .systemSmall, .systemMedium])
.contentMarginsDisabled()
}
}
struct WidgetEventIntent: WidgetConfigurationIntent {
static let title: LocalizedStringResource = "AddingWidget_Title"
static let description = IntentDescription(LocalizedStringResource("AddingWidget_Description"))
@Parameter(title: LocalizedStringResource("Event"))
var event: WidgetEventDetails?
init(event: WidgetEventDetails? = nil) {
self.event = event
}
init() {}
static var parameterSummary: some ParameterSummary {
Summary {
\.$event
}
}
}
struct EventQuery: EntityQuery, Sendable {
func entities(for identifiers: [WidgetEventDetails.ID]) async throws -> [WidgetEventDetails] {
modelData.availableEvents.filter { identifiers.contains($0.id) } // availableEvents is just [WidgetEventDetails]
}
func suggestedEntities() async throws -> [WidgetEventDetails] {
return modelData.availableEvents.filter { $0.type == kEventTypeStandard }
}
}
If you think it's the TimelineProvider causing it, I can provide that code, too.
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
We use a local swift package in 6 of our app extensions. The product from the local package that we link to each app extension is a dynamic framework. And while the dynamic framework is copied into the final app bundle once, the resource bundles of each target that comprise the dynamic framework is copied into each app extension. I'd much rather have the bundles be copied into the dynamic framework once to prevent app bloat.
Here is a visualization of the issue:
.
└── MyApp.ipa/
├── MyApp (executable)
├── MyDynamicFramework_TargetA.bundle
├── MyDynamicFramework_TargetB.bundle
├── MyDynamicFramework_TargetC.bundle
├── Frameworks/
│ └── MyDynamicFramework.framework/
│ ├── TargetA
│ ├── TargetB
│ └── TargetC
└── PlugIns/
├── Widgets.appex/
│ ├── MyDynamicFramework_TargetA.bundle
│ ├── MyDynamicFramework_TargetB.bundle
│ └── MyDynamicFramework_TargetC.bundle
├── Intents.appex/
│ ├── MyDynamicFramework_TargetA.bundle
│ ├── MyDynamicFramework_TargetB.bundle
│ └── MyDynamicFramework_TargetC.bundle
├── IntentsUI.appex/
│ ├── MyDynamicFramework_TargetA.bundle
│ ├── MyDynamicFramework_TargetB.bundle
│ └── MyDynamicFramework_TargetC.bundle
├── NotificationContent.appex/
│ ├── MyDynamicFramework_TargetA.bundle
│ ├── MyDynamicFramework_TargetB.bundle
│ └── MyDynamicFramework_TargetC.bundle
├── RichPushContent.appex/
│ ├── MyDynamicFramework_TargetA.bundle
│ ├── MyDynamicFramework_TargetB.bundle
│ └── MyDynamicFramework_TargetC.bundle
└── NotificationService.appex/
├── MyDynamicFramework_TargetA.bundle
├── MyDynamicFramework_TargetB.bundle
└── MyDynamicFramework_TargetC.bundle
Notice that the resource bundles of Target A, B, and C are copied multiple times causing an unhealthy app size.
I'd either like the resource bundles to be copied into MyDynamicFramework or copied once into the app bundle and let the app extensions reference them.
Given the SPM + Xcode linking is a black box for the most part, how would I accomplish this?
Post not yet marked as solved
iPhone 16.0 16.0.2 系统上运行小组件出现问题, 其他系统没有问题
SendProcessControlEvent:toPid: encountered an error: Error Domain=com.apple.dt.deviceprocesscontrolservice Code=8 "Failed to show Widget 'com.jiduauto.iphone.jdcomiphoneWidget' error: Error Domain=FBSOpenApplicationServiceErrorDomain Code=5 "The request to open "com.apple.springboard" failed." UserInfo={NSLocalizedDescription=The request to open "com.apple.springboard" failed., NSLocalizedFailureReason=Unexpected error type., NSUnderlyingError=0x600002bbd7a0 {Error Domain=BSServiceConnectionErrorDomain Code=3 "XPC error received on message reply handler" UserInfo={BSErrorCodeDescription=OperationFailed, NSLocalizedFailureReason=XPC error received on message reply handler}}, BSErrorCodeDescription=InvalidResponse}." UserInfo={NSLocalizedDescription=Failed to show Widget 'com.jiduauto.iphone.jdcomiphoneWidget' error: Error Domain=FBSOpenApplicationServiceErrorDomain Code=5 "The request to open "com.apple.springboard" failed." UserInfo={NSLocalizedDescription=The request to open "com.apple.springboard" failed., NSLocalizedFailureReason=Unexpected error type., NSUnderlyingError=0x600002bbd7a0 {Error Domain=BSServiceConnectionErrorDomain Code=3 "XPC error received on message reply handler" UserInfo={BSErrorCodeDescription=OperationFailed, NSLocalizedFailureReason=XPC error received on message reply handler}}, BSErrorCodeDescription=InvalidResponse}., NSUnderlyingError=0x600002bbd5f0 {Error Domain=FBSOpenApplicationServiceErrorDomain Code=5 "The request to open "com.apple.springboard" failed." UserInfo={NSLocalizedDescription=The request to open "com.apple.springboard" failed., NSLocalizedFailureReason=Unexpected error type., NSUnderlyingError=0x600002bbd7a0 {Error Domain=BSServiceConnectionErrorDomain Code=3 "XPC error received on message reply handler" UserInfo={BSErrorCodeDescription=OperationFailed, NSLocalizedFailureReason=XPC error received on message reply handler}}, BSErrorCodeDescription=InvalidResponse}}}
Domain: DTXMessage
Code: 1
User Info: {
DVTErrorCreationDateKey = "2024-02-19 08:02:14 +0000";
}
System Information
macOS Version 13.5.2 (Build 22G91)
Xcode 15.0 (22265) (Build 15A240d)
Timestamp: 2024-02-19T16:02:14+08:00
Post not yet marked as solved
I'm stuck fetching location inside iOS app's widget extension running on MacOS.
locationManager.authorizationStatus == .notDetermined always returns true, meanwhile main app, running on MacOS has permission for location in MacOS system settings and doesn't have any problems with using geodata.
Is it possible to fetch a location inside of iOS app's widget extension running on MacOS and if yes, what could I be doing wrong?
Post marked as Apple Recommended
Hi guys,
I am migrating my widgets to iOS 17 and because I already manage my layout margins, I just want to disable to new built-in widget content margins.
I did it by using ".contentMarginsDisabled()" on the WidgetConfiguration and it works fine at run time.
WIDGET CODE
struct MyWidget: Widget {
let kind: String = "MyWidget"
var body: some WidgetConfiguration {
return IntentConfiguration(kind: kind, intent: MyWidgetIntent.self, provider: WidgetProvider<MyWidgetIntent>()) { entry in
WidgetView<MyWidgetIntent>(entry: entry)
}
.configurationDisplayName("My Widget")
.supportedFamilies([WidgetFamily.systemMedium])
.contentMarginsDisabled() // <-- HERE
}
}
RESULT
Nevertheless, when previewing the WidgetView in a WidgetPreviewContext I didn't find anyway to disable the content margins (because manipulating directly the view and not a WidgetConfiguration).
PREVIEW CODE
struct MyWidget_Previews: PreviewProvider {
static var previews: some View {
WidgetView<MyWidgetIntent>(entry: WidgetEntry<MyWidgetIntent>())
// .padding(-16) Need to add this negative padding to disable margin
.previewContext(
WidgetPreviewContext(family: .systemMedium))
}
}
Do you know how to disable the content margins for widget preview?
Post not yet marked as solved
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)
}
}
}