WatchKit

RSS for tag

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

Posts under WatchKit tag

131 Posts
Sort by:

Post

Replies

Boosts

Views

Activity

Migrating to WidgetKit, issues with editing Watch Faces on iPhone
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?
5
0
883
1w
Unable to upload after app transfer
My App includes iPhone + Watch. Then, I carried out the app transfer, After app transfer, I could only see the bundle ID for iphone, but could not find the bundle ID for watch. So I tried to recreate the missing watch bundle id and got an error: An App ID with Identifier 'com.***.watchkitapp' is not available.Please enter a different string. I guess the Bundle ID is duplicate, so I created a non-duplicate Bundle ID to develop, it is ‘com.***.watchapp’, by the way, I want to migrate to SwiftUI. When I finished the development and uploaded the new ipa, I got another error: Invalid Bundle Identifier. Attempting to change bundle identifier from com.***.watchkitapp to com.***.watchapp is disallowed for bundle *** Watch App.app I can't do anything now. What am I supposed to do
0
0
709
Jul ’23
Refresh/Reload Views on watchOS with SwiftUI
I have an iOS app with a companion watchOS app. On the main app I set up an auto renewing subscription. By purchasing it you unlock the Apple Watch app. If you are not subscribed, a paywall view is shown in the watch app. If you are, you get to see the whole app. The thing is when a user completes the purchase on the main app, the watchOS view won't update. The Watch Connectivity framework is set up just fine and I get to communicate successfully to/from both devices. But to reflect the new state change, from the purchase made on the phone, I need to close the watch app and open it again. In doing so, the home page opens up and the users will finally get to navigate the app. Is there a way so that upon receiving the message from the Connectivity framework, I get to refresh/reload the view so that the user doesn't have to close the app and open it again? The pseudocode would be: I receive the object from the main app I check that the user has successfully purchased the subscription I reload the app/reload the view so that the user after tapping the app on the watch gets to see the home page with no extra steps. Thank you!
0
2
591
Jul ’23
Delay when posting Local notification on Apple Watch
Hi! I have some trouble with local notification delivery on Apple Watch. It can take more than 1 minute to see the first local notification delivered. I made sure to not use a trigger so the notification will be delivered right away possible as specified in the UNNotificationRequest initializer doc. But there is always a delay for notification delivery. Here is how I'm creating the local notification: content.title = "title" content.subtitle = "subtitle" content.body = "body" content.userInfo = "userInfo" content.categoryIdentifier = "categoryIdentifier" content.threadIdentifier = "threadIdentifier" content.sound = UNNotificationSound.default let notifyRequest = UNNotificationRequest(identifier: stringWithUUID(), content: content, trigger: nil) let center = UNUserNotificationCenter.current() center.add(notifyRequest) { ( error: Error?) in if let theError = error { print(theError.localizedDescription) } else { print("Scheduled OK") } } Do you have any idea how to avoid the delay? Best!
0
0
504
Jul ’23
How to launch apple watch app from companion app?
Is there a way to open an app on Apple Watch from the iOS companion app as Maps is doing? When a navigation is started from Maps in iOS, Maps app starts right away on Apple Watch. Notice that it is not the notification which is started on Apple Watch, it's the real Maps which is automatically launched on Apple Watch. Do you know how to reproduce the same behaviour for any apps in watchOS? Best!
2
0
708
Jul ’23
Title: Issues with NSExtensionMainStoryboard or NSExtensionPrincipalClass in Widget Extensions for iOS 14
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?
2
1
1k
May ’24
watchOS SwiftUI application deeplink on push notifications
Hey, I am currently trying to add deeplink handling from tapping on push notifications in my watchOS application with a SwiftUI lifecycle. I already have deeplinking working with several onOpenURL modifiers throughout the app for the iOS version. What I wanted to do, is whenever I receive a push notification I construct an URL and then utilise the onOpenURL view modifier to handle the deeplink. I currently struggle to understand if this is possible at all. I have the following setup @main struct WatchApp: App { @WKApplicationDelegateAdaptor var appDelegate: WatchAppDelegate // MARK: - Body var body: some Scene { WindowGroup { ContentView() } } } class WatchAppDelegate: NSObject, WKApplicationDelegate, ObservableObject { func applicationDidFinishLaunching() { UNUserNotificationCenter.current().delegate = self } } extension WatchAppDelegate: UNUserNotificationCenterDelegate { func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse) async { // handle the push notification } } I do receive the the notification as expected in userNotificationCenter(center:, didReceive:) but from there on I didn't find a way bring this information into my app. On iOS I do leverage UIApplication.shared.open(url:) but this is obviously not available on watchOS. What is the official guidance of handling watchOS deep links with SwiftUI lifecycle from tapping of push notifications ? Currently the onOpenURL modifiers are placed on several views, so it would be nice if there is a way to trigger them from a central place. Would be really appreciated if someone knows a way on how to do it :)
0
0
809
Jul ’23
Is this a good approach for creating this Apple Watch sleep game feature?
I am creating a watch app that keeps track of the amount of time a user has been asleep for and then updates a game using an API in real time if they surpass another user's sleep time. They select who they want to surpass so the app knows the target time they want to sleep for. I know this probably sounds silly, it's not the final iteration of what I want to build but I know I will need this functionality. So I need this watch app to be able to update the game if they surpass the opponent while the user is sleeping. I don't think this is possible without using extended runtime sessions so that it can run in the background and check to see how long the user has been asleep for after the watch locks. As far as I know the extended runtime sessions only last for 30 minutes though. My current plan to deal with this is to reschedule the session using session.start(at: ) I am currently thinking about doing it like this: User selects opponent and goes to bed App gets the amount of time the user needs to sleep for to surpass opponent, "sleepTime" App schedules an extended runtime session to activate sleepTime seconds in the future sleepTime seconds in the future the session activates and the app checks to see how long the user has actually slept since they went to bed. If the user has slept less than the sleepTime needed to surpass the opponent the app will reschedule the extended runtime session for sleepTime - amountSleptSoFar == "sleepRemaining" seconds, in the future. sleepRemaining seconds in the future the session will activate and check to see how long the user has actually slept for again. If the user has slept less than the time needed to surpass the opponent then the session is rescheduled like before If the user has slept more than the time needed to surpass the opponent then the app uses an API to update the game. It is important that the game is updated as soon as the user surpasses an opponent and I don't want to set up a database to store sleep information and then update the game using the database data as soon as the database is updated. Does this seem like an okay approach? And more importantly is it possible to do? From what I've read and implemented so far it seems possible but please let me know if I'm missing something. The one thing I'm unsure about is if I can use session.start(at: ) when the app is not currently open. If I can't reschedule using that then how else could I do what I need to do?
0
0
544
Aug ’23
Crash when using SwiftData Access in background triggered from WCSessionDelegate
I'm having a weird issue. I have a watch app which communicates with the phone using a WCSessionDelegate. if the phone app is open everything works fine, but if the app is closed, when the watch sends a message, my app is woken from the background, after which onAppear() is called in my app which causes a swiftData query to run. Calling any swiftdata function from a backgrounded app causes it to immediately crash with the following stack trace. Any ideas what im doing wrong? or a better way to trigger my code instead of onAppear, so it won't be called when my watch wakes my app from the background? .onAppear { reloadData() } private func reloadData() { let fetch = FetchDescriptor<SavedServer>( predicate: nil, sortBy: [.init(\.displayOrder)] ) guard let results = try? modelContext.fetch(fetch) else { self.rows = [] return } self.rows = results } ------------------------------------- Translated Report (Full Report Below) ------------------------------------- Incident Identifier: 057999AF-7840-410E-B3EE-29082C5AED00 CrashReporter Key: 28AF2AA0-4626-9964-9664-36077DAF4E1A Hardware Model: MacBookPro18,2 Process: MC Status [68915] Path: /Users/USER/Library/Developer/CoreSimulator/Devices/C61698BA-C4CA-4DD9-B824-DBF57AC65090/data/Containers/Bundle/Application/A685371C-9174-4CF7-9E99-D573310CC3E5/MC Status.app/MC Status Identifier: com.shemeshapps.MinecraftServerStatus Version: 2.0 (1) Code Type: ARM-64 (Native) Role: Non UI Parent Process: launchd_sim [55432] Coalition: com.apple.CoreSimulator.SimDevice.C61698BA-C4CA-4DD9-B824-DBF57AC65090 [164301] Responsible Process: SimulatorTrampoline [53834] OS Version: macOS 13.4.1 (22F82) Release Type: User Report Version: 104 Exception Type: EXC_CRASH (SIGABRT) Exception Codes: 0x0000000000000000, 0x0000000000000000 Triggered by Thread: 0 Last Exception Backtrace: 0 CoreFoundation 0x18046589c __exceptionPreprocess + 160 1 libobjc.A.dylib 0x18005c09c objc_exception_throw + 56 2 CoreData 0x184989b94 -[NSFetchRequest(_NSInternalMethods) _incrementInUseCounter] + 0 3 CoreData 0x1849aa99c -[NSManagedObjectContext executeRequest:error:] + 164 4 CoreData 0x1848fe250 NSManagedObjectContext.fetch<A>(_:) + 80 5 SwiftData 0x1a89b7ad8 ModelContext.fetch<A>(_:) + 124 6 SwiftData 0x1a89c48c0 dispatch thunk of ModelContext.fetch<A>(_:) + 20 7 MC Status 0x102530ef4 MainAppContentView.reloadData(forceRefresh:) + 752 (MainAppContentView.swift:112) 8 MC Status 0x102533540 closure #2 in MainAppContentView.body.getter + 44 (MainAppContentView.swift:78) 9 SwiftUI 0x108a0b7a0 0x107b8c000 + 15202208 10 SwiftUI 0x108a0b7bc 0x107b8c000 + 15202236 11 SwiftUI 0x108a0b7a0 0x107b8c000 + 15202208 12 SwiftUI 0x108fdce70 0x107b8c000 + 21302896 13 SwiftUI 0x108fd6ec0 0x107b8c000 + 21278400 14 SwiftUI 0x1081edb24 0x107b8c000 + 6691620 15 SwiftUI 0x10928d650 0x107b8c000 + 24122960 16 libdispatch.dylib 0x1801424f4 _dispatch_call_block_and_release + 24 17 libdispatch.dylib 0x180143d3c _dispatch_client_callout + 16 18 libdispatch.dylib 0x180152b24 _dispatch_main_queue_drain + 1272 19 libdispatch.dylib 0x18015261c _dispatch_main_queue_callback_4CF + 40 20 CoreFoundation 0x1803c61b4 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 12 21 CoreFoundation 0x1803c08cc __CFRunLoopRun + 1936 22 CoreFoundation 0x1803bfd28 CFRunLoopRunSpecific + 572 23 GraphicsServices 0x189864bc0 GSEventRunModal + 160 24 UIKitCore 0x103b30208 -[UIApplication _run] + 868 25 UIKitCore 0x103b33e80 UIApplicationMain + 124 26 SwiftUI 0x108a10524 0x107b8c000 + 15222052 27 SwiftUI 0x108a103c4 0x107b8c000 + 15221700 28 SwiftUI 0x108722088 0x107b8c000 + 12148872 29 MC Status 0x102506d30 static MCStatusApp.$main() + 40 30 MC Status 0x102506de0 main + 12 (MCStatusApp.swift:12) 31 dyld_sim 0x1028fd558 start_sim + 20 32 dyld 0x1026b1f28 start + 2236 33 ??? 0x3c15800000000000 ??? Thread 0 Crashed:: Dispatch queue: com.apple.main-thread 0 libsystem_kernel.dylib 0x102f1cfa8 __pthread_kill + 8 1 libsystem_pthread.dylib 0x10285712c pthread_kill + 256 2 libsystem_c.dylib 0x1801375ec abort + 104 3 libc++abi.dylib 0x180263c78 abort_message + 128 4 libc++abi.dylib 0x180255198 demangling_terminate_handler() + 300 5 libobjc.A.dylib 0x180037bf0 _objc_terminate() + 124 6 libc++abi.dylib 0x180263150 std::__terminate(void (*)()) + 12 7 libc++abi.dylib 0x180263100 std::terminate() + 52 8 libdispatch.dylib 0x180143d50 _dispatch_client_callout + 36 9 libdispatch.dylib 0x180152b24 _dispatch_main_queue_drain + 1272 10 libdispatch.dylib 0x18015261c _dispatch_main_queue_callback_4CF + 40 11 CoreFoundation 0x1803c61b4 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 12 12 CoreFoundation 0x1803c08cc __CFRunLoopRun + 1936 13 CoreFoundation 0x1803bfd28 CFRunLoopRunSpecific + 572 14 GraphicsServices 0x189864bc0 GSEventRunModal + 160 15 UIKitCore 0x103b30208 -[UIApplication _run] + 868 16 UIKitCore 0x103b33e80 UIApplicationMain + 124 17 SwiftUI 0x108a10524 0x107b8c000 + 15222052 18 SwiftUI 0x108a103c4 0x107b8c000 + 15221700 19 SwiftUI 0x108722088 0x107b8c000 + 12148872 20 MC Status 0x102506d30 static MCStatusApp.$main() + 40 21 MC Status 0x102506de0 main + 12 (MCStatusApp.swift:12) 22 dyld_sim 0x1028fd558 start_sim + 20 23 dyld 0x1026b1f28 start + 2236
1
2
889
Aug ’23
Beginner Seeking Guidance on Connecting a WatchOS App to Tesla API and Core Data Best Practices
Hello everyone, I'm a complete beginner when it comes to programming and have been learning Swift for the past 2-3 months. I'm in the process of writing my very first project, an Apple Watch app for Tesla owners. So far, I've managed to complete the UI aspect of the app and have recently begun diving into the coding part. However, I find myself a bit lost when it comes to connecting my app to the unofficial Tesla API. On top of that, I'm also wondering if integrating Core Data is necessary for this kind of project? If anyone could help me by providing a clear roadmap, it would greatly accelerate my research and learning process. Any tips, tutorials, or resources you could point me toward would be immensely helpful. Thanks in advance for your assistance! Best Regards Sasan
0
0
362
Aug ’23
How can users download an old version of a watch app?
I have just released a new version of my watch app, which requires watchOS 8 and is therefore not usable by series 2 and older watches. Is there any way that users with those watches can get the previous version of the app? The new version of the iOS app runs on their phones but the watchOS app will not run on their watches, so they need to use the old version of both. Thanks in advance.
3
0
1.3k
Sep ’23
No swimming distances on watchOS 10
For some reason I am not receiving HKQuantityTypeIdentifierDistanceSwimming samples when using the watchOS 10 beta (8). The same code works fine on watchOS 9 but not on watchOS 10. I have tried specifically enabling them in the collection types for the live builder and /or starting a query for them, but neither approach is causing any samples to be returned to the app. Is this a known issue? Has something changed for swimming in watchOS 10? Thanks in advance.
4
0
1k
Oct ’23
How to Play Audio File on Apple Watch Physical Speaker
I am writing a watchOS app where I have some audio files that I want to play at various points. I am using AVAudioPlayer. It all works in the simulator and it also works if I have Air Pods connected to my watch via Bluetooth. However I get no sound if there isn't a paired set of earphones. In the case of no earphones I would like the sounds to play from the physical watch speaker. I can't seem to find any documentation on how to cause that to happen. Any hints or tips are appreciated.
0
0
539
Sep ’23
iOS + WatchOS Build: How to automatize?
Hello, Have an iOS App with (extensionless) Watch App. Watch App is not a stand alone app. Watch App appears in the "Frameworks, Libraries & Embedded content" section of the iOS App Target. Nevertheless, I have to manually launch a build of the Watch App before building the iOS app if I want the build to succeed. Is there a way to automatize build in cascade (at least for release scheme and for "Archiving" ?
1
1
447
Sep ’23
Has WKExtendedRuntimeSession changed the way timers work in watchOS 10?
I have a stand-alone watchOS app that starts a WKExtendedRuntimeSession and a 1-second repeating timer when a button is pressed. No CPU-intensive stuff happens during this extended (background) time. On watchOS 9, this worked perfectly until I stopped it again (or after the hour I get out of a Mindfulness Session Type has passed, and the extended runtime session expires). The screen could go dark, and the timer would keep running. On watchOS 10, I get about 50 seconds when the screen goes dark, and then the timer just stops. No delegate methods are called (i.e. no "extendedRuntimeSession...willExpire()" or "...didInvalidateWith()" is called), though. Also, the scenePhase does not change at this point, it remains at inactive. The execution just stops. When I tap the watch to turn the screen back on, the timer resumes as if nothing happened. Does anybody know what's going on here? Has something changed in WKExtendedRuntimeSessions in watchOS 10, or is it a bug? I tried removing the timer and changing it to a recursive DispatchAsync.main.asyncAfter block, but it yielded the same result.
1
0
470
Sep ’23
CLLocationManager with watchOS10 not sending anything to didUpdateLocations:
My watch app records workouts including health (with HKWorkoutSession) and location data.The watch app is on the App Store and runs without any problems since long time. I updated my own Watch Ultra to watchOS10 and my app does not properly work anymore. Everything works with the exception that the app does not receive any CLLocationManager data on the physical device. On the simulator it works perfectly. I tried several devices in the simulator and they all work. Also I de-coupled the watch from the phone, deleted the watch completely and re-installed it. My app's target is watchOS9, I tried it with watchOS10 and the problems are the same CLLocationManager has correct and valid permissions CLLocationManager is setup like this: locationManager = CLLocationManager() locationManager.delegate = self locationManager.allowsBackgroundLocationUpdates = true locationManager.activityType = .fitness locationManager.desiredAccuracy = kCLLocationAccuracyBest locationManager.distanceFilter = kCLDistanceFilterNone locationManager.startUpdatingLocation() CLLocationManager's delegate is listening to: func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) The CLLocationManager is starting and correctly giving feedback on 'didFailWithError' and on 'didChangeAuthorization'. Nothing that tells me that something is wrong and points to a problem. No data is sent to didUpdateLocations. The function is never ever called. Of course I'm outside with my watch and the GPS signal is strong and I wait long enough. My app is adding the recorded workout to Apple Fitness app (my app uses HKWorkoutSession) and even though my own app does not receive any CLLocationManager data, the workout that it sent to Apple Fitness includes all the CLLocationManager data. It really seems like being a problem with my app only. Does someone have an idea or knows of a same problem? Thomas
1
0
664
Sep ’23