Post

Replies

Boosts

Views

Activity

Queried heart rate samples in the past interval have lower resolution than recent samples
I am querying heart rate samples taken during a workout. For all of the mentioned cases below I'm wearing an Apple Watch and using the stock Workouts.app in the watch. If I query heart rate samples for a recent workout, it being yesterday or the past month for example, I get the full samples. If I query a workout let's say, two/three months in the past the samples I get back look "choppy" with a lot of missing data. (See attached image) imgur.com/a/FbMSBoa How am I getting the heart rate samples? swift extension HKHealthStore: HKHealthStoreCombine {     public func getT(sample: T, start: Date, end: Date, limit: Int = HKObjectQueryNoLimit) - AnyPublisher[HKQuantitySample], Error where T: HKObjectType {         let subject = PassthroughSubject[HKQuantitySample], Error()                 let sampleType = HKSampleType.quantityType(forIdentifier: HKQuantityTypeIdentifier(rawValue: sample.identifier))!         let predicate = HKQuery.predicateForSamples(withStart: start, end: end)                  let query = HKSampleQuery(sampleType: sampleType, predicate: predicate, limit: limit, sortDescriptors: nil, resultsHandler: { (query, samples, error) in             guard error == nil else {                 logger.error("Error fetching samples of type \(sample.description) from \(start) to \(end) with a limit of \(limit): \(error!.localizedDescription)")                 subject.send(completion: .failure(error!))                 return             }             let samples = samples as? [HKQuantitySample] ?? []             logger.log("Successfully fetched \(samples.count) samples of type \(sample.description) from \(start) to \(end) with a limit of \(limit)")             subject.send(samples)             subject.send(completion: .finished)         })         self.execute(query)         return subject.eraseToAnyPublisher()     } } swift healthStore.get(sample: HKQuantityType.quantityType(forIdentifier: HKQuantityTypeIdentifier.heartRate)!, start: workout.startDate, end: workout.endDate)             .map({                 $0.compactMap({ $0.quantity.doubleValue(for: UserUnits.shared().heartCountUnits) })             })             .replaceError(with: [])             .receive(on: DispatchQueue.main)             .sink(receiveValue: {                 self.heartRate = $0             })             .store(in: &bag) Is this some kind of wrong way that I am working with HealthKit? I don't know what the issue can be but it looks like accessing heart samples in the "past" are somewhat archived and I don't get the full resolution.
4
0
1.7k
Apr ’21
Unable to read or download (sandbox) receipt to find original install version on iOS
I am trying to read the [appStoreReceiptURL](https://developer.apple.com/documentation/foundation/bundle/1407276-appstorereceipturl#) to read the receipt in hopes to find the initial date of purchase or initial version the user has. The plan to use this is to migrate from a paid upfront version to a free + IAP as many might have done over the years. I know I am under a sandbox environment, while I develop this, so the path is file:///.../StoreKit/sandboxReceipt. Currently, I don't require neither local or remote validation of the receipt for the time being so I only need to read the file. Checking if it exists using the FileManager it says that it doesn't so I start a SKReceiptRefreshRequest to retrieve a copy of the receipt from Apple's servers. I know that receipt won't have the exact data I am looking for but as far as I know it will give me an initial install version field for this environment that's 1.0 so it'd work for testing purposes. After setting the SKRequestDelegate and starting the request when the receipt is not found neither the requestDidFinish nor didFailWithError delegate methods are called. Currently I am not able to retrieve any copy of even a "sample" receipt for the sandbox environment. This sample code I am using it's pretty simple so far and is as follows, import StoreKit @objc class ReceiptFetcher : NSObject, SKRequestDelegate { 	let receiptRefreshRequest = SKReceiptRefreshRequest() 	 	override init() { 		super.init() 		receiptRefreshRequest.delegate = self 	} 	 	@objc 	func fetchReceipt() { 		guard let receiptUrl = Bundle.main.appStoreReceiptURL else { 			print("unable to retrieve receipt url") 			return 		} 		 		do { 			// if the receipt does not exist, start refreshing 			let reachable = try receiptUrl.checkResourceIsReachable() 			 			// the receipt does not exist, start refreshing 			if reachable == false { 				receiptRefreshRequest.start() 			} 		} catch { 			print("error: \(error.localizedDescription)") 			/* 			 error: The file “sandboxReceipt” couldn’t be opened because there is no such file 			 */ 			DispatchQueue.main.async { 				self.receiptRefreshRequest.start() 			} 		} 	} 	 	// MARK: SKRequestDelegate methods 	func requestDidFinish(_ request: SKRequest) { 		print("request finished successfully") 	} 	 	func request(_ request: SKRequest, didFailWithError error: Error) { 		print("request failed with error \(error.localizedDescription)") 	} } This is being called from the AppDelegate to first of all request a fresh receipt or load one if it's not present. Currently I am testing this using an iPad with my Apple ID logged in but under Settings.app --> App Store --> Sandbox Account I've logged in with a sandbox account created inside the development team which this app is published under that account. Do I need to enable IAP in the AppStore Connect account so I am able to retrieve receipts? Is receipt validation strictly necessary in this case? I wouldn't need to validate against some third party as the initial purchase has been through the App Store. I would want to only read the fields of the receipt that show information on the initial purchase date/version. I remember did this some time ago with another app that was free but with an IAP. And AFAIK every app, either paid or free, has a receipt attached with this kind of information but being currently on a sandbox environment I am a bit confused. I haven't found anything so far that's relevant and can point me towards what's going on. Running iOS 14b3 and Xcode 12b3.
2
1
2.2k
Jul ’20
Reactivating console mail logging from cronjobs on macOS server
I am running several cron jobs on a Mac server. Some time ago I don't know why I deactivated the cron logs into the local mail of the system. I now am getting errors running those cronjobs and I am not able to take a look at the logs as they are not generated.Is there a way to reactivate this behavior?I tried adding this line on top of the cronjob definition file, cronjob -eMAILTO="/var/mail/MY_USERNAME"With no result, previously whenever a cron ran I was getting on the console a message indicating that I had new mail as the result has been appended to the mail. I can't seem to reactivate this behavior and when I open `mail` from console the inbox is empty.
0
0
515
May ’20
Not able to writeValue to a Bluetooth Peripheral when announced properties state writing+reading is available
I am trying to send a simple JSON to a connected Bluetooth peripheral but getting some problems in the process.The properties read from the peripheral in the didDiscoverCharacteristicsFor method are the following:po characteristic.properties ▿ CBCharacteristicProperties - rawValue : 10Which as this is a mask and if I am not mistaken this states that I can read (2) and write (8) from/to the device.I am writing the data as soon as I discover a new characteristic that matches the requirements in the following wayfunc peripheral(_ peripheral: CBPeripheral, didDiscoverCharacteristicsFor service: CBService,error: Error?) { for characteristic in service.characteristics! { let characteristic = characteristic as CBCharacteristic print(characteristic.uuid) if characteristic.uuid.isEqual(RX_UUID) { // Received only support for writing with response, writing without response is not allowed if characteristic.properties.contains(CBCharacteristicProperties.write) { self.writeJsonStringToPeripheral(peripheral: peripheral, characteristic: characteristic, writeType: .withResponse) } else if characteristic.properties.contains(CBCharacteristicProperties.writeWithoutResponse) { self.writeJsonStringToPeripheral(peripheral: peripheral, characteristic: characteristic, writeType: .withoutResponse) } } } } func writeJsonStringToPeripheral(peripheral: CBPeripheral, characteristic: CBCharacteristic, writeType: CBCharacteristicWriteType) { do { let msgDictionary = ["SSID": self.wiFiCredentials.SSID, "Password": self.wiFiCredentials.Password] let jsonData = try JSONSerialization.data(withJSONObject: msgDictionary, options: []) //let data = "".data(using: .utf8) peripheral.writeValue(jsonData, for: characteristic, type: writeType) } catch let error as NSError { debugPrint("Error in auth message JSON: \(error.description)") This snippet calls the function at line 10 indicating the possibility of writing with a response and after callign it the didWriteValueFor delegate method is called.func peripheral(_ peripheral: CBPeripheral, didWriteValueFor characteristic: CBCharacteristic, error: Error?) { if let error = error { print(error) } else { print("Value writen sucessfully.") } }Printing the following error.Error Domain=CBATTErrorDomain Code=3 "Writing is not permitted." UserInfo={NSLocalizedDescription=Writing is not permitted.}I've made myself sure that the device is connected and I can also see it in the Settings.app. I am a bit lost and I don't know what could be going on here.On the other side if I force the writing to be withoutResponse I get another console log2020-03-25 22:23:50.286662+0100 Cloudy[2595:1232291] [CoreBluetooth] WARNING: Characteristic does not specify the "Write Without Response" property - ignoring response-less writeAfter sending the specified JSON to the device it should start a sequence to connect to the specified WiFi SSID. I am sure the hardware works because I can set those values using the console on the device itself and the process works so there must be something I am missing here that causes this to fail.This test has been done using an iPhone 6S running ios 13.3.1.
2
0
2.5k
Mar ’20