We are working on a WatchKit app that streams heart rate data to a companion iOS app. This works very well with WCSession, however, when the WatchKit app sleeps, the data does not continue to stream. The only way to get the data to stream again is by moving/touching the Apple Watch and waking it up again. We tried implementing a WKExtendedRuntimeSession, but we were unable to send data with this session. Is there a way to have data to continue to stream continuously, even if the watchkit app falls asleep?
WatchOS: 8.8.1
iOS: 17.0
XCode: 15.0.1
WatchKit
RSS for tagBuild apps that leverage watchOS features like background tasks, extended runtime sessions, and access to the Digital Crown using WatchKit.
Posts under WatchKit tag
132 Posts
Sort by:
Post
Replies
Boosts
Views
Activity
Apple Watch Ultra 2, watchOS 10.2
I'm trying to recognize a finger double-tap gesture in watchOS 10.2 on an Apple Watch Ultra 2 or Apple Watch 9. Apple indicates watchOS will invoke primary watch button of app, but I don't know how to specify button as primary. I've written two small watchOS 10.2 SwiftUI apps to demonstrate the problem. Does anyone see what I'm missing, or can point me to relevant docs?
APP #1 - simple one-button tap app. Touching button works, but double tap finger gesture seems recognized by watchOS as blue finger icon appears on top of watch display, shaking back and forth indicating it doesn't know what to do, but doesn't invoke Say Hello button.
import SwiftUI
struct ContentView: View {
// Controls whether You did it message is shown
@State private var showingSuccessMessage = false
var body: some View {
VStack {
Button("Say Hello") {
// This closure is the primary action for the button
showingSuccessMessage = true
// After 3 seconds, hide the success message
DispatchQueue.main.asyncAfter(deadline: .now() + 3) {
showingSuccessMessage = false
}
}
// Toggle the visibility of the success message
if showingSuccessMessage {
Text("You Did It")
}
}
.padding()
}
}
#Preview {
ContentView()
}
APP #2 - basically same app with tap gesture recognizer. Single touch of text works, but double tap gesture while seemingly recognized by watchOS as blue finger icon appears on top of watch display, shaking back and forth indicating it doesn't know what to do, also won't invoke a touch of the Say Hello text.
import SwiftUI
struct ContentView: View {
@State private var showingSuccessMessage = false
var body: some View {
VStack {
// The view that responds to the tap gesture
Text("Tap to Say Hello")
.padding()
.background(Capsule().fill(Color.orange))
.foregroundColor(.white)
.onTapGesture {
// The action to perform on tap
showingSuccessMessage = true
// After 3 seconds, hide the success message
DispatchQueue.main.asyncAfter(deadline: .now() + 3) {
showingSuccessMessage = false
}
}
// Toggle the visibility of the success message
if showingSuccessMessage {
Text("You did it")
}
}
}
}
#Preview {
ContentView()
}
For some unknown reason, my apple watch is unable to sync with Xcode and I am unable to build to my Watch. In the Devices and Simulators window, it always shows my Apple Watch as "Connecting" and switches between the following messages:
"Waiting to reconnect to [NAME]’s Apple Watch/Xcode will continue when the operation completes."
or
"Previous preparation error: Unsupported wire protocol version: This host does not support the wire protocol version implemented by the device."
The only change that has happened between the apple watch connecting and the error occuring now is I updated my iPhone to IOS v.17.
I have tried to restart all devices, Xcode, Reinstall Xcode and nothing has worked. One thing to note is I am not apart of the Apple Developer Program so I will not have access to any of the diagnostic tools apart of that membership to diagnose this issue.
I use setTitle() to display a custom text on the top left corner (aligned to the clock) of a controller. But after upgrading to watchOS 10, the title is displayed on the right, under the clock, pushing all the design down.
Is there a workaround to make the title behave as it did on older versions?
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?
Anyone who has successfully migrated to using WidgetKit for their Apple Watch complications, your help would be greatly appreciated!
I've migrated to WidgetKit for my Watch app. On the Apple Watch Face Editor, the new Widget names and options appear correctly.
However, on the iPhone Apple Watch app, it offers both WidgetKit and old ClockKit complications... this should not be.
I also have found rendering issues where Watch Faces on the main My Watch tab have blank gaps for WidgetKit complications, when selecting the Watch Face they then render (see photos)
I've put in a feedback FB12460375
Have tried a full clear and reinstall of my app on both devices, no change. This issue occurs on WatchOS 9.5.2 / iOS 16.5.1 and WatchOS 10 Beta 2 / iOS 17 Beta 2
Any other ideas?
Isn't it possible to use the same widgetkit extension for both iOS and WatchOS?
In the WWDC's BackyarBirds project from Apple, I can see the widget extension is added to both the multiplatform (including iOS) and the watch targets. I can also see that the SwiftUI code even uses macros to check which platform the code is running on.
However, I'm having several issues with adding the same extension to both targets. When I add it to the watch target, I get a build error that I'm trying to embed an application that also builds for iOS and that is not allowed for the watch app.
Not sure if any code here is helpful, but this is my widget UI code:
struct AkvaWidget: Widget {
private let kind = "Akva Widget"
var families: [WidgetFamily] {
#if os(iOS)
return [.accessoryCircular, .accessoryRectangular, .systemSmall]
#elseif os(watchOS)
return [.accessoryCircular, .accessoryRectangular, .accessoryInline, .accessoryCorner]
#endif
}
var body: some WidgetConfiguration {
StaticConfiguration(
kind: kind,
provider: AkvaSnapshotTimelineProvider()
) { entry in
AkvaWidgetView(entry: entry)
}
.configurationDisplayName("Akva")
.description("Keep track of your water intake.")
.supportedFamilies(families)
}
}
I’ve created a single-target watchOS app in Xcode 14, but I can’t seem to get ClockKit complications working.
I’ve added a CLKComplicationDataSource class to my watch target, and in the Info pane for my target I have set the CLKComplicationPrincipalClass key to MODULE-NAME.ComplicationController
I haven’t yet added Complication placeholder images to my Assets.xcassets, but as far as I am aware, that shouldn’t be a problem while I am still testing.
However, when I run it on a watchOS simulator, the complications never show up on the watch complications list when adding a complication.
All of the tutorials I can find for ClockKit complications reference older two-target WatchKit apps. Do the newer single target apps no longer support ClockKit? If so, how can I make a two-target WatchKit app with Xcode 14?
Unfortunately I cannot use WidgetKit for my complications because I need to support watchOS 7 at least, and WidgetKit only supports watchOS 9+
Thanks for your help
I added a Watch app to an existing iOS app using XCode 14.1. (single target template) When using WCSession delegate, so I can message between the apps, I always get isWatchAppInstalled = false. If Icreate the same scenario using XCode 13.x, I have no issues.
Has anyone been able to add a watch app to an existing iOS app, create a WCSession object and have isWatchAppInstalled = true?
print("Session:activationDidCompleteWith -->
IsPaired[(String(describing: session.isPaired))]
isWatchAppInstalled[(String(describing: session.isWatchAppInstalled))]
isReachable[(String(describing: session.isReachable))]");
displays:
Session:activationDidCompleteWith --> IsPaired[true] isWatchAppInstalled[false] isReachable[false]
I'm trying to migrate from Complication with CLKComplication to WidgetKit.
I have implemented the required methods in https://developer.apple.com/documentation/widgetkit/converting-a-clockkit-app, but the migration is not working. There is no evidence that the method for migration is also called.
It was the same with Xcode 14.0.1 and Xcode 14.1RC.
class ComplicationController: NSObject, CLKComplicationDataSource, CLKComplicationWidgetMigrator {
...
@available(watchOS 9.0, *)
var widgetMigrator: CLKComplicationWidgetMigrator {
return self
}
@available(watchOS 9.0, *)
func widgetConfiguration(from complicationDescriptor: CLKComplicationDescriptor) async -> CLKComplicationWidgetMigrationConfiguration? {
return CLKComplicationStaticWidgetMigrationConfiguration(kind: "MyWidget", extensionBundleIdentifier: "com.example.myapp.mywatchkitapp.mywidget")
}
}
What's wrong? Has anyone been able to migrate?
I developed an iPhone/Watch app with the single target setting (new method) for Watch app projects, which will be available from Xcode14. This app uses HealthKit to retrieve information such as step count and heart rate from healthcare. The watch app is not independent and requires the iPhone app (companion app).
Regarding the permission to access health care, i found some differences from the Old WatchApp Project (application project structure using WatchExtension when Xcode 13.4 or lower is used).
This does not occur in the iPhone simulator or watch simulator, but only on the actual device.
Both the iPhone app and watch app now display a dialog to allow access to health care
In the Old WatchApp Project, if access was granted in either app, the granted access is synchronized.
When checking the Health Care access status in the iPhone Settings App, permission settings for both the iPhone app and watch app are displayed independently.
Because each permission setting is independent, you can choose to allow access to the iPhone app but not to allow it to the watch app.
the Old WatchApp Project, permission settings for the iPhone app and watch app were synchronized, so it was not possible to have different settings for each.
These behaviors are not described in the documentation.
It would be understandable if the transition from watch "extension" to watch "app" is to split the app into two separate units.
However, since there is no official documentation explaining this, i cannot determine whether this is the correct specification or not.
Furthermore, since the companion app is required rather than a separate Watch app, having the Health Care permission settings out of sync with the companion app could cause unexpected problems and worsen the user experience.
(It would be difficult and cumbersome for the user to know what settings they have made).
Is there a solution to synchronize this behavior with the companion app like as the Old WatchApp Project?
Do i have to go back to the project configuration (use of watchExtension) before Xcode13?
I have prepared a sample project below that can test the above.
https://github.com/HayakawaAKIRA/SingleTargetWatchOSApp-HealthKit
reference:
https://developer.apple.com/videos/play/wwdc2022/10133/
https://developer.apple.com/documentation/watchkit/wkapplication
https://developer.apple.com/documentation/healthkit/setting_up_healthkit
I am having problems on Xcode13.3.1, Monterey 12.2.1, Apple M1 Max.
Sending an UpdateApplicationContext update from a paired iPhone simulator is not received on the paired Apple Watch Simulator in the didRecieveApplicationContext. However, sendMessage from the apple watch simulator does update the iphone simulator app properly. It is however, not possible to send anything from the paired iPhone simulator to the paired Apple Watch Simulator.
When working with actual devices everything works properly with WatchConnectivity with passing information back and forth via updateapplicationcontext and sendmessage calls.
Can anyone confirm this is a bug or if there is something wrong with my setup?