I’m developing with swiftUI and zoom-sdk-ios-5.13.1.6095.
I implemented fundamental function in UIViewControllerRepresentable and called the Controller in View like:
VStack {
ZoomController()
}
Then I got error message Unbalanced calls to begin/end appearance transitions for <ZMRootNavigationController: 0x10f03ba00>. and even AVCaptureDevice.requestAccess seems not working properly
I copied and pasted code that other developer wrote in this forum.
import Foundation
import SwiftUI
import MobileRTC
import AVFoundation
struct StartZoomVC: UIViewControllerRepresentable {
@Binding var meetingNumber: String
@Binding var passCode: String
let newVC = UIViewController()
private let delegate: MobileRTCMeetingServiceDelegate
//private let authDelegate: MobileRTCAuthDelegate
init(delegate: MobileRTCMeetingServiceDelegate, zoomMeetingNumber: Binding<String>, zoomPasscode: Binding<String>) {
self._meetingNumber = zoomMeetingNumber
self._passCode = zoomPasscode
self.delegate = delegate
}
func makeUIViewController(context: Context) -> UIViewController {
newVC.view.tag = 83838383
newVC.view.backgroundColor = .white
MobileRTC.shared().setMobileRTCRootController(newVC.navigationController)
return newVC
}
func updateUIViewController(_ taskViewController: UIViewController, context: Context) {
askPermissionsForCameraFeed()
print("check video permissions")
}
func askPermissionsForCameraFeed() {
AVCaptureDevice.requestAccess(for: AVMediaType.video) { response in
if response {
//access granted
getMainWindowToShareWithAppDelegate()
} else {
print("wtf")
}
}
}
func getMainWindowToShareWithAppDelegate(){
DispatchQueue.main.async {
// let scene = UIApplication.shared.connectedScenes.first
// let windowSceneDelegate = scene?.delegate as? UIWindowSceneDelegate
// let window = (windowSceneDelegate?.window)!
// let delegate = UIApplication.shared.delegate as! AppDelegate
// delegate.window = window
// print("finding window to provide to zoom sdk")
// print(meetingNumber)
// print(passCode)
joinMeeting(meetingNumber: meetingNumber, meetingPassword: passCode)
}
}
func startMeeting() {
// 5. Obtain the MobileRTCMeetingService from the Zoom SDK, this service can start meetings, join meetings, leave meetings, etc.
if let meetingService = MobileRTC.shared().getMeetingService() {
//6. Set the ViewContoller to be the MobileRTCMeetingServiceDelegate
meetingService.delegate = delegate
/*** 5. Create a MobileRTCMeetingStartParam to provide the MobileRTCMeetingService with the necessary info to start an instant meeting. In this case we will use MobileRTCMeetingStartParam4LoginlUser(), since the user has logged into Zoom. ***/
let startMeetingParameters = MobileRTCMeetingStartParam4LoginlUser()
// 6. Call the startMeeting function in MobileRTCMeetingService. The Zoom SDK will handle the UI for you, unless told otherwise.
meetingService.startMeeting(with: startMeetingParameters)
}
}
/*func logIn(email: String, password: String) {
// 2. Obtain the MobileRTCAuthService from the Zoom SDK, this service can log in a Zoom user, log out a Zoom user, authorize the Zoom SDK etc.
if let authorizationService = MobileRTC.shared().getAuthService() {
// 3. Call the login function in MobileRTCAuthService. This will attempt to log in the user.
//authorizationService.login(withEmail: email, password: password, rememberMe: false)
}else {
print("authorization service failed")
}
}*/
func joinMeeting(meetingNumber: String, meetingPassword: String) {
// Obtain the MobileRTCMeetingService from the Zoom SDK, this service can start meetings, join meetings, leave meetings, etc.
if let meetingService = MobileRTC.shared().getMeetingService() {
// Create a MobileRTCMeetingJoinParam to provide the MobileRTCMeetingService with the necessary info to join a meeting.
// In this case, we will only need to provide a meeting number and password.
// 2. Set the ViewContoller to be the MobileRTCMeetingServiceDelegate
meetingService.delegate = delegate
let joinMeetingParameters = MobileRTCMeetingJoinParam()
joinMeetingParameters.meetingNumber = meetingNumber
joinMeetingParameters.password = meetingPassword
MobileRTC.shared().getMeetingSettings()?.disableShowVideoPreview(whenJoinMeeting: true)
MobileRTC.shared().getMeetingSettings()?.enableCustomMeeting = false
if #available(iOS 13.0, *) {
// 13.0 and above
//MobileRTC.shared().setMobileRTCRootController(self.newVC as? UINavigationController)
}
// Call the joinMeeting function in MobileRTCMeetingService. The Zoom SDK will handle the UI for you, unless told otherwise.
// If the meeting number and meeting password are valid, the user will be put into the meeting. A waiting room UI will be presented or the meeting UI will be presented.
DispatchQueue.main.async {
meetingService.joinMeeting(with: joinMeetingParameters)
}
}
}
}
extension StartZoomVC {
class Delegate: NSObject, MobileRTCMeetingServiceDelegate {
func onMeetingError(_ error: MobileRTCMeetError, message: String?) {
switch error {
case .passwordError:
print("Could not join or start meeting because the meeting password was incorrect.")
case .success:
print("onMeetingError : MobileRTCMeetError_Success")
default:
print("Could not join or start meeting with MobileRTCMeetError: \(error) \(message ?? "")")
}
}
func onMeetingEndedReason(_ reason: MobileRTCMeetingEndReason) {
print("Join meeting end reason.")
}
// Is called when the user joins a meeting.
func onJoinMeetingConfirmed() {
print("Join meeting confirmed.")
if let meetingService = MobileRTC.shared().getMeetingService() {
meetingService.meetingView()
print("what am I seeing !")
}
}
// Is called upon meeting state changes.
func onMeetingStateChange(_ state: MobileRTCMeetingState) {
print("onMeetingStateChange")
print(state)
switch state {
case .connecting:
print("Connecting")
case .disconnecting:
print("disconnecting")
case .ended:
print("ended")
case .failed:
print("failed")
case .idle:
print("idle")
case .inMeeting:
print("in meeting")
case .inWaitingRoom:
print("in waiting room")
case .joinBO:
print("join bo")
case .leaveBO:
print("leave bo")
case .locked:
print("locked")
case .reconnecting:
print("reconnecting")
case .unknow:
print("unknown")
case .unlocked:
print("unlocked")
case .waitingForHost:
print("waiting for host")
case .webinarDePromote:
print("de promote")
case .webinarPromote:
print("promote")
default:
print("bad things happened")
}
}
}
}
Please help me to make it perfect in SwiftUI.
Thanks for your help.