Posts

Post not yet marked as solved
0 Replies
175 Views
I suddenly noticed that changes I made in code had no effect on the app when I rebuilt it and ran it on my M1 Mac as a "made for iPad" target. The debugger will even stop on new lines and seem to execute them, but they do nothing. If I clean the build folder and re-run, the same line executes as expected. This wastes an incredible amount of time until you discover what's happening. Now I have to remember to clean build folder every time I build and run. The application's structure is very simple, with no included libraries or third-party dependencies. Anybody else seeing this? Xcode 15.3 under Sonoma (14.4.1).
Posted Last updated
.
Post marked as solved
1 Replies
267 Views
I'm attempting to record from a device's microphone (under iOS) using AVAudioRecorder. The examples are all quite simple, and I'm following the same method. But I'm getting error messages on attempts to record, and the resulting M4A file (after several seconds of recording) is only 552 bytes long and won't load. Here's the recorder usage: func startRecording() { let settings = [ AVFormatIDKey: Int(kAudioFormatMPEG4AAC), AVSampleRateKey: 22050, AVNumberOfChannelsKey: 1, AVEncoderAudioQualityKey: AVAudioQuality.high.rawValue ] do { recorder = try AVAudioRecorder(url: tempFileURL(), settings: settings) recorder?.delegate = self recorder!.record() recording = true } catch { recording = false recordingFinished(success: false) } } The immediate sign of trouble appears to be the following, in the console. Note the 0 bits per channel and irrelevant 8K sample rate: AudioQueueObject.cpp:1580 BuildConverter: AudioConverterNew returned -50 from: 0 ch, 8000 Hz, .... (0x00000000) 0 bits/channel, 0 bytes/packet, 0 frames/packet, 0 bytes/frame to: 1 ch, 8000 Hz, Int16 A subsequent attempt to load the file into AVAudioPlayer results in: MP4_BoxParser.cpp:1089 DataSource read failed MP4AudioFile.cpp:4365 MP4Parser_PacketProvider->GetASBD() failed AudioFileObject.cpp:105 OpenFromDataSource failed AudioFileObject.cpp:80 Open failed But that's not surprising given that it's only 500+ bytes and we had the earlier error. Anybody have an idea here? Every example on the Web shows essentially this exact method. I've also tried constructing the recorder with let audioFormat = AVAudioFormat.init(standardFormatWithSampleRate: 44100, channels: 1) if audioFormat == nil { print("Audio format failed.") } else { do { recorder = try AVAudioRecorder(url: tempFileURL(), format: audioFormat!) ... with mostly the same result. In that case the instantiation error message was the following, which at least mentions the requested sample rate: AudioQueueObject.cpp:1580 BuildConverter: AudioConverterNew returned -50 from: 0 ch, 44100 Hz, .... (0x00000000) 0 bits/channel, 0 bytes/packet, 0 frames/packet, 0 bytes/frame to: 1 ch, 44100 Hz, Int32
Posted Last updated
.
Post not yet marked as solved
0 Replies
200 Views
I need to duck the audio coming from ApplicationMusicPlayer while playing a local file using AVAudioPlayer. I've tried using the duckOthers option as follows, but it doesn't work: let appAudioSession = AVAudioSession.sharedInstance() do { try appAudioSession.setCategory(.playAndRecord, mode: .default, options: .duckOthers) Maybe this is because there's one session for the entire app, and ApplicationMusicPlayer is using it? This is a fairly critical problem for my application, since Music content is always much louder than locally recorded content. Any insight appreciated.
Posted Last updated
.
Post not yet marked as solved
3 Replies
309 Views
Let's say I have a class to represent a user: class User : Equatable, Codable, ObservableObject { @Published var ID: String = "" @Published var username: String = "" @Published var firstName: String = "" @Published var lastName: String = "" @Published var EMail: String = "" @Published var phoneNbr: String = "" @Published var avatarURL: String = "" @Published var mediaServiceID: String = "" @Published var validated: Bool = false ... } I also have a controller ("viewmodel") to broker interactions between SwiftUI views and the User. It contains a User object as: @MainActor class UserManager : ObservableObject { @Published var user: User ... } And finally of course the view, into which I pass the UserManager upon initialization: struct StartupView: View { @ObservedObject var userMgr: UserManager ... } Changing published members of the User embedded in UserManager does not trigger a UI refresh. That strikes me as broken, since everything is published. Is it expected behavior?
Posted Last updated
.
Post marked as solved
7 Replies
1k Views
Given that SwiftUI and modern programming idioms promote asynchronous activity, and observing a data model and reacting to changes, I wonder why it's so cumbersome in Swift at this point. Like many, I have run up against the problem where you perform an asynchronous task (like fetching data from the network) and store the result in a published variable in an observed object. This would appear to be an extremely common scenario at this point, and indeed it's exactly the one posed in question after question you find online about this resulting error: Publishing changes from background threads is not allowed Then why is it done? Why aren't the changes simply published on the main thread automatically? Because it isn't, people suggest a bunch of workarounds, like making the enclosing object a MainActor. This just creates a cascade of errors in my application; but also (and I may not be interpreting the documentation correctly) I don't want the owning object to do everything on the main thread. So the go-to workaround appears to be wrapping every potentially problematic setting of a variable in a call to DispatchQueue.main. Talk about tedious and error-prone. Not to mention unmaintainable, since I or some future maintainer may be calling a function a level or two or three above where a published variable is actually set. And what if you decide to publish a variable that wasn't before, and now you have to run around checking every potential change to it? Is this not a mess?
Posted Last updated
.
Post not yet marked as solved
2 Replies
296 Views
I'm wrestling with a view that handles a class whose members are mostly optional. This does not appear to be a scenario that SwiftUI envisions. What is the expected approach? Take this class, for example, which represents a user: class User : Equatable, Codable, ObservableObject { var ID: String? var pw: String? var username: String? var firstName: String? var lastName: String? var EMail: String? var phoneNbr: String? var avatarURL: String? var mediaServiceID: String? var validated: Bool = false ... } I can't directly show a form to fill this thing out in SwiftUI, because you can't bind text fields to optionals. Most of the published workarounds to that involve using let to create a non-optional variable if the member isn't nil; but this is unworkable because that won't populate a nil member if someone enters text in the text field. Apple docs talk about custom binding, which would probably work to populate an optional member. That means doing this in the SwiftUI view to set the object's username, for example: @State private var tempUser = User() private var username: Binding<String> { Binding { if let theName = tempUser.username { return theName } else { return "" } } set: { newName in tempUser.username = newName } } But that means setting up one of these verbose methods for every single optional member of every class I want to show in a UI. At that point I might as well just make a shadow structure that's all non-optionals that I can bind directly to. Or just make all the members non-optional and just face the fact that optionals are done with in the age of SwiftUI. Or is there some succinct approach I'm missing here? Thanks for any insight.
Posted Last updated
.
Post not yet marked as solved
2 Replies
385 Views
I encountered this in Apple's doc: Users must grant permission for your app to access their music data. Add the NSAppleMusicUsageDescription key to your app’s Info.plist file Info.plist is no longer generated as part of Xcode projects. Do we add a key like this to the app's .entitlements file instead?
Posted Last updated
.
Post not yet marked as solved
1 Replies
251 Views
I am trudging through the doc on the seemingly endless ways to expose model data through a view hierarchy. The Apple doc here provides this example: struct BookReaderApp: App { @State private var library = Library() var body: some Scene { WindowGroup { LibraryView() .environment(\.library, library) } } } Why would you do this? Is the Library at risk of being repeatedly destroyed and re-created? Also, Library is defined as an Observable class, not a struct. So why is it @State and not @StateObject?
Posted Last updated
.
Post not yet marked as solved
1 Replies
1.3k Views
I work on my project on two computers. One of them is older and stuck at Xcode 13. My project targets iOS 15+. Previously I was able to bounce back and forth between the two, checking code into source control in between. After doing a bunch of work on one of them over an extended period, I've returned to my older one and checked out the code... only to be unable to build because Xcode balks at every use of #Preview. I didn't change any project settings in the meantime, so I have no idea why this is suddenly a problem... Edit: It turns out that this is because previous versions of the SDK did not use this macro. Because I created a couple of new SwiftUI files on the newer OS and Xcode/SDK, it plopped #Preview into the new files instead of the previous implementation, PreviewProvider. I'll leave this post up for anyone who searches on this problem, since I found zero other references in a general Web search.
Posted Last updated
.
Post not yet marked as solved
0 Replies
541 Views
Hi all. I'm writing an app that targets iOS 15 and beyond. I can't build or test because Xcode complains that iOS 17 SDK is not installed, which is true. But my deployment target is set for 15.6. I installed a simulator for 15 by downloading iOS 15 simulator support from the Platforms tab in settings. This is also where you see that iOS SDKs there are... but there's no way to add them. The + button in the corner only lets you install more simulators. Where do you install support for earlier iOS versions? This is in Xcode 15.0.1. Thanks.
Posted Last updated
.
Post not yet marked as solved
2 Replies
1.4k Views
I have created certificates to test development locally with HTTPS. You used to be able to drag-&amp;-drop a certificate on the simulator, but this does not appear to work anymore. You can drag one onto the simulator and get the + drop symbol, but attempting to go into "VPN &amp; device management" to trust it under General settings just shows a blank screen that bounces you out immediately. Now what?
Posted Last updated
.
Post not yet marked as solved
0 Replies
789 Views
Our application is available for current and previous generations of Mac OS. But our QA team can't test it, because Apple has inexplicably blocked previous OSes from TestFlight. Does anyone have an explanation for this idiotic policy?
Posted Last updated
.
Post not yet marked as solved
0 Replies
574 Views
Our QA team is trying to test our application on all platforms we support, but Apple has inexplicably blocked installation of TestFlight on OS 11. Does anyone know the rationale behind this, or how we're supposed to distribute test builds in an orderly manner now? Having to make ad-hoc builds piecemeal and E-mail them around with duplicated instructions is not exactly professional. Thanks for any insight!
Posted Last updated
.