Swift 5.1 Error: [plugin] AddInstanceForFactory: No factory registered for id <CFUUID

前端 未结 7 2261
再見小時候
再見小時候 2021-02-12 10:41

App crashes with the following error message

2019-10-12 20:01:34.332334-0700 Awesome App[26368:3535170] [plugin] AddInstanceForFactory: No factory registered for         


        
7条回答
  •  孤独总比滥情好
    2021-02-12 10:49

    I believe you all might have added the AVFoundation to the frameworks list in Project General Info tab.

    Erroneous Code was as follows:

    import SwiftUI
    import AVFoundation
    
    struct PlayerDetailView: View {
    @State private var downloadedFilePath: URL = nil
    var audioPlayer: AVAudioPlayer
     
    var body: some View {
    

    And after I moved the var audioPlayer: AVAudioPlayer declaration to just after the line of import AVFoundation line it seemed to be working.

    So following code worked for me in a SwiftUI project:

    import SwiftUI
    import AVFoundation
    var audioPlayer: AVAudioPlayer!
    
    struct PlayerDetailView: View {
        @State private var downloadedFilePath: URL = nil
    
        var body: some View {
            VStack {
                Button("Play the Downloaded Track") {
                    if let downloadedPath = self.downloadedFilePath?.path, FileManager().fileExists(atPath: downloadedPath) {
                        do {
                            audioPlayer = try AVAudioPlayer(contentsOf: self.downloadedFilePath!)
                            guard let player = audioPlayer else { return }
    
                            player.prepareToPlay()
                            player.play()
                        } catch let error {
                            print(error.localizedDescription)
                        }
                    } else {
                        print("The file doesn not exist at path || may not have been downloaded yet")
                    }
                }
            }
        }
    }
    

    I was initially following this tutorial of CodeWithChris and its discussion also led to above change. Also checkout following tutorial too if you need further examples.

    Hope this will be helpful to someone of you out there!

    Cheers!

提交回复
热议问题