Posts

Post not yet marked as solved
6 Replies
16k Views
Hello, Just starting to learn Xcode and I can test the first chapter's app on my iPhone if it's conncted via USB-C. The book walks me through the part where I can allow Xcode to connect to the iPhone via WiFi, just checking "Connect via Network."Yet Xcode cannot find my phone unless it's connected via USB. When I go to Devices that checkbox stays checked, unless I unplug the phone it which case that box doesn't even appear.And yes, they are both on the same WiFi, it's the only one I have and it's up and running.Any thoughs?
Posted
by SergioDCQ.
Last updated
.
Post marked as solved
2 Replies
2.2k Views
Am going through a SwiftUI course, so the code is not my own. When I migrated my @Bindings into @Published items in an @ObservableObject I started getting the following error: Publishing changes from within view updates is not allowed, this will cause undefined behavior. The warning occurs in the ScannerView which is integrated with the main view, BarcodeScannerView. It occurs when an error occurs, and scannerView.alertItem is set to a value. However, it does not occur when I am setting the value of scannerView.scannedCode, and as far as I can tell, they both come from the sample place, and are the same actions. There are tons of posts like mine, but I have yet to find an answer. Any thoughts or comments would be very appreciated. BarcodeScannerView import SwiftUI struct BarcodeScannerView: View { @StateObject var viewModel = BarcodeScannerViewModel() var body: some View { NavigationStack { VStack { ScannerView(scannedCode: $viewModel.scannedCode, typeScanned: $viewModel.typeScanned, alertItem: $viewModel.alertItem) .frame(maxWidth: .infinity, maxHeight: 300) Spacer().frame(height: 60) BarcodeView(statusText: viewModel.typeScanned) TextView(statusText: viewModel.statusText, statusTextColor: viewModel.statusTextColor) } .navigationTitle("Barcode Scanner") .alert(item: $viewModel.alertItem) { alertItem in Alert(title: Text(alertItem.title), message: Text(alertItem.message), dismissButton: alertItem.dismissButton) } } } } BarcodeScannerViewModel import SwiftUI final class BarcodeScannerViewModel: ObservableObject { @Published var scannedCode = "" @Published var typeScanned = "Scanned Barcode" @Published var alertItem: AlertItem? var statusText: String { return scannedCode.isEmpty ? "Not Yet scanned" : scannedCode } var statusTextColor: Color { scannedCode.isEmpty ? .red : .green } } ScannerView import SwiftUI struct ScannerView: UIViewControllerRepresentable { typealias UIViewControllerType = ScannerVC @Binding var scannedCode : String @Binding var typeScanned : String @Binding var alertItem: AlertItem? func makeCoordinator() -> Coordinator { Coordinator(scannerView: self) } func makeUIViewController(context: Context) -> ScannerVC { ScannerVC(scannerDelegate: context.coordinator) } func updateUIViewController(_ uiViewController: ScannerVC, context: Context) { } final class Coordinator: NSObject, ScannerVCDelegate { private let scannerView: ScannerView init(scannerView: ScannerView) { self.scannerView = scannerView } func didFind(barcode: String, typeScanned: String) { scannerView.scannedCode = barcode scannerView.typeScanned = typeScanned print (barcode) } func didSurface(error: CameraError) { switch error { case .invalidDeviceinput: scannerView.alertItem = AlertContext.invalidDeviceInput case .invalidScannedValue: scannerView.alertItem = AlertContext.invalidScannedValue case .invalidPreviewLayer: scannerView.alertItem = AlertContext.invalidPreviewLayer case .invalidStringObject: scannerView.alertItem = AlertContext.invalidStringObject } } } }
Posted
by SergioDCQ.
Last updated
.
Post not yet marked as solved
0 Replies
494 Views
I have this long kludgy bit of code that works. I've outlined it below so as not to be confusing as I have no error within my code. I just need to know if there's a method that already exists to copy a specific part of an AVAudioPCMBuffer to a new AVAudioPCMBuffer? So if I have an AVAudioPCMBuffer of 10,000 frames, and I just want frames 500 through 3,000 copied into a new buffer (formatting and all) without altering the old buffer...is there a method to do this? My code detects silent moments in an audio recording I currently read an audio file into an AVAudioPCMBuffer (audBuffOne) I loop through the buffer and detect the starts and ends of silence I record their positions in an array This array holds what frame position I detect voice starting (A) and which frame position the voice ends (B), with some padding of course ... new loop ... I loop through my array to go through each A and B framePositions Using the sample size from the audio file's formatting info, I create a new AVAudioPCMBuffer (audBuffTwo) large enough to hold from A to B and having the same formatting as audBuffOne I go back to audBuffOne Set framePosition to on the audio file to A Read into audBuffTwo for there proper length to reach frame B Save audBuffTwo to a new file ...keep looping
Posted
by SergioDCQ.
Last updated
.
Post marked as solved
1 Replies
916 Views
I am looping through an audio file, below is my very simple code. Am looping through 400 frames each time, but I picked 400 here as a random number. I would prefer to read in by time instead. Let's say a quarter of second. So I was wondering how can I determine the time length of each frame in the audio file? I am assuming that determining this might differ based on audio formats? I know almost nothing about audio. var myAudioBuffer = AVAudioPCMBuffer(pcmFormat: input.processingFormat, frameCapacity: 400)! guard var buffer = AVAudioPCMBuffer(pcmFormat: input.processingFormat, frameCapacity: AVAudioFrameCount(input.length)) else { return nil } var myAudioBuffer = AVAudioPCMBuffer(pcmFormat: input.processingFormat, frameCapacity: 400)! while (input.framePosition < input.length - 1 ) { let fcIndex = ( input.length - input.framePosition > 400) ? 400 : input.length - input.framePosition try? input.read(into: myAudioBuffer, frameCount: AVAudioFrameCount(fcIndex)) let volUme = getVolume(from: myAudioBuffer, bufferSize: myAudioBuffer.frameLength) ...manipulation code }
Posted
by SergioDCQ.
Last updated
.
Post marked as solved
2 Replies
544 Views
I would like to open an audio file on my iOS device and remove long silences. I already have the code for calculating volumes so am not pasting that here. What I am unsure of "how to do" is: While I believe that I have the proper code to read the file below, I am unsure as to how to read it in proper pieces to I can later get the volume of each piece. I realize that this might be a situation of calculating the size of frames and whatnot. But I am totally green when it comes to audio. I would seriously appreciate any guidance. guard let input = try? AVAudioFile(forReading: url) else { return nil } guard let buffer = AVAudioPCMBuffer(pcmFormat: input.processingFormat, frameCapacity: AVAudioFrameCount(input.length)) else { return nil } do { try input.read(into: buffer) } catch { return nil }
Posted
by SergioDCQ.
Last updated
.
Post not yet marked as solved
0 Replies
678 Views
Updated info below Full disclosure: I do have this question over on StackOverflow, but I am at a standstill till I find a way to move forward, debug, etc. I am trying to recognize prerecorded speech in Swift. Essentially it either detects no speech, detects blank speech, or works on the one prerecorded file where I screamed a few words. I can't tell where the headache lies and can't figure out if there's a more detailed way to debug this. I can't find any properties that give more detailed info. Someone on SO did recommend I go through Apple's demo, here. This works just fine, and my code is very similar to it. Yet the main difference remains if there is something about the way I save my audio files or something else is leading to my headaches. If anyone has any insight into this I would very much appreciate any hints. My question over on StackOverflow Updated info below, and new code Updated info It appears that I was calling SFSpeechURLRecognitionRequest too often, and before I completed the first request. Perhaps I need to create a new instance of SFSpeechRecognizer? Unsure. Regardless, I quickly/sloppily adjusted the code to only run it once the previous instance returned its results. The results were much better, except one audio file still came up as no results. Not an error, just no text. This file is the same as the previous file, in that I took an audio recording and split it in two. So the formats and volumes are the same. So I still need a better way to debug this, to find out what it going wrong with that file. The code where I grab the file and attempt to read it func findAudioFiles(){ let fm = FileManager.default var aFiles : URL print ("\(urlPath)") do { let items = try fm.contentsOfDirectory(atPath: documentsPath) let filteredInterestArray1 = items.filter({$0.hasSuffix(".m4a")}) let filteredInterestArray2 = filteredInterestArray1.filter({$0.contains("SS-X-")}) let sortedItems = filteredInterestArray2.sorted() for item in sortedItems { audioFiles.append(item) } NotificationCenter.default.post(name: Notification.Name("goAndRead"), object: nil, userInfo: myDic) } catch { print ("\(error)") } } @objc func goAndRead(){ audioIndex += 1 if audioIndex != audioFiles.count { let fileURL = NSURL.fileURL(withPath: documentsPath + "/" + audioFiles[audioIndex], isDirectory: false) transcribeAudio(url: fileURL, item: audioFiles[audioIndex]) } } func requestTranscribePermissions() { SFSpeechRecognizer.requestAuthorization { [unowned self] authStatus in DispatchQueue.main.async { if authStatus == .authorized { print("Good to go!") } else { print("Transcription permission was declined.") } } } } func transcribeAudio(url: URL, item: String) { guard let recognizer = SFSpeechRecognizer(locale: Locale(identifier: "en-US")) else {return} let request = SFSpeechURLRecognitionRequest(url: url) if !recognizer.supportsOnDeviceRecognition { print ("offline not available") ; return } if !recognizer.isAvailable { print ("not available") ; return } request.requiresOnDeviceRecognition = true request.shouldReportPartialResults = true recognizer.recognitionTask(with: request) {(result, error) in guard let result = result else { print("\(item) : There was an error: \(error.debugDescription)") return } if result.isFinal { print("\(item) : \(result.bestTranscription.formattedString)") NotificationCenter.default.post(name: Notification.Name("goAndRead"), object: nil, userInfo: self.myDic) } } }
Posted
by SergioDCQ.
Last updated
.
Post marked as solved
1 Replies
399 Views
I am looking for a proper tutorial on how to write let's say a messaging app. in other words the user doesn't have to run Messaging to get messages. I would like to build that type of structured app. I realize that "push notifications" appear the way to go. But at this point I still can't find an decent tutorial that seems to cover all the bases. Thank you
Posted
by SergioDCQ.
Last updated
.
Post not yet marked as solved
0 Replies
456 Views
I have a UIViewText that I have in all my UIViewControllers that carries over data from the entire app's instance. If I put the 2 lines that scroll to the bottom in the viewDidAppear section, the text scrolls to the bottom, but you see it occur, so it's not pleasant visually. However, if I put the same 2 lines in the viewWillAppear section (as shown below) then for some reason the UITextView starts at the top of the text. Am I somehow doing this incorrectly? override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) myStatusWin.text = db.status let range = NSMakeRange(myStatusWin.text.count - 1, 0) myStatusWin.scrollRangeToVisible(range) } override func viewDidAppear(_ animated: Bool) { super.viewDidAppear(animated) }
Posted
by SergioDCQ.
Last updated
.
Post not yet marked as solved
2 Replies
653 Views
Within my code to fetch data from CoreData I have the following line: let itemNoSort = NSSortDescriptor(key:"itemNo", ascending: false) What I am not sure of however is that the above is the same as saying descending: true Can't seem to find it in the documentation.
Posted
by SergioDCQ.
Last updated
.
Post not yet marked as solved
0 Replies
406 Views
I've had this issue before... Under User-Defined I have created DEBUG_LEVEL_1 And within my code I have #if DEBUG_LEVEL_1 self.status = printSimDir() #endif However the printSimDir function is never called. So obviously I am setting something incorrectly here
Posted
by SergioDCQ.
Last updated
.
Post not yet marked as solved
1 Replies
516 Views
Within my UIViewController I have a UITextView which I use to dump current status and info into. Obviously evry time I add text to the UITextView I would like it to scroll to the bottom. So I've created this function, which I call from UIViewController whenever I have new data. func updateStat(status: String, tView: UITextView) { db.status = db.status + status + "\n" tView.text = db.status let range = NSMakeRange(tView.text.count - 1, 0) tView.scrollRangeToVisible(range) tView.flashScrollIndicators() } The only thing that does not work is the tView.scrollRangeToVisible. However, if from UIViewController I call: updateStat(status: "...new data...", tView: mySession) let range = NSMakeRange(mySession.text.count - 1, 0) mySession.scrollRangeToVisible(range) then the UITextView's scrollRangeToVisible does work. I'm curious if anyone knows why this works when called within the UIViewController, but not when called from a function? p.s. I have also tried the updateStatus function as an extension to UIViewController, but that doesn't work either
Posted
by SergioDCQ.
Last updated
.
Post marked as solved
3 Replies
504 Views
I am trying to add a UITextView within my app to output data to. Naturally the data will eventually be bigger than the size of the UITextView, and the view is a set size. So I would like the user to be able to scroll through its content. However, I cannot scroll through the content in the app. Am I supposed to build the scrolling function myself? Seems weird that I would have to do that, but I cannot seem to find the answer to this on the web. I’ve also noticed that no vertical scroll at shows up when the text count is larger than the size of the object, which makes me wonder if I am missing a property or two. func createStatusField() -> UITextView { let myStatus = UITextView(frame: CGRect(x: 50, y: 50, width: 100, height: 300)) myStatus.autocorrectionType = .no myStatus.text = "hello there" myStatus.backgroundColor = .secondarySystemBackground myStatus.textColor = .secondaryLabel myStatus.font = UIFont.preferredFont(forTextStyle: .body) myStatus.layer.zPosition = 1 myStatus.isScrollEnabled = true myStatus.showsVerticalScrollIndicator = true return myStatus }
Posted
by SergioDCQ.
Last updated
.
Post not yet marked as solved
0 Replies
525 Views
I already posted about Xcode 13.4.1 not supporting iPhone's 15.6 iOS. But the answer raised even more questions. If the latest version of Xcode (13.4.1) won't support iOS 15.6, why should I think an earlier version of Xcode would? What is the real solution to getting Xcode to run apps on that iOS? Github does not have files past 15.5? Does Xcode automatically update its supported iOS files behind the scenes? Is there a planned date for Xcode to support iOS 15.6? Thank you
Posted
by SergioDCQ.
Last updated
.
Post not yet marked as solved
2 Replies
1.3k Views
So I've found out from other posts that Xcode 13.4.1 won't debug apps on iPhones with iOS 15.6. The solution everyone that everyone seems to agree on is to go back to Xcode 13.3.1. While I am downloading the xip file for that version, I want to check first on how to install the older version? I don't need to mess things up any worse than they are now.
Posted
by SergioDCQ.
Last updated
.