Skip to content

Commit 57add0e

Browse files
author
zhaoyongqiang
committed
fix crash bug
1 parent 8722dc7 commit 57add0e

1 file changed

Lines changed: 9 additions & 9 deletions

File tree

macOS/APIExample/Examples/Advanced/ContentInspect/ContentInspect.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class ContentInspectViewController: BaseViewController {
3838
}
3939
}
4040

41-
var agoraKit: AgoraRtcEngineKit!
41+
var agoraKit: AgoraRtcEngineKit?
4242

4343

4444
// MARK: - LifeCycle
@@ -48,14 +48,14 @@ class ContentInspectViewController: BaseViewController {
4848
}
4949

5050
override func viewWillBeRemovedFromSplitView() {
51-
agoraKit.leaveChannel(nil)
51+
agoraKit?.leaveChannel(nil)
5252
AgoraRtcEngineKit.destroy()
5353
}
5454

5555
// MARK: - UI
5656
@IBAction func joinBtnClicked(_ sender: NSButton) {
5757
if isJoinChannel {
58-
agoraKit.leaveChannel(nil)
58+
agoraKit?.leaveChannel(nil)
5959
isJoinChannel = false
6060
return
6161
}
@@ -66,12 +66,12 @@ class ContentInspectViewController: BaseViewController {
6666
agoraKit = AgoraRtcEngineKit.sharedEngine(withAppId: KeyCenter.AppId, delegate: self)
6767
// Configuring Privatization Parameters
6868
Util.configPrivatization(agoraKit: agoraKit)
69-
agoraKit.enableVideo()
69+
agoraKit?.enableVideo()
7070

7171
let videoCanvas = AgoraRtcVideoCanvas()
7272
videoCanvas.view = localVideo.videocanvas
7373
videoCanvas.renderMode = .hidden
74-
agoraKit.setupLocalVideo(videoCanvas)
74+
agoraKit?.setupLocalVideo(videoCanvas)
7575

7676
// Enable content inspect with local video view
7777
let moderateModule = AgoraContentInspectModule()
@@ -80,13 +80,13 @@ class ContentInspectViewController: BaseViewController {
8080

8181
let inspectConfig = AgoraContentInspectConfig()
8282
inspectConfig.modules = [moderateModule]
83-
agoraKit.enableContentInspect(true, config:inspectConfig)
83+
agoraKit?.enableContentInspect(true, config:inspectConfig)
8484

8585
let options = AgoraRtcChannelMediaOptions()
8686
options.publishCameraTrack = true
8787
options.clientRoleType = .broadcaster
8888
NetworkManager.shared.generateToken(channelName: channelId, success: { token in
89-
let result = self.agoraKit.joinChannel(byToken: token, channelId: channelId, uid: 0, mediaOptions: options)
89+
let result = self.agoraKit?.joinChannel(byToken: token, channelId: channelId, uid: 0, mediaOptions: options)
9090
if result != 0 {
9191
// Usually happens with invalid parameters
9292
// Error code description can be found at:
@@ -153,7 +153,7 @@ extension ContentInspectViewController: AgoraRtcEngineDelegate {
153153
videoCanvas.uid = uid
154154
videoCanvas.view = remoteVideo.videocanvas
155155
videoCanvas.renderMode = .hidden
156-
agoraKit.setupRemoteVideo(videoCanvas)
156+
agoraKit?.setupRemoteVideo(videoCanvas)
157157
}
158158

159159
func rtcEngine(_ engine: AgoraRtcEngineKit, didOfflineOfUid uid: UInt, reason: AgoraUserOfflineReason) {
@@ -163,7 +163,7 @@ extension ContentInspectViewController: AgoraRtcEngineDelegate {
163163
let videoCanvas = AgoraRtcVideoCanvas()
164164
videoCanvas.view = nil
165165
videoCanvas.uid = uid
166-
agoraKit.setupRemoteVideo(videoCanvas)
166+
agoraKit?.setupRemoteVideo(videoCanvas)
167167
}
168168
}
169169

0 commit comments

Comments
 (0)