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

144 Posts
Sort by:
Post not yet marked as solved
0 Replies
208 Views
Hello How can I create same chart as activity Ring without use healtkit? I try to use some pod as "YOChartImageKit" But this pod not function on Apple Watch 5 series, where i tested it.
Posted
by
Post not yet marked as solved
1 Replies
287 Views
I'm developing an independent WatchOS app that uses NSURLSessionWebSocketTask to access Web Sockets. This works fine as long as the Apple Watch is connected to an iPhone, but when it's not, the web socket won't connect and gives an error that there is no network available. Using NSURLSession to access a web resource works fine though whether the watch is connected to an iPhone or not. Is this a bug or is there a way to get this working? Thanks
Posted
by
Post not yet marked as solved
0 Replies
314 Views
I have a app want to add watch extension,use WatchConnectivity is success when watch and phone all active,but it is fail when watch inactive. how to do phone can send message success or trigger watch shock when watch inactive
Posted
by
Post not yet marked as solved
4 Replies
275 Views
Could anyone help me? If push view app crashed only on real Apple Watch, not Crashed in Watch simulator.  override func awake(withContext context: Any?) {         super.awake(withContext: context)   let imageUrlStringQR = "http://192.168.x.x/Image/MainCollection/MainBG.png"         let imageUrlQR = URL(string: imageUrlStringQR)         let imageDataQR = try! Data(contentsOf: imageUrlQR!)         let imageQR2 = UIImage(data: imageDataQR)         QRImage.setImage(imageQR2)     }
Posted
by
Post not yet marked as solved
3 Replies
247 Views
Hello, how can i send data to apple watch if app is not running. I need the application in apple watch to run with data from iphone as (login, password)) I send data to apple watch when I click the Sign In button. I need the data to be stored in apple watch even if the application in apple watch is not running. as soon as I run it, the data that was received from the Iphone must be used.
Posted
by
Post not yet marked as solved
0 Replies
208 Views
Good day, I am developing an Apple Watch app where one of the main functions should be the Watch to vibrate (a specific sequence of haptic feedback) a few times per day at random intervals. It should do it roughly 4 times per day with the times being different each day From what I’ve gathered, the best approach might be the Smart Alarm from WKExtendedRuntime, but that creates a 30 minute window only and I am not sure how (if at all) that would be useful for my case. PS. It could also be a non Apple approved method, as this app will not go live on the App Store.
Posted
by
Post not yet marked as solved
0 Replies
286 Views
I developed an independent Apple Watch that can access network resources on its own using NSURLSession without going through the iPhone. This works fine if the iPhone is on, but if I turn the iPhone off it is not able to connect. Why does my app lose network connectivity when the iPhone is off even though it's a standalone app and the Watch is connected to my WIFI? Is there anything special I need to do to get this working? It appears that no apps work with the internet when the iPhone is off. WIFI is enabled and connected to my WIFI network under the Settings on the watch
Posted
by
Post not yet marked as solved
2 Replies
519 Views
We've added a watch app extension in the developed iOS application source code. When we're selecting and running the watch application target, We're getting this application installation error with an alert: Could not attach to pid : “11996” attach failed ((os/kern) invalid argument) This alert is coming only on M1 chip-based Mac systems. But the same code is running well on Intel-based Mac systems. Any help from anyone is highly appreciable. Thank you.
Posted
by
Post not yet marked as solved
0 Replies
164 Views
I am receiving the subject error when building my watch-only app to install on my actual watch via iPhone. It does not occur when building for the simulator. This is Xcode 13 so the Info.plist isn't a separate file anymore. Indeed, this key is present in both places, but I didn't add it there and to my knowledge I can't remove it. Any Help appreciated. All operating systems at latest levels. Barry
Posted
by
Post marked as solved
1 Replies
368 Views
Goal: When user (patient) starts performing any test cycle on watchOS app (test can be anything user can interact with watchOS app). At the same time (Simultaneously) I wanted to record the audio in the background on the watchOS app. As soon as the test cycle is completed. I want to stop the audio recording & then sync the audio data with the backend. I know we can do the audio recording on watchOS app using presentAudioRecorderController (using Voice memo) but it is not allowed to perform the test cycle at the same time. Any help can be appreciated. Thanks in advance
Posted
by
Post not yet marked as solved
0 Replies
278 Views
I am using WatchConnectivity to send messages between my swift iPhone / watch app. When I receive a message on the iPhone, from the watch, I need to jump to the main thread. The problem is; when the iPhone is in an inactive/not running state it never seems to complete that action. The iPhone receives the message, but when it tries to dispatchQueue.main.async{} , it seems to time out. The code inside .async{} never gets called. Here’s the code where it receives the message on the iPhone: func session(_ session: WCSession, didReceiveMessage message: [String : Any]) { print("Message recieved: ", message) // We always make it to at least here, no matter what state the application is in. DispatchQueue.main.async { // This code is never called if the app is in an inactive/not running state. // Do something... } }
Posted
by
Post not yet marked as solved
1 Replies
340 Views
Updated to xCode 13.2.1 yesterday. Now getting this crash when launching the Watch App in the simulator. 2022-01-28 10:16:04.429988-0700 WatchApp3 WatchKit Extension[69325:786275] [default] -[SPApplicationDelegate application:_didFinishLaunchingWithOptions:]_block_invoke:833: Error - No interface description file Interface.plist for com.xxxxx.app3.watchkitapp in /Users/user/Library/Developer/CoreSimulator/Devices/9D5452AB-D1F5-4F44-BEE7-D7B49CD51FD9/data/Containers/Bundle/Application/78E94000-05B0-4AD2-8375-3700ED9D8EB4/Control4.app and extensionDelegate <WatchApp3_WatchKit_Extension.ExtensionDelegate: 0x600003c8c5c0> didn't return a applicationRootInterfaceControllerClass.
Posted
by
Post not yet marked as solved
0 Replies
295 Views
I have a watch app which communicates with the iPhone app fine. But when running the WCSession from the Intent extension (used for Siri) I'm getting following in the console logs: Error Domain=WCErrorDomain Code=7018 "Companion app is not installed." Can the Watch Intent extension communicate with iPhone app - if so how can I enable it?
Posted
by
Post not yet marked as solved
1 Replies
391 Views
Hi Folks, I am building a SwiftUI based WatchOS app primarily focused on updating a complication using data from a REST API call. I am trying to reproduce the approach to updating complications in the background as described in "Keeping your complications up to date". The trouble I have is that the func handle(_ backgroundTasks: Set<WKRefreshBackgroundTask>) method on the ExtensionDelegate is never called for the WKURLSessionRefreshBackgroundTask task type. The handle method is invoked for other task types such as WKSnapshotRefreshBackgroundTask. After some refactoring, I have deviated from the approach in the video and I now reshedule the background task in the func urlSession(_ session: URLSession, task: URLSessionTask, didCompleteWithError error: Error?) method of the URLSessionDownloadDelegate. This works fine, and the tasks are being resheduled in the background, but my concern is that there maybe a WKURLSessionRefreshBackgroundTask object lurking in the background for which I haven't called setTaskCompletedWithSnapshot. My session is configured as follows: private lazy var backgroundURLSession: URLSession = { let appBundleName = Bundle.main.bundleURL.lastPathComponent.lowercased().replacingOccurrences(of: " ", with: ".") let sessionIdentifier = "com.gjam.liffeywatch.\(appBundleName)" let config = URLSessionConfiguration .background(withIdentifier: sessionIdentifier) config.isDiscretionary = false config.sessionSendsLaunchEvents = true config.requestCachePolicy = .reloadIgnoringLocalCacheData config.urlCache = nil return URLSession (configuration: config, delegate: self , delegateQueue: nil ) }() and the scheduling code is a follows: func schedule(_ first: Bool) { print("Scheduling background URL session") let bgTask = backgroundURLSession.downloadTask(with: LiffyDataProvider.url) #if DEBUG bgTask.earliestBeginDate = Date().addingTimeInterval(first ? 10 : 60 * 2) #else bgTask.earliestBeginDate = Date().addingTimeInterval(first ? 30 : 60 * 60 * 2) #endif bgTask.countOfBytesClientExpectsToSend = 200 bgTask.countOfBytesClientExpectsToReceive = 1024 bgTask.resume() print("Task started") backgroundTask = bgTask } Does anyone have any idea's why the handle method is not invoked with WKURLSessionRefreshBackgroundTask tasks? Cheers, Gareth.
Posted
by
Post not yet marked as solved
1 Replies
604 Views
Hello, I published an iOS (14.1+) app on the App Store. At present time it is free for download (see the link on my profile). It's mainly for people using public transportation. I would like to create the companion watch app. I am just starting to work on it but the code is already done, I just have to put it together. The main issue seems to be that the WKWebView functionality the iOS app has to display a special list, is not available WatchOS, so the watch app cannot be created. Is that true, or just I did not understand? XCode is complaining about the WebKit not being available when building for the WatchOS simulator. I could use a normal list but the user experience would be different. I cannot find relevant information anywhere. I am developing with SwiftUI and I used the WKWebView inside a UIViewRepresentable on iOS. Please can anyone tell me something on this subject? Thanks in advance
Posted
by
Post not yet marked as solved
0 Replies
201 Views
I have a project of an iOS app with an embedded framework called TotoKit with some model classes. Now I've added a new target with the template "WatchApp for iOS App" to my project. When I try to do "import TotoKit" from the newly created WatchKit extension, no such module is found. What do I have to do ? I have tried without success to: add one dependencies to TotoKi in BuildPhase of the extension target add AppleWatch in Deployment/Target Device Families of the TotoKit target Thanks,
Posted
by
Post not yet marked as solved
1 Replies
334 Views
I'm developing an independent watch app and I have a background task every 60 minutes. But don't have anything happen when I close app or run background mode in over 24 hours. I have use below code: ViewController.swift  override func didDeactivate() {     // This method is called when watch view controller is no longer visible     super.didDeactivate()     setScheduleBackgroundJob {       // Set success     }   }   func setScheduleBackgroundJob(completed: @escaping () -> Void) {     let dateStartBackgroundTask = Date(timeInterval: TASK_INTERVAL_TIME.timeInterval, since: Date())     WKExtension.shared().scheduleBackgroundRefresh(withPreferredDate: dateStartBackgroundTask, userInfo: nil) { error in       if let error = error {         // log if have error         print("Error: ", error.localizedDescription)         return       }       print("BACKGROUND TASK: ", Date());       completed()     }   }   @IBAction func closeApp() {     setScheduleBackgroundJob {       exit(0)     }         } ExtensionDelegate.swift func handle(_ backgroundTasks: Set<WKRefreshBackgroundTask>) {     // Sent when the system needs to launch the application in the background to process tasks. Tasks arrive in a set, so loop through and process each one.     for task in backgroundTasks {       // Use a switch statement to check the task type       switch task {       case let backgroundTask as WKApplicationRefreshBackgroundTask:         // Be sure to complete the background task once you’re done.         createBackgroundSceduleTask()         LocalStorageManager.logCollectData(content: "Collect Health Data Background \(Date())")         DataManager.shared.collectData(bgTask: backgroundTask) //        backgroundTask.setTaskCompletedWithSnapshot(false)       case let snapshotTask as WKSnapshotRefreshBackgroundTask:         // Snapshot tasks have a unique completion call, make sure to set your expiration date         snapshotTask.setTaskCompleted(restoredDefaultState: true, estimatedSnapshotExpiration: Date.distantFuture, userInfo: nil)       case let connectivityTask as WKWatchConnectivityRefreshBackgroundTask:         // Be sure to complete the connectivity task once you’re done.         connectivityTask.setTaskCompletedWithSnapshot(false)       case let urlSessionTask as WKURLSessionRefreshBackgroundTask:         // Be sure to complete the URL session task once you’re done.           DataManager.shared.handleData(urlSessionTask) //        urlSessionTask.setTaskCompletedWithSnapshot(false)       case let relevantShortcutTask as WKRelevantShortcutRefreshBackgroundTask:         // Be sure to complete the relevant-shortcut task once you're done.         relevantShortcutTask.setTaskCompletedWithSnapshot(false)       case let intentDidRunTask as WKIntentDidRunRefreshBackgroundTask:         // Be sure to complete the intent-did-run task once you're done.         intentDidRunTask.setTaskCompletedWithSnapshot(false)       default:         // make sure to complete unhandled task types         task.setTaskCompletedWithSnapshot(false)       }     }   }
Posted
by
Post not yet marked as solved
0 Replies
194 Views
Hey - can you program the watch to vibrate for 2-20 seconds intervals followed by an off period between each vibration period and repeat these various cycles for any amount of time? It seems you could not in the past but there is an opportunity now. Can you also set alarms to trigger it? Thank you!
Posted
by
Post not yet marked as solved
2 Replies
247 Views
I'm a Rails / Node engineer, wanting to make apps for the Apple Watch. Does WatchKit allow us to build background streaming apps, and can those apps store audio files locally (to work without a network connection?
Posted
by