WatchKit

RSS for tag

Build apps that leverage watchOS features like background tasks, extended runtime sessions, and access to the Digital Crown using WatchKit.

WatchKit Documentation

Posts under WatchKit tag

137 Posts
Sort by:
Post not yet marked as solved
2 Replies
1.4k Views
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
Posted
by AlwardK.
Last updated
.
Post not yet marked as solved
1 Replies
535 Views
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?
Posted Last updated
.
Post not yet marked as solved
0 Replies
426 Views
Errors: ''Invalid info.plist key. The key 'NSHealthShareUsageDescription'' ''Invalid info.plist key. The key 'NSHealthUpdateUsageDescription'' The app works fine when I just run it on hardware without deployment, but as soon as I try to distribute it, this shows up. The keys above are both defined and described in my App and extensions lists, so what's wrong?
Posted
by ksinha.
Last updated
.
Post not yet marked as solved
0 Replies
382 Views
I am making an application that plays music and vibrates at regular intervals. When you put your arm down, the following situation occurs. Music stops (volume goes to 0?) Vibration stops How can I make it so that it does not stop even if I put my arm down? Supplementation In the WatchOS settings, "Always on" is enabled. I use AVAudioPlayer for sound playback.
Posted
by t_misei.
Last updated
.
Post not yet marked as solved
1 Replies
577 Views
I am trying to add a watch target in my existing project using XCode 15.1 but I am not able to see any watch simulators for this to run my watch app. I created a small sample project separately where I can see watch simulators reflecting in the run destination. Can somebody please help me to locate which property or setting I need to check which is disabling XCode to show watch simulators? I have downloaded the watch simulator.
Posted
by binga11.
Last updated
.
Post not yet marked as solved
0 Replies
616 Views
When connecting my iphone (14pro with iOS 17.2.1) with a paired apple watch (series 9 with OS 10.3), it is not showing up on the devices/simulators list in xcode 15.1. Beyond unpairing/repairing the watch, restarting either iphone or watch, connecting/disconnecting the iphone from the computer or deleting xcode and re-installing xcode, any other suggestions? Under the WatchApp field it shows "no eligible device connected", however, under the console the Apple Watch does appear. I have tried just about everything and can't get the watch to appear in Xcode. I am running all this on a MacBook Pro with Sonoma. Thanks for any assistance!
Posted
by jarns.
Last updated
.
Post not yet marked as solved
0 Replies
446 Views
Hi folks! We are developing a WatchOS companion app which records Accelerometer data. We call CMSensorRecorder.recordAccelerometer(forDuration: _) and retrieve the data by calling CMSensorRecorder.accelerometerData(from: _, to: _). So far so good. But the issue arises when we have a data for say 2 hours. We get the accelerometer data in the SwiftUI Task or using GCD's background queue. The data we get is in the loop, enumerating the CMSensorDataList. The loop goes on when the app is active. But as soon as the Watch app goes to inactive state, say applicationWillResignActive is called, the loop is suspended. I know this is the default behaviour of the OS. But this makes our data parsing so slow that sometimes it takes an hour or so to get 2 hours data. This is making our app not user friendly. Is there a way we can keep our app alive as soon as the data is being processed? Or is there another way for faster data processing that we can send the raw data to phone using WCSession so that the data gets there as soon as recording stops? Thanks
Posted Last updated
.
Post not yet marked as solved
2 Replies
680 Views
I can't get the simplest Widget to work. I simply want to present the app's icon. It does what it's supposed to do in the simulator but on the actual device it only says "Please adopt containerBackground API" at the place where the Widget would have shown otherwise. I found out that I am supposed to add .containerBackground(Color.clear, for: .widget) for no reason at all to make this work. However, when I do that, I just get a gray circle where the app icon was supposed to show. The png files should be fine because again on the simulator it works so I have no idea what I am doing wrong. If someone can tell me what I'm doing wrong or if someone can share their Widget class that would be awesome - I literally only want to show my app's icon on the Watch face but I already fail at that, no idea why they made WidgetKit impossible to work with. import SwiftUI import WidgetKit struct IconEntry: TimelineEntry { let date = Date() let icon: Image } struct IconProvider: TimelineProvider { func placeholder(in context: Context) -> IconEntry { return IconEntry(icon: getImageForContext(context, color: false)) } func getSnapshot(in context: Context, completion: @escaping (IconEntry) -> ()) { let entry = IconEntry(icon: getImageForContext(context, color: false)) completion(entry) } func getTimeline(in context: Context, completion: @escaping (Timeline<Entry>) -> ()) { let entry = IconEntry(icon: getImageForContext(context, color: false)) let timeline = Timeline(entries: [entry], policy: .never) completion(timeline) } } struct IconWidget: Widget { let kind: String = "IconWidget" var body: some WidgetConfiguration { StaticConfiguration(kind: kind, provider: IconProvider()) { entry in IconView() .containerBackground(Color.clear, for: .widget) } .supportedFamilies([.accessoryCircular, .accessoryCorner, .accessoryRectangular]) .description(Text("Show the app's icon on a watch face.")) } } struct InlineWidget: Widget { var body: some WidgetConfiguration { StaticConfiguration(kind: "Inline", provider: IconProvider()) { entry in Text("App Title") .containerBackground(Color.clear, for: .widget) } .configurationDisplayName("App Title") .description("Description") .supportedFamilies([.accessoryInline]) } } func getImageForContext(_ context: TimelineProviderContext, color: Bool) -> Image { var fileNameToUse = "iconColor.png" if(!color) { fileNameToUse = "iconAlpha.png" } let displaySize = context.displaySize if(displaySize.width == 0 || displaySize.height == 0) { return Image(uiImage: .init()) } let uiImage = UIImage(imageLiteralResourceName: fileNameToUse).resizeImage(width: displaySize.width, height: displaySize.height) let image = Image(uiImage: uiImage) return image } struct IconView: View { @Environment(\.widgetRenderingMode) var widgetRenderingMode var body: some View { imageFor(widgetRenderingMode) .resizable() .onAppear { print("ICON VIEW \(widgetRenderingMode == .fullColor ? "COLOR" : "ALPHA")") } .containerBackground(Color.clear, for: .widget) } } private func imageFor(_ widgetRenderingMode: WidgetRenderingMode) -> Image { switch widgetRenderingMode { case .fullColor: return Image(uiImage: UIImage(imageLiteralResourceName: "iconColor.png")) default: return Image(uiImage: UIImage(imageLiteralResourceName: "iconAlpha.png")) } } @main struct IconBundle: WidgetBundle { @WidgetBundleBuilder var body: some Widget { IconWidget() InlineWidget() } } extension UIImage { func resizeImage(width: CGFloat, height: CGFloat) -> UIImage { let edgeLength = min(width, height) let newSize = CGSize(width: edgeLength, height: edgeLength) UIGraphicsBeginImageContextWithOptions(newSize, false, 0.0) self.draw(in: CGRect(x: 0, y: 0, width: newSize.width, height: newSize.height)) if let resizedImage = UIGraphicsGetImageFromCurrentImageContext() { UIGraphicsEndImageContext() return resizedImage } else { return UIImage() } } }
Posted
by Watcher03.
Last updated
.
Post not yet marked as solved
0 Replies
392 Views
Hi, I'm trying to build an app for WatchOS and want to add a translucent capsule with a background blur to blur my text behind it. I tried asking ChatGPT, but it couldn't give me a sufficient answer. I would appreciate it if someone could suggest how I could create that background blur. Thanks!
Posted
by David_Akh.
Last updated
.
Post not yet marked as solved
1 Replies
1k Views
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]
Posted
by wolfulve.
Last updated
.
Post not yet marked as solved
1 Replies
499 Views
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
Posted Last updated
.
Post not yet marked as solved
2 Replies
1.7k Views
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
Posted Last updated
.
Post not yet marked as solved
1 Replies
569 Views
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() }
Posted Last updated
.
Post not yet marked as solved
0 Replies
504 Views
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.
Posted Last updated
.
Post not yet marked as solved
2 Replies
562 Views
I'm working on migrating my app from using CoreData to SwiftData. The swift data code generated by Xcode works correctly for the iOS and Mac Catalyst targets but it is causing a crash for the WatchOS target. It gives me this message **Fatal error: Application must register a ValueTransformer for NSSecureUnarchiveFromDataTransformer ** This attribute is the only one with a .transformable option. @Attribute(.transformable(by: "NSSecureUnarchiveFromDataTransformer")) public var linkedEntities: [UUID] = [] Changing the string NSSecureUnarchiveFromDataTransformer to NSValueTransformerName.secureUnarchiveFromDataTransformerName.rawValue causes a generic crash with no error message. The app has CloudKit integration as well (not sure if relevant). Does anyone have a similar issue and can help me on what to do here?
Posted Last updated
.
Post not yet marked as solved
0 Replies
445 Views
Project Info:A music player iOS App with watchOS app embedded. Project Structure: app target: music intent extenstion: intent (for iOS platform) watchOS app target: watchKit watchOS extension: watchKit Extension iOS app use intent extension to support SiriKit with play media intent, it works very well. now i want to support Siri on watchOS app, but i don't know how. i have tried to add new watch extension target, but it doesn't work. i t keeps saying "my app doesn't support *** instruction". Please share if I have missed to read through some documentation / reference that solves this problem.
Posted
by Highmore.
Last updated
.