0

I am facing crash in the following code only in iOS 11.2. I am using swift 4.0. I tried to debug for hours to reproduce the crash but could not succeed. Here is the code

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;
}

Here is crashlytics report.

enter image description here

I shall be very thankful for any help.

Fawad Masud
  • 12,219
  • 3
  • 25
  • 34

1 Answers1

0

please avoid safely unwrapping, use 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
}
rabeeh
  • 11
  • 3