watchOS is the operating system for Apple Watch.

Posts under watchOS tag

200 Posts
Sort by:

Post

Replies

Boosts

Views

Activity

NavigationLink does not work
Hello, For my first watchOS app, I want use a navigationLink for switch to a new view, but the button does not work. Can you help me ? import SwiftUI struct ContentView: View { @State var timerVal = 1 @State var secondScreenShow = false @State private var selectedColor = "30s" var body: some View { VStack { NavigationLink ( destination: SecondView1() , isActive: $secondScreenShow, label: { Text("GO") }) } } } struct SecondView1: View { var body: some View { VStack { Text ("second view1") } } } struct ContentView_Preview: PreviewProvider { static var previews: some View { ContentView() } } Thank you
2
0
388
Nov ’23
How to support Siri on a watchOS app with iOS app(play media intent)
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.
0
0
472
Nov ’23
Watch Only App happens on WatchOS 10.1.1 SSL error
My Watch Only App only went wrong on WatchOS 10.1.1,and ran correctly on other WatchOS systems.The error message is: 1、An SSL error has occurred and a secure connection to the server cannot be made 2、 network error: ErrorDomain =NSURLErrorDomain Code=-1009 "The Internet connection appears to be offline. After my investigation, both my watch network and the server interface I access are normal. May I ask how to solve this problem?
0
1
219
Nov ’23
Issue with WatchOS 10 NavigationLink in Toolbar's topBarLeading or topBarTrailing placement
There is an issue with the NavigationStack in WatchOS 10 when used with TabView: the navigation back from a top bar NavigationLink destination can stay two or three times on the destination when trying to come back to the navigation root. Here are the conditions for the issue to occur: TabView inside NavigationStack ToolbarItem associated with a tab from the TabView--not the whole TabView ToolbarItem placed at .topBarLeading or .topBarTrailing Notes: Wrapping the tab with a NavigationStack inside TabView fails to run Placing the ToolbarItem at .bottomBar works as expected Second level NavigationLink from the destination also works as expected Is there a way to fix? Or is it a WatchOS 10 issue. Thank you! Code to replicate the issue: import SwiftUI struct ContentView: View { var body: some View { NavigationStack { TabView { Text("Tab 1") .toolbar { ToolbarItem(placement: .topBarLeading) { NavigationLink() { Text("Destination") } label: { Image(systemName: "hand.tap") } } } Text("Tab 2") } .tabViewStyle(.verticalPage) } } } Run the app, tap the hand icon, and then tap the caret (or swipe right) to come back to the main screen. (It may require a second take to experience the issue.)
1
0
377
Nov ’23
Add an iOS companion app to a Apple Watch only app
Hi everyone, We're fighting an issue that's driving us up the wall. We developed an Apple Watch Only standalone app, which cost $2.99; once you paid, you could download and use the app on your Apple Watch. We've released a companion iOS app for iPhone that goes into the same bundle (as it's the same app, now supporting two platforms). Nevertheless, the Watch app is still available as a separate app (you can download the Watch app only if you wish without needing to download the iPhone app as well). The iOS companion reads information from the watch and provides more insights into the data it displays. Similar to the sleep tracking apps where you use the watch to sleep and track and the iPhone to see the results. When we released the latest version, including both, we changed the price to Free in all countries. After this, we now have a huge problem we haven't been able to solve: Our existing users (who paid for the Apple Watch-only app) cannot download the companion iOS app. If they go to the App Store, it'd just say "Purchased" with no option to download it (nor the "Get" button or the "Cloud" icon). If you go to your App Store account in your iPhone and then to "Purchases," the app won't appear there. Because technically, you never bought it, and it's now free. If you do the same on your Apple Watch, you can still see the app on your purchases, but that would only download the Apple Watch app, not both. But on top of that, I want my users to be able to download the companion app from the App Store with their iPhones because that's what they'll do anyway (only 9% of our app downloads happen straight in an Apple Watch; most come from iPhones). Did anyone have this problem? I'm already talking with support because this is having a very negative impact on our app, and it all looks to be a bug on the App Store or an edge case that Apple hasn't considered. The thing is, I experienced this issue myself with an app from another dev previously where I had the Apple Watch app installed and paid for it. When I wanted to download the companion they released, it was impossible for the same reasons stated above. He managed to fix it, but I couldn't find any information.
2
0
1.1k
Feb ’24
Troubleshooting Session Start Errors on watchOS
https://idmsa.apple.com/IDMSWebAuth/signin?path=%2F%2Fforums%2Fpost%2Fquestion%3Flogin%3Dtrue&language=US-EN&instanceId=EN&appIdKey=25138a77e3499638936f018102a53961c923f72b517d4a4d6aee9f09529baca9&rv=4 I've built and tested the code obtained from this site, but although the session starts, pausing or stopping it doesn't seem to work properly. Does anyone know what might be causing this issue? I'm using the latest versions of iOS and watchOS, and my Xcode is version 15.0.1. The main code is as follows, and the session does not start properly in startWorkout. import Foundation import os import HealthKit @MainActor class WorkoutManager: NSObject, ObservableObject { struct SessionSateChange { let newState: HKWorkoutSessionState let date: Date } @Published var sessionState: HKWorkoutSessionState = .notStarted @Published var heartRate: Double = 0 @Published var activeEnergy: Double = 0 @Published var speed: Double = 0 @Published var power: Double = 0 @Published var cadence: Double = 0 @Published var distance: Double = 0 @Published var water: Double = 0 @Published var elapsedTimeInterval: TimeInterval = 0 @Published var workout: HKWorkout? let typesToShare: Set = [HKQuantityType.workoutType(), HKQuantityType(.dietaryWater)] let typesToRead: Set = [ HKQuantityType(.heartRate), HKQuantityType(.activeEnergyBurned), HKQuantityType(.distanceWalkingRunning), HKQuantityType(.cyclingSpeed), HKQuantityType(.cyclingPower), HKQuantityType(.cyclingCadence), HKQuantityType(.distanceCycling), HKQuantityType(.dietaryWater), HKQuantityType.workoutType(), HKObjectType.activitySummaryType() ] let healthStore = HKHealthStore() var session: HKWorkoutSession? #if os(watchOS) var builder: HKLiveWorkoutBuilder? #else var contextDate: Date? #endif let asynStreamTuple = AsyncStream.makeStream(of: SessionSateChange.self, bufferingPolicy: .bufferingNewest(1)) static let shared = WorkoutManager() private override init() { super.init() Task { for await value in asynStreamTuple.stream { await consumeSessionStateChange(value) } } } /** Consume the session state change from the async stream to update sessionState and finish the workout. */ private func consumeSessionStateChange(_ change: SessionSateChange) async { sessionState = change.newState /** Wait for the session to transition states before ending the builder. */ #if os(watchOS) /** Send the elapsed time to the iOS side. */ let elapsedTimeInterval = session?.associatedWorkoutBuilder().elapsedTime(at: change.date) ?? 0 let elapsedTime = WorkoutElapsedTime(timeInterval: elapsedTimeInterval, date: change.date) if let elapsedTimeData = try? JSONEncoder().encode(elapsedTime) { await sendData(elapsedTimeData) } guard change.newState == .stopped, let builder else { return } let finishedWorkout: HKWorkout? do { try await builder.endCollection(at: change.date) finishedWorkout = try await builder.finishWorkout() session?.end() } catch { Logger.shared.log("Failed to end workout: \(error))") return } workout = finishedWorkout #endif } } // MARK: - Workout session management // extension WorkoutManager { func resetWorkout() { #if os(watchOS) builder = nil #endif workout = nil session = nil activeEnergy = 0 heartRate = 0 distance = 0 water = 0 power = 0 cadence = 0 speed = 0 sessionState = .notStarted } func sendData(_ data: Data) async { do { try await session?.sendToRemoteWorkoutSession(data: data) } catch { Logger.shared.log("Failed to send data: \(error)") } } } extension WorkoutManager: HKWorkoutSessionDelegate { nonisolated func workoutSession(_ workoutSession: HKWorkoutSession, didChangeTo toState: HKWorkoutSessionState, from fromState: HKWorkoutSessionState, date: Date) { Logger.shared.log("Session state changed from \(fromState.rawValue) to \(toState.rawValue)") let sessionSateChange = SessionSateChange(newState: toState, date: date) asynStreamTuple.continuation.yield(sessionSateChange) } nonisolated func workoutSession(_ workoutSession: HKWorkoutSession, didFailWithError error: Error) { Logger.shared.log("\(#function): \(error)") } nonisolated func workoutSession(_ workoutSession: HKWorkoutSession, didDisconnectFromRemoteDeviceWithError error: Error?) { Logger.shared.log("\(#function): \(error)") } nonisolated func workoutSession(_ workoutSession: HKWorkoutSession, didReceiveDataFromRemoteWorkoutSession data: [Data]) { Logger.shared.log("\(#function): \(data.debugDescription)") Task { @MainActor in do { for anElement in data { try handleReceivedData(anElement) } } catch { Logger.shared.log("Failed to handle received data: \(error))") } } } } private func startWorkout() { Task { do { let configuration = HKWorkoutConfiguration() configuration.activityType = .cycling configuration.locationType = .outdoor try await workoutManager.startWorkout(workoutConfiguration: configuration) } catch { Logger.shared.log("Failed to start workout \(error))") } } }
0
0
426
Nov ’23
Enable Developer Mode on Apple Watch SE w/ Family Setup?
I have an Apple Watch SE (watchOS 10.1) paired to my phone via Family Setup. I'd like to connect it to Xcode to install apps on, but it's not appearing in Xcode's Device Organizer. Nor can I find the option to enable Developer Mode in Settings->Privacy & Security. Note*: I do have my personal watch connected to Xcode. This would be the second watch I'm trying to build to. Is this a limitation of Family Setup? Or is there some way I should be kicking the watch to have it recognized?
1
0
405
Nov ’23
Apple Watch Modular Ultra face clips text and affects font positioning
I'm seeing problems with the new Apple Watch Modular Ultra Watch face... This is all using the latest WatchOS 10.1 and with WidgetKit complications. (Have also tested with the new WatchOS 10.2 beta in the simulator) The Graphic Circular (accessoryCircular) complications space the numbers differently sometimes causing maximum and minimum numbers to look like one long number (see small circular complications in screenshot) The exact same complication in the accessoryRectangular on the Modular Ultra face clips text when it doesn't on any other watch face I've filed feedback FB13344580 Hopefully the screenshots show the issue well.
1
0
581
Nov ’23
Trying to setup Watch app, keep getting this error.
I tried everything and I CANT GET this to work. I tried everything, making sure target dependencies are correct, but i keep getting this error. I also have firebase but the google info plist is in both of my watch app and ios app. I can answer any questions. error: Couldn't load Info dictionary for <DVTFilePath:0x600001aa3950:'/Users/sammyreifel/Library/Developer/Xcode/DerivedData/ScheduleApp-egcamslcafeqlngkuqzfpmipbrzw/Build/Products/Debug-iphonesimulator/ScheduleApp.app/Watch/WSchedule Watch App.app'>
0
0
226
Nov ’23
Is there somehow to change automatically my Bundle Identifier for my Companion App?
Hello! In my project here we have 3 build modes / schemas for our iPhone app: Dev, Stage, Prod. And each one has one bundle identifier, for example, com.myproject.app-Dev, com.myproject.app-Stage and com.myproject.app. How do I can get each bundle identifier and store it inside the WKCompanionAppBundleIdentifier key automatically? Is it possible? Because, sometimes we need to build manually the Stage version here and XCode says the info.plist key for WatchOS App is different from the iPhone App.
1
0
573
Nov ’23
Implementing Apple Watch Widget Complications
I am trying to add Widget Complications to an existing Apple Watch app. I added the WatchOS widgets extension and followed instructions to create static, non-updating complications to merely launch the app from the watch home screen. Here is my code in the widget extension: import WidgetKit import SwiftUI struct Provider: TimelineProvider { func getSnapshot(in context: Context, completion: @escaping (SimpleEntry) -> Void) { } func getTimeline(in context: Context, completion: @escaping (Timeline<SimpleEntry>) -> Void) { } func placeholder(in context: Context) -> SimpleEntry { SimpleEntry(date: Date()) } func snapshot(in context: Context) async -> SimpleEntry { SimpleEntry(date: Date()) } } struct SimpleEntry: TimelineEntry { let date: Date } struct TrapScores_WidgetsEntryView : View { @Environment(\.widgetFamily) var widgetFamily var entry: Provider.Entry var body: some View { switch widgetFamily { case .accessoryCorner: ComplicationCorner() case .accessoryCircular: ComplicationCircular() case .accessoryRectangular: Text("TrapScores") case .accessoryInline: Text("TrapScores") @unknown default: //mandatory as there are more widget families as in lockscreen widgets etc Text("AppIcon") } } } @main struct TrapScores_Widgets: Widget { let kind: String = "TrapScores_Complications" var body: some WidgetConfiguration { StaticConfiguration(kind: kind, provider: Provider()) { entry in TrapScores_WidgetsEntryView(entry: entry) .containerBackground(.fill.secondary, for: .widget) } .configurationDisplayName("TrapScores") .description("This will launch TrapScores App") .supportedFamilies([.accessoryCorner, .accessoryCircular]) } } struct ComplicationCircular: View { var body: some View { Image("Graphic Circular") .widgetAccentable(true) .unredacted() } } struct ComplicationCorner: View { var body: some View { Image("Graphic Circular") .widgetAccentable(true) .unredacted() } } #Preview(as: .accessoryCircular) { TrapScores_Widgets() } timeline: { SimpleEntry(date: .now) } The complications appear fine in the preview: The complication can be added to the watch face, but no graphic comes with it and it is a blank circle: Any suggestions on what I'm doing wrong?
3
1
584
Nov ’23
Animation not showing on WatchOS 10.1
Ive got a little animation on the first screen on my watchOS app, but in watchOS 10.1 it's not showing up. It docent work. I can't use the simulator to find out why because I haven't got watchOS 10.1 simulator. - here is the code that works on watch OS 10 func updatCurrentProgress() { print("updatCurrentProgress") withAnimation(.interpolatingSpring(duration: 1.2, bounce: 0.0, initialVelocity: 0.0).delay(0.5)) { currentProgress = tiyowehSession.currentDayGoalComplete } completion: { if customGoalValue > 0 && UserDefaults.standard.double(forKey: "currentDayGoalComplete") < 1.0 && tiyowehSession.currentDayGoalComplete >= 1.0 { WKInterfaceDevice.current().play(.notification) print("playing .success)") goalProgressViewOpasity = 0.0 goalCompleteTickOpasity = 1.0 withAnimation(.easeOut(duration: 2.0).delay(1.2)) { goalCompleteTickOpasity = 0.0 goalProgressViewOpasity = 1.0 } } UserDefaults.standard.set(currentProgress, forKey: "currentDayGoalComplete") } } . The sound plays correctly "WKInterfaceDevice.current().play(.notification)" but the opacity docent change like it used to.
0
0
293
Oct ’23
Migrating from CoreData to SwiftData causes crashes on Watch app
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?
2
0
589
Nov ’23
App Store OS versioning rules for watchOS apps
have a watchOS app and it’s iOS counterpart in the AppStore. For now, my app support iOS 15 and watchOS 8. The next version will make a huge step forward and only supports iOS 17 and watchOS 10. I have a question : If someone has an iPhone on iOS17 and a watch on watchOS 8, will the AppStore update the app ? It will be incompatible as the new iOS app won’t work with the old watchOS one. I hope the AppStore won’t propose the update in this case to avoid impacting users with a modern iPhone and an old Apple Watch who can continue with the previous app version. What’s your advice ?
2
0
411
Oct ’23
App that allows two-way data exchange between iOS app and WatchOS app.
I would like to create an app that allows iOS and watchOS apps to exchange data in both directions, but I can't find instructions on how to do this anywhere. I would like to know how to do this in detail. import SwiftUI import WatchConnectivity struct ContentView: View { @State private var receivedMessage: String = "No message received" @ObservedObject private var sessionDelegate = SessionDelegate() var body: some View { VStack { Text(receivedMessage) .padding() Button("Receive from iPhone") { sessionDelegate.sendMessageToiPhone() } } .onAppear { // WatchConnectivityセットアップ sessionDelegate.setupWatchConnectivity() } } } struct ContentView_Previews: PreviewProvider { static var previews: some View { ContentView() } } class SessionDelegate: NSObject, ObservableObject, WCSessionDelegate { @Published var receivedMessage: String = "No message received" func setupWatchConnectivity() { if WCSession.isSupported() { let session = WCSession.default if WCSession.isSupported() { let session = WCSession.default // デリゲートを設定 session.delegate = self // セッションのアクティベーション状態を確認し、非アクティブな場合にアクティベートする if session.activationState != .activated { session.activate() } // セッションのその他の設 if WCSession.default.activationState == .activated { // セッションがアクティブ // ここでセッションがアクティブな場合の処理を実行 print("アクティブ") } else { // セッションがアクティブでない // ここでセッションがアクティブでない場合の処理を実行 print("アクティブない") } } session.delegate = self if session.isReachable { session.sendMessage(["messageKey": "Initial message"], replyHandler: nil, errorHandler: { error in print("Error sending initial message to iPhone: \(error.localizedDescription)") }) } } } func sendMessageToiPhone() { if WCSession.default.isReachable { WCSession.default.sendMessage(["messageKey": "Request from Watch"], replyHandler: nil, errorHandler: { error in print("Error sending request to iPhone: \(error.localizedDescription)") }) } } // WCSessionDelegate メソッド func session(_ session: WCSession, activationDidCompleteWith activationState: WCSessionActivationState, error: Error?) { // セッションのアクティベーションが完了したときの処理 } func session(_ session: WCSession, didReceiveMessage message: [String : Any]) { if let receivedMessage = message["messageKey"] as? String { DispatchQueue.main.async { self.receivedMessage = receivedMessage } } } } I wrote the above code in contentView.swift in watchOS, but the session was not activated. I wonder if this is the cause.
0
0
200
Oct ’23
GPS performance is still terrible for WatchOS 10
Related to this thread https://developer.apple.com/forums/thread/737819 I can confirm (again) that GPS performance on the watch Ultra (and likely all watches on watchOS 10) had been severely degraded. Here is a swim that I did with both an Apple Watch Series 4 on watchOS 9 (green track) and a watch Ultra on watch OS 10.1 (blue track). While the Series 4 provides relatively accurate data, the Watch Ultra provides very poor data with criss crossing paths and ridiculous data points. Apple did respond to my feedback with the usual request for sysdiagnose but this has not progressed. FB13192409
0
0
393
Oct ’23