Post

Replies

Boosts

Views

Activity

Downloaded certificates not showing up in Certificate Trust Authority
Under iOS 18.0.1, I can't do any development that uses HTTPS, because I can't authorize my generated certificates on my phone. This was not a problem in the past. Normally you AirDrop a root certificate authority to your phone, install the "profile" for it, and then trust it in Settings / General / About / Certificate Trust Authority. Then you can connect to another server on your network that's using the accompanying certificates. But after sucessfully installing two profiles on my phone, neither shows up in Certificate Trust Authority. Anybody else seeing this? This problem, in combo with this one (which prevents running on my Mac as an iPad app) has completely halted my project. I've found reports of this problem that blamed an empty "common name" field in the certs, but that field is populated in both of these.
3
1
496
Oct ’24
App crashes at launch on missing symbol AVPlayerView... except on first launch
I don't know what triggered this in a previously-running application I'm developing: When I have the build target set to "My Mac (designed for iPad)," I now must delete all the app's build materials under DerivedData to get the app to build and run exactly once. Cleaning isn't enough; I have to delete everything. On second launch, it will crash without even getting to the instantiation of the application class. None of my code executes. Also: If I then set my iPhone as the build target, the app will build and run repeatedly. If I then return to "My Mac (designed for iPad)," the app will again launch once and then crash on every subsequent launch. The crash is the same every time: dyld[3875]: Symbol not found: _OBJC_CLASS_$_AVPlayerView Referenced from: <D566512D-CAB4-3EA6-9B87-DBD15C6E71B3> /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Debugger/libViewDebuggerSupport.dylib Expected in: <4C34313C-03AD-32EB-8722-8A77C64AB959> /System/iOSSupport/System/Library/Frameworks/AVKit.framework/Versions/A/AVKit Interestingly, I haven't found any similar online reports that mention this symbol. Has anyone seen this behavior before, where the crash only happens after the first run... and gets reset when you toggle the target type?
6
0
504
Oct ’24
MacOS "Made for iPad" builds are not being updated by Xcode
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).
0
0
448
Apr ’24
Why is AVAudioRecorder creating corrupt files?
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
1
1
1.1k
Mar ’24
How do you control the volume of ApplicationMusicPlayer?
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.
0
0
517
Mar ’24
Are changes to published embedded objects really not detected in SwiftUI?
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?
3
0
729
Jan ’24
SwiftUI seems to assume that no one uses optionals anymore.
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.
2
1
894
Jan ’24
Why would you use @State at the application level, or anywhere outside SwiftUI?
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?
1
0
468
Dec ’23
All of a sudden Xcode says "Use of unknown directive #Preview" in SwiftUI
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.
1
2
2.2k
Dec ’23
Why aren't changes to @Published variables automatically published on the main thread?
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?
9
0
2.6k
Nov ’23
How do we install older iOS SDKs in Xcode?
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.
1
3
1.3k
Oct ’23
How do you put a self-signed certificate on iOS 17 simulator?
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?
2
0
2.7k
Oct ’23