如何解决“AddInstanceForFactory: No factory registered for id <CFUUID 0x600001bef9c0>”错误?

6
我正在学习https://github.com/LaiFengiOS/LFLiveKit/blob/master/samples/LFLiveKitSwiftDemo/LFLiveKitSwiftDemo/ViewController.swift的功能。
import UIKit
import LFLiveKit

class ViewController: UIViewController, LFLiveSessionDelegate {

  override func viewDidLoad() {
    super.viewDidLoad()

    session.delegate = self
    session.preView = self.view

    self.requestAccessForAudio()
    self.requestAccessForVideo()
    self.view.backgroundColor = UIColor.clear
    self.view.addSubview(containerView)
    containerView.addSubview(stateLabel)
    containerView.addSubview(closeButton)
    containerView.addSubview(beautyButton)
    containerView.addSubview(cameraButton)
    containerView.addSubview(startLiveButton)

    cameraButton.addTarget(self, action:  #selector(didTappedCameraButton(_:)), for: .touchUpInside)
    beautyButton.addTarget(self, action: #selector(didTappedBeautyButton(_:)), for: .touchUpInside)
    startLiveButton.addTarget(self, action: #selector(didTappedCloseButton(_:)), for: .touchUpInside)
  }

  override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
  }

  func requestAccessForAudio() -> Void {
    let status = AVCaptureDevice.authorizationStatus(for: AVMediaType.audio)
    switch status {
    case AVAuthorizationStatus.notDetermined:
      AVCaptureDevice.requestAccess(for: AVMediaType.audio, completionHandler: { ( granted ) in

      })
      break;
    case AVAuthorizationStatus.authorized: break;
    case AVAuthorizationStatus.denied: break;
    case AVAuthorizationStatus.restricted: break;
    default:
      break;
    }
  }

  func requestAccessForVideo() -> Void {
    let status = AVCaptureDevice.authorizationStatus(for: AVMediaType.video)
    switch status {
    case AVAuthorizationStatus.notDetermined:
      AVCaptureDevice.requestAccess(for: AVMediaType.video, completionHandler: { ( granted ) in
        if (granted) {
          DispatchQueue.main.async {
            self.session.running = true
          }
        }
      })
      break;
    case AVAuthorizationStatus.authorized:
      self.session.running = true
      break;

    case AVAuthorizationStatus.denied: break;
    case AVAuthorizationStatus.restricted: break;
    default:
      break;
    }
  }

  @objc func didTappedStartLiveButton(_ button: UIButton) -> Void {
    startLiveButton.isSelected = !startLiveButton.isSelected;
    if (startLiveButton.isSelected) {
      startLiveButton.setTitle("End Live", for: UIControl.State())
      let stream = LFLiveStreamInfo()
      stream.url = "rtmp://0.0.0.0:1935"
      session.startLive(stream)
    } else {
      startLiveButton.setTitle("Start Live", for: UIControl.State())
      session.stopLive()
    }
  }

  @objc func didTappedCameraButton(_ button: UIButton) -> Void {
    let devicePosition = session.captureDevicePosition;
    session.captureDevicePosition = (devicePosition == AVCaptureDevice.Position.back) ? AVCaptureDevice.Position.front : AVCaptureDevice.Position.back
  }

  @objc func didTappedBeautyButton(_ button: UIButton) -> Void {
    session.beautyFace = !session.beautyFace;
    beautyButton.isSelected = !session.beautyFace
  }

  @objc func didTappedCloseButton(_ button: UIButton) -> Void {
    // shut down
  }

  // Callback Functions
  func liveSession(_ session: LFLiveSession?, debugInfo: LFLiveDebug?) {
    print("debugInfo: \(String(describing: debugInfo?.currentBandwidth))")
  }

  func liveSession(_ session: LFLiveSession?, errorCode: LFLiveSocketErrorCode) {
    print("errorCode: \(errorCode.rawValue)")
  }

  func liveSession(_ session: LFLiveSession?, liveStateDidChange state: LFLiveState) {
      print("liveStateDidChange: \(state.rawValue)")
      switch state {
      case LFLiveState.ready:
          stateLabel.text = "Not Connected"
          break;
      case LFLiveState.pending:
          stateLabel.text = "Connecting..."
          break;
      case LFLiveState.start:
          stateLabel.text = "Connected"
          break;
      case LFLiveState.error:
          stateLabel.text = "Connection Error"
          break;
      case LFLiveState.stop:
          stateLabel.text = "Not Connected"
          break;
      default:
          break;
      }
  }

  var session: LFLiveSession = {
    let audioConfiguration = LFLiveAudioConfiguration.defaultConfiguration(for: LFLiveAudioQuality.high)
    let videoConfiguration = LFLiveVideoConfiguration.defaultConfiguration(for: LFLiveVideoQuality.low3)
    let session = LFLiveSession(audioConfiguration: audioConfiguration, videoConfiguration: videoConfiguration)
    return session!
  }()

  var containerView: UIView = {
    let containerView = UIView(
      frame: CGRect(
        origin: CGPoint(
          x: 0,
          y: 0
        ), size: CGSize(
          width: UIScreen.main.bounds.width,
          height: UIScreen.main.bounds.height
        )
      )
    )
    containerView.backgroundColor = UIColor.clear
    containerView.autoresizingMask = [
      .flexibleHeight, .flexibleHeight
    ]
    return containerView
  }()

  var stateLabel: UILabel = {
    let stateLabel = UILabel(
      frame: CGRect(
        origin: CGPoint(
          x: 20,
          y: 20
        ),
        size: CGSize(
          width: 80,
          height: 40
        )
      )
    )
    stateLabel.text = "Not Connected"
    stateLabel.textColor = UIColor.white
    stateLabel.font = UIFont.systemFont(ofSize: 14)
    return stateLabel
  }()

  var closeButton: UIButton = {
    let closeButton = UIButton(
      frame: CGRect(
        origin: CGPoint(
          x: UIScreen.main.bounds.width - 10 - 44,
          y: 20
        ),
        size: CGSize(
          width: 44,
          height: 44
        )
      )
    )
    closeButton.backgroundColor = UIColor.red
    return closeButton
  }()

  var cameraButton: UIButton = {
    let cameraButton = UIButton(
      frame: CGRect(
        origin: CGPoint(
          x: UIScreen.main.bounds.width - 54 * 2,
          y: 20
        ),
        size: CGSize(
          width: 44,
          height: 44
        )
      )
    )
    cameraButton.backgroundColor = UIColor.blue
    return cameraButton
  }()

  var beautyButton: UIButton = {
    let beautyButton = UIButton(
      frame: CGRect(
        origin: CGPoint(
          x: UIScreen.main.bounds.width - 54 * 3,
          y: 20
        ),
        size: CGSize(
          width: 44,
          height: 44
        )
      )
    )
    beautyButton.backgroundColor = UIColor.green
    return beautyButton
  }()

  var startLiveButton: UIButton = {
    let startLiveButton = UIButton(
      frame: CGRect(
        origin: CGPoint(
          x: 30,
          y: UIScreen.main.bounds.height - 50
        ),
        size: CGSize(
          width: UIScreen.main.bounds.width - 10 - 44,
          height: 44
        )
      )
    )
    startLiveButton.layer.cornerRadius = 22
    startLiveButton.setTitleColor(UIColor.black, for: UIControl.State())
    startLiveButton.setTitle("Start Streaming", for: UIControl.State())
    return startLiveButton
  }()
}

这是我写的一个程序,但它无法工作。

AddInstanceForFactory: No factory registered for id <CFUUID 0x600001bef9c0> F8BB1C28-BAE8-11D6-9C31-00039315CD46

在启动应用程序时,很快就会出现错误。
我已经检查过Swift 5.1错误:[plugin] AddInstanceForFactory:未注册id<CFUUID,但我没有使用AVAudioPlayer 我该如何解决?

LFLiveKit使用AVFoundation。 - Marcy
2个回答

5

"AddInstanceForFactory: No factory registered for id"

根据我的经验,这个消息只是表明正在使用模拟器。可以推测模拟器没有注册工厂ID。当在真实设备上运行时,此消息会消失。出现此消息时,AVFoundation框架被使用,而且似乎与任何崩溃或其他问题无直接关系。

尝试在真实设备上运行。


1

我曾经遇到过同样的问题。问题出在我为一个文本框使用的背景图片上,当我移除这张图片后问题得以解决。 如果你正在使用一张图片作为背景,请尝试将其移除并查看差异。 继续编码吧!


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接