Post

Replies

Boosts

Views

Activity

Is it safe to put AVAudioSession calls not on main thread?
We have noticed that sometimes our app spends too much time in the first call of AVAudioSession.sharedInstance and [AVAudioSession setCategory:error:] which we call on app's initialization (during init of apps delegate). I am not sure if the app is stuck in these calls or it simply takes too much time to complete. This probably causes the app to crash due to main thread watchdog. Would it be safe to move these calls to a separate thread?
2
0
2.4k
Jan ’22
How to handle events by a view and then pass them to the view directly below?
I am trying to implement my own version of UIMenuController. One of the things I am struggling to imitate is what happens when a there is a touch event outside the menu. In this case the menu will be dismissed, but the event will also be passed to the correct view . So I need somehow to handle or capture the event in the menu or some transparent view covering the whole screen but also let it pass to the view below it. One idea is to override hitTest:withEvent: of the menu view, dismiss the menu when it is called (if point is outside the menu) and then return nil as if it was transparent to events. The issue is that hitTest:withEvent: must be pure function without side effect. On other hand, when touchesBegan:withEvent: is called, it is possible dismiss the menu and to pass the event to the nextResponder, but the view directly below the menu is not necessarily the superview of the menu view, so it is not part of the responder chain.
0
0
803
Oct ’21
Widget Extension Jetsamming when Loading SVG Images
To reproduce: Create a new standard iOS project and add a Widget extension to it. Download an SVG from here: https://pixabay.com/vectors/flourish-decorative-ornamental-3166119/ Add the SVG asset into Assets.xcassets. Replace the line Text(entry.date, style: .time) with Image("flourish-3166119").frame(width: 20). When running the extension, I get Thread 1: EXC_RESOURCE RESOURCE_TYPE_MEMORY (limit=30 MB, unused=0x0). Notice that the asset is only 8k but something in the rendering of the SVG into bitmap cause a memory spike. I tested this with Xcode 13.0, iOS 14.4.1 Xs MAX device. Is there a way to overcome this, or should I dump SVG and pre render the images for x2 and x3 scale factors and call it a day? Edit: Just to clarify, the issue happens with only 1 entry as well. I attached the full source for reference. Demo convenience:
1
0
1.5k
Sep ’21
How to write AVAudioBuffer to a file?
If the audio buffer is AVAudioPCMBuffer, it is possible to write it into a file using AVAudioFile's writeFromBuffer:error: method. How should plain AVAudioBuffer be handled? In my specific case, I get this buffer from the callback of AVSpeechSynthesizer's writeUtterance:toBufferCallback: In fact the documentation says: // Use this method to receive audio buffers that can be used to store or further process synthesized speech. // The dictionary provided by -[AVSpeechSynthesisVoice audioFileSettings] can be used to create an AVAudioFile. - (void)writeUtterance:(AVSpeechUtterance *)utterance toBufferCallback:(AVSpeechSynthesizerBufferCallback)bufferCallback API_AVAILABLE(ios(13.0), watchos(6.0), tvos(13.0), macos(10.15)) ; But I don't know how exactly AVAudioFile can be used if the buffer is not guaranteed to be an AVAudioPCMBuffer.
1
0
1.7k
Sep ’21
Why Xcode 12.5 errs when using Class as a key in NSDictionary?
I downloaded Xcode 12.5 Beta and now an existing project does not compile with errors telling I can't use Class as a key in NSDictionary. Cannot initialize a parameter of type 'id<NSCopying>  _Nonnull const __unsafe_unretained' with an rvalue of type 'Class' I have assumes so far that while Class does not conform to NSCopying, it is safe to use as a dictionary key because it implements copy and copyWithZone:. Did anything change with that regard in the compiler/runtime shipped with Xcode 12.5? Is it safe (and endorsed practice) to cast to id<NSCopying> to silence these errors?
6
0
4.2k
Feb ’21