0

我仅在 iOS 11.2 中面临以下代码崩溃。我正在使用 swift 4.0。我试图调试几个小时以重现崩溃但未能成功。这是代码

func prepareNewConnection(conn:String) -> RTCPeerConnection {

    let uuid = UIDevice.current.identifierForVendor?.uuidString

    localAudioTrack = peerConnectionFactory.audioTrack(withTrackId: uuid!)

        mediaStream = peerConnectionFactory.mediaStream(withStreamId: LOCAL_MEDIA_STREAM_ID)
        if(localAudioTrack != nil && mediaStream != nil)
        {
            mediaStream.addAudioTrack(localAudioTrack!) //Crash on this line
        }

    let pc = peerConnectionFactory.peerConnection(with: rtcConfig, constraints: mediaConstraints, delegate: self)
    if(mediaStream != nil)
    {
        pc.add(mediaStream)
    }

return pc;
}

这是崩溃分析报告。

在此处输入图像描述

我将非常感谢任何帮助。

4

1 回答 1

0

请避免安全打开包装,使用 if let ..

 func prepareNewConnection(conn:String) -> RTCPeerConnection {

   if let uuid = UIDevice.current.identifierForVendor?.uuidString {
localAudioTrack = peerConnectionFactory.audioTrack(withTrackId: uuid) //removed safely Unwrapping
    mediaStream = peerConnectionFactory.mediaStream(withStreamId: LOCAL_MEDIA_STREAM_ID)
 let pc = peerConnectionFactory.peerConnection(with: rtcConfig,constraints: mediaConstraints, delegate: self)
    if(localAudioTrack != nil && mediaStream != nil)
    {
        mediaStream.addAudioTrack(localAudioTrack)
        pc.add(mediaStream) 
    }
  }
 return pc
}
于 2018-08-03T16:02:39.720 回答