I am trying to record audio using Apple Watch using the presentAudioRecorderControllerWithOutputURL method.
I am using Xcode 7.0 beta 5, iOS9 beta, WatchOS 2 beta and Swift2.
It works great on an emulator. However, as soon as on the device itself, it crashes when the method is called.
Here is my current code:
@IBAction func onClickSpeech() { let filePaths = NSSearchPathForDirectoriesInDomains( NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomainMask.UserDomainMask, true) let documentDir = filePaths.first! let recSoundURL = documentDir + "/record.m4a" let nsUrl = NSURL.fileURLWithPath(recSoundURL) let audioOptions = [ WKAudioRecorderControllerOptionsActionTitleKey : "Recording title", WKAudioRecorderControllerOptionsAlwaysShowActionTitleKey : false, WKAudioRecorderControllerOptionsAutorecordKey: true, WKAudioRecorderControllerOptionsMaximumDurationKey: NSTimeInterval.infinity ] presentAudioRecorderControllerWithOutputURL( nsUrl, preset: WKAudioRecorderPreset.NarrowBandSpeech, options: audioOptions as [NSObject : AnyObject]) { (didSave, error) -> Void in print("didSave:\(didSave), error:\(error)") } }
recSoundURL is a valid path.
The error I get in device logs is:
Aug 18 16:42:12 Sennetts-AppleWatch mediaserverd[283] <Error>: 16:42:12.532 EXCEPTION: [0x1f1ac000] >va> 565: kAudioHardwareUnknownPropertyError: "AudioObjectHasProperty([goin/glob/0]) returned false." Aug 18 16:42:12 Sennetts-AppleWatch mediaserverd[283] <Error>: 16:42:12.555 ERROR: [0x1f1ac000] >va> 240: CAException caught by ExceptionBarrier: 2003332927.
Any idea would be greatly appreciated as I cannot understand this. Thanks.
source share