I need to know if an Apple Watch user has a passcode set before we can show sensitive data in a View.
Is there a way to check for this?
LAPolicy is unavailable on the Watch and I cannot check deviceOwnerAuthenticationWithWatch from a paired phone only from a Mac.
Post not yet marked as solved
the specifics are pretty straight forward we just need to the code to get HRV in realtime and pasively like the zendo app in the app store
https://github.com/zendotools/zendo but that github doesnt compile. on the watch i can get the Heart rate to update but not hear rate variability. I need it in real time while the user is looking at his watch and passively throught out the day,.
Post not yet marked as solved
I am just looking for the native watchOS applications bundle ids.
For example:
for iPhone: "com.apple.news" and what is for Watch: ???
I tried "com.apple.news.watchkitapp" which doesn't work. Maybe someone know how to help me?
Post not yet marked as solved
Hi, guys
I am writing UI tests for Apple Watch using XCTest and I need to interact with Apple Watch Home Screen and with elements on it. I know that "com.apple.springboard" could be used to interact with iPhone's Home Screen, what about Apple Watch?
Thank you!
Post marked as Apple Recommended
Is it possible to update the UI of an application written in WatchKit (not SwiftUI) while the watch is lowered and the device is in always-on mode?
I am wanting to continue to update a WKInterfaceTimer label (which shows minutes and seconds) and a couple of WKInterfaceLabel which show live HealthKit info for a fitness app.
I can't seem to see any Watchkit APIs for this and if I do not pause a WKInterfaceTimer when the didDeactivate is called on a WKInterfaceController the it still seems to pause when the app is put into always on mode.
Post not yet marked as solved
I have a watchOS extension that I'm trying to sync to their iPhone using CoreData and CloudKit, but it doesn't seem to want to sync.
I've tried a few solutions (CloudKit + CoreData on iOS and watchOS sync not working, Core data + CloudKit - sharing between iOS and watchOS companion app), but it's still not syncing.
Here's my shared (it's loading in both targets) persistence code:
import CoreData
struct PersistenceController {
static let shared = PersistenceController()
static var preview: PersistenceController = {
let result = PersistenceController(inMemory: true)
return result
}()
let container: NSPersistentCloudKitContainer
init(inMemory: Bool = false) {
container = NSPersistentCloudKitContainer(name: "My-app")
if inMemory {
container.persistentStoreDescriptions.first!.url = URL(fileURLWithPath: "/dev/null")
}
let description = container.persistentStoreDescriptions.first
description?.cloudKitContainerOptions = NSPersistentCloudKitContainerOptions(containerIdentifier: "iCloud.com.mydomain.my-app")
container.loadPersistentStores(completionHandler: { (storeDescription, error) in
if let error = error as NSError? {
print("Unresolved error \(error), \(error.userInfo)")
}
})
container.viewContext.mergePolicy = NSMergeByPropertyObjectTrumpMergePolicy
container.viewContext.automaticallyMergesChangesFromParent = true
}
}
Should I have a different code for the watch? Right now both targets share all the files.
Both targets share the same xcdatamodeld file. I used to have all the ManagedObject classes automatically generated (Codegen: Class Definition), but someone suggested manually generating them, but that didn't seem to change anything. Maybe the classes need to be different for each target (but what should be different)?
Both targets have iCloud and background notifications enabled.
I don't know if this matters, but I'm using SwiftUI. Here's the view model and the relevant code that loads the data (same file for both targets):
import Foundation
import CoreData
import SwiftUI
final class ProjectListViewModel : ObservableObject {
private var viewContext : NSManagedObjectContext
@Published var settings : Settings?
@Published var coreDataHasError = false
@Published var projects : [Project]
init(viewContext : NSManagedObjectContext, settings : Settings? = nil) {
self.projects = [Project]()
self.viewContext = viewContext
self.settings = settings
if settings != nil {
updateList()
}
}
func updateList() {
var orderBy : NSSortDescriptor = NSSortDescriptor(keyPath: \Project.dateModified, ascending: false)
if settings != nil {
switch settings!.orderBy {
case Settings.OrderBy.dateCreated.rawValue:
orderBy = NSSortDescriptor(keyPath: \Project.dateCreated, ascending: false)
case Settings.OrderBy.alphabetical.rawValue:
orderBy = NSSortDescriptor(keyPath: \Project.name, ascending: true)
default:
orderBy = NSSortDescriptor(keyPath: \Project.dateModified, ascending: false)
}
}
let request : NSFetchRequestProject = Project.fetchRequest()
request.predicate = NSPredicate(format: "status == %d", Project.ProjectStatus.active.rawValue)
request.sortDescriptors = [orderBy]
projects = try! viewContext.fetch(request)
}
}
And the view (this one is only used by the watch):
import SwiftUI
import CoreData
struct ProjectListView: View {
@ObservedObject var viewModel : ProjectListViewModel
@ObservedObject var settings : Settings
@Environment(\.presentationMode) var presentationMode: BindingPresentationMode
@Environment(\.managedObjectContext) private var viewContext
init(viewContext: NSManagedObjectContext, settings: Settings) {
self.viewModel = ProjectListViewModel(viewContext: viewContext, settings: settings)
self.settings = settings
}
var body: some View {
if quickCountProject.count == 0 {
viewModel.addScratchProject()
}
return
ScrollView {
VStack {
if viewModel.projects.count = 1 {
ZStack {
VStack {
Text(NSLocalizedString("Title", comment: "Page title"))
.TitleStyle()
List {
ForEach(viewModel.projects) { project in
NavigationLink(destination:
ProjectView(project: project, settings: settings, viewModel: ProjectListViewModel(viewContext: viewContext), viewContext: viewContext)
.environmentObject(self.settings)
.environment(\.managedObjectContext, viewContext))
{
HStack {
Image(systemName: "plus.app.fill").foregroundColor(.main).imageScale(.large)
Text(project.name ?? "").font(.headline).padding(.bottom, 5).padding(.top, 5)
}
.accessibilityHint(Text(NSLocalizedString("View project details", comment: "")))
}
}
.listRowBackground(Color.lightGray)
.padding(0)
}
.frame(minHeight: (45 * CGFloat(viewModel.projects.count)))
}
.padding(0)
}
} else {
Text(NSLocalizedString("To start, add a new project on you phone or iPad. Or use the button below to do a quick count.", comment: ""))
.fixedSize(horizontal: false, vertical: true)
}
}
}
.onAppear(perform: {
viewModel.updateList()
})
}
}
Post not yet marked as solved
I have implemented a very simple iOS + WatchOS app project, where I test how one can communicate with the other. I will paste the code below, but the idea is really simple. Each app has one single screen with a button and a label. Tapping the button will send a message to the counterpart indicating the timestamp when the message was generated.
If I run the app on the simulators, everything works fine: messages are sent and received correctly on both the iPhone and the Watch. (You can find a reference gif on imgur.com/ + o1ZQTLp).
The problem occurs when I try to run the same apps on my physical devices. Session is activated successfully but messages aren't sent. If I debug the code, I even see the WCSession.isReachable value set to true.
When debugging the WatchKit app, I see errorHandler is called on the func sendMessage(), and the error states:
WatchConnectivity session on paired device is not reachable. However, the errorHandler isn't called from the iPhone app.
Details of my devices:
iOS version: 14.0.1
WatchOS version: 7.0.1
I tested this same code before installing the 7.0.1 WatchOS and it worked without any problems, so I wonder if the update introduced some error on the WatchConnectivity framework.
Code on the iPhone app:
import UIKit
import WatchConnectivity
class ViewController: UIViewController {
		@IBOutlet weak var messageLabel: UILabel!
		fileprivate var wcSession: WCSession!
		override func viewDidLoad() {
				super.viewDidLoad()
				wcSession = WCSession.default
				wcSession.delegate = self
				wcSession.activate()
		}
		@IBAction func sendMessageAction(_ sender: Any) {
				let message = [
						"content": "Message sent from iPhone on \(Date())."
				]
				wcSession.sendMessage(message, replyHandler: nil, errorHandler: { error in
						print("Error when sending message: \(error.localizedDescription)")
				})
		}
}
extension ViewController: WCSessionDelegate {
		func session(_ session: WCSession, activationDidCompleteWith activationState: WCSessionActivationState, error: Error?) {
				switch activationState {
				case .activated:
						print("WCSession activated successfully")
				case .inactive:
						print("Unable to activate the WCSession. Error: \(error?.localizedDescription ?? "--")")
				case .notActivated:
						print("Unexpected .notActivated state received after trying to activate the WCSession")
				@unknown default:
						print("Unexpected state received after trying to activate the WCSession")
				}
		}
		func session(_ session: WCSession, didReceiveMessage message: [String : Any]) {
				guard let content = message["content"] as? String else { return }
				DispatchQueue.main.async {
						self.messageLabel.text = content
				}
		}
		func sessionDidBecomeInactive(_ session: WCSession) {
		}
		func sessionDidDeactivate(_ session: WCSession) {
		}
}
Code on the Watch Kit app:
import WatchKit
import Foundation
import WatchConnectivity
class InterfaceController: WKInterfaceController {
		@IBOutlet weak var messageLabel: WKInterfaceLabel!
		fileprivate var wcSession: WCSession!
		override func awake(withContext context: Any?) {
				wcSession = WCSession.default
				wcSession.delegate = self
				wcSession.activate()
		}
		@IBAction func sendMessageAction() {
				let message = [
						"content": "Message sent from Watch on \(Date())."
				]
				wcSession.sendMessage(message, replyHandler: nil, errorHandler: { error in
						print("Error when sending message: \(error.localizedDescription)")
				})
		}
}
extension InterfaceController: WCSessionDelegate {
		func session(_ session: WCSession, activationDidCompleteWith activationState: WCSessionActivationState, error: Error?) {
				switch activationState {
				case .activated:
						print("WCSession activated successfully")
				case .inactive:
						print("Unable to activate the WCSession. Error: \(error?.localizedDescription ?? "--")")
				case .notActivated:
						print("Unexpected .notActivated state received after trying to activate the WCSession")
				@unknown default:
						print("Unexpected state received after trying to activate the WCSession")
				}
		}
		func session(_ session: WCSession, didReceiveMessage message: [String: Any]) {
				guard let content = message["content"] as? String else { return }
				messageLabel.setText(content)
		}
}
Post not yet marked as solved
I'm making my first watch app and have run into a bit of a weird problem.
While writing the app, I'm using it on my Apple Watch Series 6 on a regular basis. I'm installing builds on the watch by simply clicking Run in Xcode with my watch as the target device.
This works well for the most part, but lately I've run into a strange issue: While new builds install seemingly correctly when I click Run in Xcode, they do not persist for very long. Maybe for the next few hours. If I open the app on the Watch the next day, the app has reverted to a particular build I made several weeks ago. To get the newest build back on the watch I have to build and run from Xcode again.
This is the second time over the past few months where the watch has gotten stuck on a build like this. Last time I fiddled with the build and version numbers until it got unstuck. This time I haven't found a way of resolving it.
Things I have tried:
Delete the app from the watch and re-install from Xcode
The same as above, but reboot the device after deleting the app
**** away Xcode's derived data
I'm running the latest stable versions of Xcode and watchOS.
Has anyone else run into this? The app is written in SwiftUI 2 if that matters at all.
Post not yet marked as solved
In all the years of developing for the Apple Watch, the process of trying to run my app on a physical watch or simulator through Xcode is still an absolute nightmare. I probably waste hours each day trying to get my app running. Either the watch doesn't show as paired in Xcode, or it's stuck setting the watch up for development, or it says it's running but Xcode just hangs, or it just doesn't show up in Xcode at all. I have to do so many combinations of restarting my watch, my iPhone, my Mac to try and get it working again. Sometimes it works, sometimes it doesn't and I just give up for the day.
Once I get it running I may have 5 times the app will start properly before going back to not running. When trying to use the simulator the watch keeps coming unpaired with the iPhone and won't run. And it's not possible to use Xcode with an iPhone that has multiple Apple Watches paired to it, which is annoying because I can't have one dedicated watch for testing. I just don't understand after all these years Apple Watch development just keeps getting worse and worse. I'm almost ready to just drop my Watch app completely, it's just not worth the headache we go through trying to develop it.
Post not yet marked as solved
With the WatchOS 8 upgrade, it appears WKExtension.shared().rootInterfaceController is returning nil in certain situations.
One situation I've identified is when there's a multi-page watch app.
But, if I remove the segue, the WKExtension.shared().rootInterfaceController has a value.
So, it seems that using paged navigation can cause the rootInterfaceController to be nil.
Even if the dietaryDetailsController is made the Main Entry Point, rootInterfaceController has a value. So, it only seems to be a problem when it's the first page.
Long term, SwiftUI can be implemented, but, a short term fix is necessary since the rootInterfaceController is necessary to refresh complication data.
With a push segue, the rootInterfaceController does have a value.
Anyone else experiencing this? Am I missing something in configuring the first page of multi-page navigation?
Post not yet marked as solved
I recently tried to connect my Apple Watch (series 3) to my iPhone (13). Before it connects it says I need to update it and I try to but it says that I need to connect to the internet even though I am and it won’t let me continue.
Post not yet marked as solved
I'm stuck in a loop. Maybe someone else can point me in the right direction ?
I'm having issues with Bluetooth device. Developer Admin says call regular tech support. But they will not handle beta.
I'm glad the forums are here, but where is the PROPER place to ask ?
Post not yet marked as solved
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.
Post not yet marked as solved
I have 2 apple watch series 3 and after factory reset, during pairing its showing
"Unable to check for update"
checking for a software update failed because you are not connected to the internet
I am able to connect connect and update my another watch Series 4 on all my iphones with same network
even tried with different network or mobile data
getting same error in all my iPhones
its very frustrating, please suggest how to resolve this issue
Post not yet marked as solved
Is there anybody knowing if there is solution to put watchOS is single app mode? Seems like its possible for all devices except Apple Watches at the moment? Would be super useful to have any kind of info here. Thanks
Post not yet marked as solved
I have an Apple Watch series 2 which is on OS 6.2
and an iPhone on iOS 15.3.1
The Apple Watch doesnt appear to be transferring any data to Apple Health. The phone data is showing and the watch is showing as paired within the My Watch Tab on the Watch App . is this just due to not being compatible?
Post not yet marked as solved
Hello everyone.
I'm trying to work with Core Motion, getting readings from my Apple Watch (Series 4), but am getting inconsistent behaviour.
If I run the code from Apple's Core Motion documentation - https://developer.apple.com/documentation/coremotion/getting_processed_device-motion_data (see Listing 1), I don't get any readings.
The code I run, which works fine on iPhone, but not on Apple Watch, is:
func startDeviceMotion() {
if motion.isDeviceMotionAvailable {
self.motion.deviceMotionUpdateInterval = 1.0 / 60.0
self.motion.showsDeviceMovementDisplay = true
self.motion.startDeviceMotionUpdates(using: .xMagneticNorthZVertical)
self.timer = Timer(fire: Date(), interval: (1.0 / 60.0), repeats: true, block: { (timer) in
if let data = self.motion.deviceMotion {
let x = data.attitude.pitch
let y = data.attitude.roll
let z = data.attitude.yaw
}
})
RunLoop.current.add(self.timer!, forMode: RunLoop.Mode.default)
}
}
The problem is that although .isDeviceMotionAvailable returns true and runs the if statement correctly, the returned data from self.motion.deviceMotion only gives me nil's.
I.e. DeviceMotion is available but still returns nil.
What I have tried so far without luck, is: Adding various Accelerometer, Gyroscope, Location, and Privacy entries to my Info.plist
Modifying the code: lowered the update interval checking for returned errors from the closure running it on a different thread
Searched online for example projects, StackOverflow, etc., but without luck
Run the code as an iPhone app. Here it works as expected without issues.
I'm fairly new to this forum and Apple Development, so any help would be much appreciated!
Post not yet marked as solved
Hi I recently got an Apple Watch and it has been perfectly fine but recently my Apple Watch hasn’t been giving me notifications and I checked it and on my Apple Watch it says that my phone is disconnected and I want my phone and it said that my Apple Watch was connected and none of my messages are going through my Apple Watch and I have no idea what to do and I’m kind of getting mad please help me
Post not yet marked as solved
I'm working on a companion Watch App for my iOS App.
.onAppear() and .onDisappear() do not run if they're inside a child view of the three main views in my content view. For example, my first page is a list of workouts, If I click and navigate to a workout on the list the .onAppear() on that workout page does not run.
Is this a bug on WatchOS 8 beta 4 or am I doing something wrong? The iOS app has very similar functionality and the .onAppear/.onDisappear all work fine on iOS 15 beta 4. Lastly, they seem to work in previews, just not in simulators or my device.
The content view for the app (Those 3 functions do run):
import SwiftUI
import CoreData
struct ContentView: View {
@Environment(\.managedObjectContext) private var viewContext
var body: some View {
TabView {
WorkoutList()
ExerciseList()
HeartRate()
}
.onAppear {
loadDefaultExercises()
loadDefaultWorkouts()
loadProfile()
}
}
func loadDefaultExercises() -> () {... }
func loadDefaultExercises() -> () {... }
func loadDefaultExercises() -> () {... }
}
The WorkoutList() view (.onAppear/.onDisappears placed in here do run but only once at app launch):
import SwiftUI
struct WorkoutList: View {
@Environment(\.managedObjectContext) private var viewContext
@FetchRequest(
sortDescriptors: [NSSortDescriptor(keyPath: \Workout.name, ascending: true)],
animation: .default)
var workouts: FetchedResults<Workout>
var body: some View {
NavigationView {
List {
ForEach(workouts) { workout in
NavigationLink(destination: WorkoutDetail(workout: workout)) {
WorkoutListRow(workout: workout)
}
}
}
.navigationTitle("Workouts")
.onAppear {
print("On Appear (Working but only once on launch)")
}
}
}
}
The WorkoutDetail page that appears when I click on a workout from WorkoutList() (.onAppear/.onDisappears placed in here on any child views from here do not run):
import SwiftUI
import CoreData
struct WorkoutDetail: View {
@ObservedObject var workout: Workout
var body: some View {
ScrollView {
VStack(alignment: .leading) {... }
}
.onAppear {
print("On Appear (NOT WORKING)")
}
.navigationTitle(workout.name ?? "")
}
}
Thanks in advance.
Post not yet marked as solved
My app needs the ability to communicate with bluetooth devices when the app is in the background. This was solved by going into my apps Plist file and adding App communicates using CoreBluetooth to the Required Background Modes. The app works as expected when this is added.
Now when I attempt to upload my app I am given the following error:
Missing entitlement. watchOS extension 'company.app/Watch/AppName.app/PlugIns/AppName Extension.appex' uses 'UIBackgroundModes' value 'bluetooth-central' without the required entitlement 'com.apple.developer.bluetooth-central-background' signed into the bundle.
I do not feel like this should be required, does anyone have an idea on how to solve this issue?
Thanks