Post

Replies

Boosts

Views

Activity

Reply to PhotoKit request AddOnly authorization error:Domain=com.apple.photos.error Code=46104
Seems to work in iOS 15, so this is what I'm doing now: requestAuthorization {   /// got permissions } func requestAuthorization(completion: @escaping (() -> Void)) {   if #available(iOS 15, *) { /// works, so use `addOnly`     PHPhotoLibrary.requestAuthorization(for: .addOnly) { (status) in       if status == .authorized || status == .limited {         completion()       }     }   } else if #available(iOS 14, *) { /// use `readWrite` directly instead. This will ask for both read and write access, but at least it doesn't crash...     PHPhotoLibrary.requestAuthorization(for: .readWrite) { (status) in       if status == .authorized || status == .limited {         completion()       }     }   } else { /// for older iOS just do `requestAuthorization`     PHPhotoLibrary.requestAuthorization { (status) in       if status == .authorized {         completion()       }     }   } }
Sep ’21
Reply to "Failed to start launchd_sim: could not bind to session, launchd_sim may have crashed"
Here's some similar problems: When running on older iOS Simulator, error “Failed to start launchd_sim: could not bind to session, launchd_sim may have crashed or quit responding” - https://stackoverflow.com/q/65172944/14351818 (I asked) Simulator crashing with iOS < 14. Started happening since Big Sur - https://developer.apple.com/forums/thread/667921 iOS Simulator is Crashing on startup - https://stackoverflow.com/q/64071652/14351818
Dec ’20
Reply to Simulator crashing with iOS < 14. Started happening since Big Sur
Same here. Here's some similar problems: When running on older iOS Simulator, error “Failed to start launchd_sim: could not bind to session, launchd_sim may have crashed or quit responding” - https://stackoverflow.com/q/65172944/14351818 (I asked) "Failed to start launchd_sim: could not bind to session, launchd_sim may have crashed" - https://developer.apple.com/forums/thread/667088 iOS Simulator is Crashing on startup - https://stackoverflow.com/q/64071652/14351818
Dec ’20
Reply to DragGesture freezes when a second finger is added
Hey @Claude31, thanks for your help! It's now working if I do @GestureState private var isPressed = false ... let drag = DragGesture(minimumDistance: 0) .updating($isPressed) { (value, gestureState, transaction) in gestureState = true } return content .gesture(drag) .onChange(of: isPressed, perform: { (pressed) in if pressed { print("changed") } else { print("ended") } }) as suggested by someone else and also Apple. Here's the feedback Apple sent: Thank you for filing this feedback report. We reviewed your report and determined the behavior you experienced is currently functioning as intended. The gesture is cancelled in this case not ended (two fingers can't match a one-finger drag). You can use GestureState to handle the cancellation. You can close this feedback by clicking on the "Close Feedback" link. Thank you.
Sep ’20
Reply to VNRecognizeTextRequest doesn't recognize Dansk language "da-DK"
I think these are the currently supported languages (in iOS 14): [ "en-US" , "fr-FR" , "it-IT" , "de-DE" , "es-ES" , "pt-BR" , "zh-Hans" , "zh-Hant" ] Dansk isn't on there -- the most similar would probably be "de-DE" (German). And in iOS 13, the only supported language is "en-US". Check out this blog (it's in Japanese but you can use Google Translate) koze.hatenablog.jp/entry/2020/06/23/093000
Sep ’20
Reply to Crash When Exporting Video with Text Overlay
Yep, same crash here. I'm adding a CALayer that animates its width. libxpc.dylib`_xpc_api_misuse:   0x7fff522fe0b4 <+0>:  pushq %rbp   0x7fff522fe0b5 <+1>:  movq  %rsp, %rbp   0x7fff522fe0b8 <+4>:  pushq %rbx   0x7fff522fe0b9 <+5>:  subq  $0xa8, %rsp   0x7fff522fe0c0 <+12>: movq  %rdi, %r9   0x7fff522fe0c3 <+15>: movaps 0xdc06(%rip), %xmm0    ; __xpcVersionNumber + 160   0x7fff522fe0ca <+22>: leaq  -0xb0(%rbp), %rbx   0x7fff522fe0d1 <+29>: movaps %xmm0, 0x90(%rbx)   0x7fff522fe0d8 <+36>: movaps %xmm0, 0x80(%rbx)   0x7fff522fe0df <+43>: movaps %xmm0, 0x70(%rbx)   0x7fff522fe0e3 <+47>: movaps %xmm0, 0x60(%rbx)   0x7fff522fe0e7 <+51>: movaps %xmm0, 0x50(%rbx)   0x7fff522fe0eb <+55>: movaps %xmm0, 0x40(%rbx)   0x7fff522fe0ef <+59>: movaps %xmm0, 0x30(%rbx)   0x7fff522fe0f3 <+63>: movaps %xmm0, 0x20(%rbx)   0x7fff522fe0f7 <+67>: movaps %xmm0, 0x10(%rbx)   0x7fff522fe0fb <+71>: movaps %xmm0, (%rbx)   0x7fff522fe0fe <+74>: leaq  0x115ad(%rip), %r8    ; "XPC API Misuse: %s"   0x7fff522fe105 <+81>: movl  $0xa0, %esi   0x7fff522fe10a <+86>: movl  $0xa0, %ecx   0x7fff522fe10f <+91>: movq  %rbx, %rdi   0x7fff522fe112 <+94>: movl  $0x0, %edx   0x7fff522fe117 <+99>: xorl  %eax, %eax   0x7fff522fe119 <+101>: callq 0x7fff5230add8      ; symbol stub for: __snprintf_chk   0x7fff522fe11e <+106>: movq  %rbx, 0x37abe863(%rip)  ; gCRAnnotations + 8   0x7fff522fe125 <+113>: leaq  0x11599(%rip), %rax    ; "API Misuse"   0x7fff522fe12c <+120>: movq  %rax, 0x37abe85d(%rip)  ; gCRAnnotations + 16> 0x7fff522fe133 <+127>: ud2    I'm only getting this issue on the iOS 13.6 simulator, not on a real device.
Aug ’20
Reply to Add file to Swift Playground on Mac
If you're using the Swift Playgrounds app (for Mac and iPad)... You need to first add a sound file to the project: Press the “+” icon Tap the paper icon Tap Insert From… Insert a sound file from the Files app Then, if you're using SwiftUI: import AVFoundation import SwiftUI import PlaygroundSupport struct SwiftUIAudioPlayerView: View { &#9;&#9; &#9;&#9;/// the audio player that will play your audio file. Can't be a local variable. &#9;&#9;/// Must be a `@State` property because we need to modify it later &#9;&#9;@State var audioPlayer: AVAudioPlayer? &#9;&#9; &#9;&#9;var body: some View { &#9;&#9;&#9;&#9;Button(action: { &#9;&#9;&#9;&#9;&#9;&#9;self.playAudio() /// play audio when tapped &#9;&#9;&#9;&#9;}) { &#9;&#9;&#9;&#9;&#9;&#9;Text("Play Audio!") /// what the button looks like &#9;&#9;&#9;&#9;} &#9;&#9;} &#9;&#9; &#9;&#9;func playAudio() { /// function to play audio &#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9;/// the URL of the audio file. &#9;&#9;&#9;&#9;/// forResource = name of the file. &#9;&#9;&#9;&#9;/// withExtension = extension, usually "mp3" &#9;&#9;&#9;&#9;if let audioURL = Bundle.main.url(forResource: "slow-spring-board", withExtension: "mp3") { &#9;&#9;&#9;&#9;&#9;&#9;do { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;try self.audioPlayer = AVAudioPlayer(contentsOf: audioURL) /// make the audio player &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;self.audioPlayer?.numberOfLoops = 0 /// Number of times to loop the audio &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;self.audioPlayer?.play() /// start playing &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9;&#9;&#9;} catch { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;print("Couldn't play audio. Error: \(error)") &#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9;} else { &#9;&#9;&#9;&#9;&#9;&#9;print("No audio file found") &#9;&#9;&#9;&#9;} &#9;&#9;} } let swiftuiAudioPlayerView = SwiftUIAudioPlayerView() PlaygroundPage.current.setLiveView(swiftuiAudioPlayerView) ...or UIKit: import AVFoundation import SwiftUI import PlaygroundSupport class UIKitAudioPlayerView: UIView { &#9;&#9; &#9;&#9;/// the audio player that will play your audio file. Can't be a local variable. &#9;&#9;var audioPlayer: AVAudioPlayer? &#9;&#9; &#9;&#9;/// so we only make and connect the button once &#9;&#9;var hasLoadedView = false &#9;&#9;var audioButton = UIButton() &#9;&#9; &#9;&#9;/// the view is guarenteed to be loaded at `layoutSubviews()` &#9;&#9;override func layoutSubviews() { &#9;&#9;&#9;&#9;super.layoutSubviews() &#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9;if !hasLoadedView { &#9;&#9;&#9;&#9;&#9;&#9;hasLoadedView = true &#9;&#9;&#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9;&#9;&#9;audioButton.setTitle("Play Audio!", for: .normal) &#9;&#9;&#9;&#9;&#9;&#9;audioButton.setTitleColor(UIColor.blue, for: .normal) &#9;&#9;&#9;&#9;&#9;&#9;backgroundColor = .white &#9;&#9;&#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9;&#9;&#9;addSubview(audioButton) /// add the button to the view &#9;&#9;&#9;&#9;&#9;&#9;audioButton.addTarget(self, action: #selector(playAudio), for: .touchUpInside) &#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9;/// positioning (center-align the button) &#9;&#9;&#9;&#9;let middleXOfView = bounds.width / 2 &#9;&#9;&#9;&#9;let middleYOfView = bounds.height / 2 &#9;&#9;&#9;&#9;let buttonFrame = CGRect(x: middleXOfView - 60, y: middleYOfView - 20, width: 120, height: 40) &#9;&#9;&#9;&#9;audioButton.frame = buttonFrame &#9;&#9;} &#9;&#9; &#9;&#9;@objc func playAudio() { /// function to play audio &#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9;/// the URL of the audio file. &#9;&#9;&#9;&#9;/// forResource = name of the file. &#9;&#9;&#9;&#9;/// withExtension = extension, usually "mp3" &#9;&#9;&#9;&#9;if let audioURL = Bundle.main.url(forResource: "slow-spring-board", withExtension: "mp3") { &#9;&#9;&#9;&#9;&#9;&#9;do { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;try self.audioPlayer = AVAudioPlayer(contentsOf: audioURL) /// make the audio player &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;self.audioPlayer?.numberOfLoops = 0 /// Number of times to loop the audio &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;self.audioPlayer?.play() /// start playing &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9;&#9;&#9;} catch { &#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;print("Couldn't play audio. Error: \(error)") &#9;&#9;&#9;&#9;&#9;&#9;} &#9;&#9;&#9;&#9;&#9;&#9; &#9;&#9;&#9;&#9;} else { &#9;&#9;&#9;&#9;&#9;&#9;print("No audio file found") &#9;&#9;&#9;&#9;} &#9;&#9;} } let uikitAudioPlayerView = UIKitAudioPlayerView() PlaygroundPage.current.setLiveView(uikitAudioPlayerView) Replace "slow-spring-board" with the name of your sound file. The trick here is to use Bundle.main.url(forResource:withExtension:). You MUST do this. If you try adding a file literal via the “+” button (by tapping an already-imported file), it won’t work. - from a Medium article I'm writing on this topic (not published yet)
Jul ’20