Post

Replies

Boosts

Views

Activity

Method to capture voice input when using CPVoiceControlTemplate
In my navigation CarPlay app I am needing to capture voice input and process that into text. Is there a built in way to do this in CarPlay? I did not find one, so I used the following, but I am running into issues where the AVAudioSession will throw an error when I am trying to set active to false after I have captured the audio. public func startRecording(completionHandler: @escaping (_ completion: String?) -> ()) throws { // Cancel the previous task if it's running. if let recognitionTask = self.recognitionTask { recognitionTask.cancel() self.recognitionTask = nil } // Configure the audio session for the app. let audioSession = AVAudioSession.sharedInstance() try audioSession.setCategory(.record, mode: .default, options: [.duckOthers, .interruptSpokenAudioAndMixWithOthers]) try audioSession.setActive(true, options: .notifyOthersOnDeactivation) let inputNode = self.audioEngine.inputNode // Create and configure the speech recognition request. self.recognitionRequest = SFSpeechAudioBufferRecognitionRequest() guard let recognitionRequest = self.recognitionRequest else { fatalError("Unable to created a SFSpeechAudioBufferRecognitionRequest object") } recognitionRequest.shouldReportPartialResults = true // Keep speech recognition data on device recognitionRequest.requiresOnDeviceRecognition = true // Create a recognition task for the speech recognition session. // Keep a reference to the task so that it can be canceled. self.recognitionTask = self.speechRecognizer.recognitionTask(with: recognitionRequest) { result, error in var isFinal = false if let result = result { // Update the text view with the results. let textResult = result.bestTranscription.formattedString isFinal = result.isFinal let confidence = result.bestTranscription.segments[0].confidence if confidence > 0.0 { isFinal = true completionHandler(textResult) } } if error != nil || isFinal { // Stop recognizing speech if there is a problem. self.audioEngine.stop() do { try audioSession.setActive(false, options: .notifyOthersOnDeactivation) } catch { print(error) } inputNode.removeTap(onBus: 0) self.recognitionRequest = nil self.recognitionTask = nil if error != nil { completionHandler(nil) } } } // Configure the microphone input. let recordingFormat = inputNode.outputFormat(forBus: 0) inputNode.installTap(onBus: 0, bufferSize: 1024, format: recordingFormat) { (buffer: AVAudioPCMBuffer, when: AVAudioTime) in self.recognitionRequest?.append(buffer) } self.audioEngine.prepare() try self.audioEngine.start() } Again, is there a build-in method to capture audio in CarPlay? If not, why would the AVAudioSession throw this error? Error Domain=NSOSStatusErrorDomain Code=560030580 "Session deactivation failed" UserInfo={NSLocalizedDescription=Session deactivation failed}
3
0
75
3w
When presenting CPNavigationAlert the navigation bar will appear
In my CarPlay app, I am hiding the navigation bar by using the following: self.mapTemplate?.automaticallyHidesNavigationBar = true self.mapTemplate?.hidesButtonsWithNavigationBar = false I don't want the navigation bar to show unless a user interacts with the map by tapping it. Strangely, when I present a CPNavigationAlert the navigation bar will often appear and then disappear after the alert is dismissed. Is there a setting or reason that the navigation bar would be appearing when presenting this alert? I would like to keep the nav bar hidden during this time.
Topic: UI Frameworks SubTopic: UIKit Tags:
0
0
38
May ’25
Use Siri to control parts of my CarPlay app
I am building a CarPlay navigation app and I would like it to be as hands free as possible. I need a better understanding of how Siri can work with CarPlay and if the direction I need to go is using Intents or App Shortcuts. My goal is to be able to have the user speak to Siri and do things like "open settings" or "zoom in map" and then call a func in my app to do what the user is asking. Does CarPlay support this? Do I need to use App Intents or App Shortcuts or something else?
2
0
64
Apr ’25
Siri Shortcuts of Siri Intent to Voice Control Parts of App
I am new to the idea of Siri Shortcuts and App Intents. What I want to do is use Siri to run a function in my app. Such as saying to Siri Zoom in map and that will then call a function in my app where I can zoom in the map. Similarly, I could say Zoom out map and it would call a function to zoom out my map. I do not need to share any sort of shortcut with the Shortcuts app. Can someone please point me in the right direction for what type of intents I need to use for this?
0
0
40
Apr ’25
CPMapTemplate measurement units on screen
I am wondering how I change the measurement units on screen in my CPMapTemplate. In my screenshot below the distance is in miles, but how can I change that to kilometers? Does this need to come from my route data? I am not seeing this anywhere in the CarPlay programming guide or in the documentation.
1
0
397
Jan ’25
UIDocumentPickerViewController directoryURL no longer opening correct folder
Since iOS 18, I have gotten user reports that the UIDocumentPickerViewController directoryURL is no longer opening the correct folder. Instead it is just loading the root directory of the Files app/iCloud files. Did something change in iOS 18 that I need to account for? Not all users are having this issue, but some are and they are frustrated because a major feature of my app was to allow users to save files at the ubiquityURL. I use the following to get the path: NSURL *rootDirectory = [[[NSFileManager defaultManager] URLForUbiquityContainerIdentifier:nil] URLByAppendingPathComponent:[NSString stringWithFormat:@"Documents/Photos/%@", folderName]]; Is there something that I need to do differently now in iOS 18 to prevent this from happening?
0
1
431
Dec ’24
CPVoiceControlState repeating image?
I am trying to use CPVoiceControlState and include an animated image, but for the life of me I cannot figure out what sort of image it wants. I have tried animated .gif, .png, a static image, an image sequence and none seem to animate. Here is what I am using with an animated .png: func showLoadingTemplate() { enum VoiceControlStates: String { case loading = "loading" } let spinner = UIImage(named: "spinner") loadingTemplate = CPVoiceControlTemplate(voiceControlStates: [ CPVoiceControlState(identifier: VoiceControlStates.loading.rawValue, titleVariants: [NSLocalizedString("Loading...", comment: "CarPlay: Loading")], image: spinner, repeats: true) ]) loadingTemplate?.activateVoiceControlState(withIdentifier: VoiceControlStates.loading.rawValue) if let loading = loadingTemplate { currentInterfaceController?.presentTemplate(loading, animated: true, completion: { (result: Bool, error: Error?) in }) } } This shows the image but it isn't animating. Can anyone let me know what sort of image needs to be used in order to get it to animate? I have seen animated images working in Waze and Google Maps so if must be possible.
1
0
413
Sep ’24
Using CPVoiceControlTemplate in my CarPlay app to capture voice
I have a CarPlay navigation app and I would like to allow the user to speak an address and have our app search at that location. In the Waze app, it provides a button to tap, then it brings up a CPVoiceControlTemplate and you can give it directions or a location and it will then show you search results including the text you spoke as the title. I assume that app would have the same limitations as I do, so I am wondering how another app might do this? It was suggested that I use an App Intent with suggested phrases and then a Shortcut could perform the action. Is there documentation on this somewhere or am I going in the wrong direction here? Obviously Waze is doing what I am wanting so there must be a way. Can anyone point me in the right direction?
2
1
807
Sep ’24
Swift Package with @objc cannot find interface declaration
I am using a Swift PM module and adding it to a brand new project. This project is Objective-C based, but I would like to use the module within a .swift file as I am working to migrate part of my project to Swift. The .swift file is called from the Objective-C app delegate. When doing this method on a brand new project, it builds correctly. However, when I add the module to my production app (has been in development for 10 years) in the same way, I get the following error in my MyApp-Swift.h file: Cannot find interface declaration for 'MBNavigationViewController', superclass of 'CarPlayMapViewController'; did you mean 'UINavigationController'? I have even created a stripped down version of my app with minimal files and it still does not build. There must be some build setting or something else that allows the module to work in a brand new project (accessing the MyApp-Swift.h file that generates the Obj-C methods) but not in my older project?
1
0
889
Jul ’24
State Restoration: Deleting current state data
In the past, it seemed that if you used the app switcher and killed the app, that state restoration data would not persist, and starting the app again would not load any stored state data. But now (at lest in iOS 17) that is no longer the case. There are situations where the old state might cause issues, which we obviously need to fix, but users should be able to clear the state data. I am not using sessions and am using the older methods - application:shouldSaveApplicationState: and application:shouldRestoreApplicationState:. My question is, how can I tell my users to reset/clear state restoration data if needed?
0
0
430
Jun ’24
Driving Task Crash When Adding Action Sheet or Alert
I have a driving task app and am trying to show a CPActionSheetTemplate or a CPAlertTemplate. Both of these are crashing showing: Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Unsupported object <CPActionSheetTemplate: 0x6000030319e0> <identifier: C744031B-99F6-4999-AF19-6ED43140502B, userInfo: (null), tabTitle: (null), tabImage: (null), showsTabBadge: 0> passed to pushTemplate:animated:completion:. Allowed classes: {( CPSearchTemplate, CPNowPlayingTemplate, CPPointOfInterestTemplate, CPListTemplate, CPInformationTemplate, CPContactTemplate, CPGridTemplate, CPMapTemplate )}' This is very strange, because in the docs all app types are allowed to show ActionSheets and Alerts. Why is this crashing?
1
0
808
Dec ’23
iOS 15 change in MKTileOverlay and tileSize?
In our iOS app we use a MKTileOverlay subclass and set tileSize to CGSizeMake(512, 512). This allows tiled maps such as Open Street Maps to display larger for those that need larger font sizes. Since iOS 15 this no longer works, and the tiles are not large anymore and are small, similar to how it was before we added this feature. Once tileSize has been set, we use loadTileAtPath:(MKTileOverlayPath)path result:(void (^)(NSData *, NSError *))result to return the larger image NSData in the result. Did something change in OS 15 and MKTileOverlay and tileSize that would require some changes on our end?
0
0
783
Sep ’21