Solving the Zoom Meeting SDK Upgrade Issue with JWT Token and SDK Initialization

 Introduction:

If you're facing issues with upgrading the Zoom meeting SDK in your iOS app, don't worry! In this tutorial, we'll walk you through the steps to solve the Zoom meeting SDK upgrade issue by generating a JWT (JSON Web Token) and initializing the SDK in Swift. Let's get started!

Step 1: Set Up Zoom Meeting SDK Credentials To begin, make sure you have your Zoom meeting SDK credentials ready. You'll need the client ID and client secret provided by Zoom. If you don't have these credentials yet, you can obtain them from the Zoom Developer Portal - by creating Zoom meeting sdk app from Zoom market place . and save the credentials.

Add zoom sdk files to your project - 1. MobileRTC 2.MobileRTCResource.bundle
Step 2: Generate JWT Token Next, we'll generate a JWT token using the Zoom meeting SDK credentials. This token will be used for authentication and SDK initialization. Here's a code snippet that demonstrates how to generate the JWT token in Swift:
Make sure to replace clientId and clientSecret with your actual Zoom meeting SDK credentials. You can customize the generateSignature function to include any additional payload information you need.
just paste this code in your app delegate file - with your own credentials .


import UIKit

import MobileRTC

import CryptoKit




@main

class AppDelegate: UIResponder, UIApplicationDelegate, MobileRTCAuthDelegate {

    

    

    let clientId = "Your Client ID"

    let clientSecret = "Your Client Secrete"

    

    func onMobileRTCAuthReturn(_ returnValue: MobileRTCAuthError) {

        if returnValue == MobileRTCAuthError.success {

            // Zoom SDK authentication success

           // print("Zoom SDK initiated successfully")

            // You can perform further operations here

        } else {

            // Zoom SDK authentication failure

            // Handle the error appropriately

        }

    }

    

    func generateSignature(key: String, secret: String, meetingNumber: Int, role: Int) -> String? {

        let iat = Int(Date().timeIntervalSince1970) - 30

        let exp = iat + 60 * 60 * 2

        

        let header = """

        {

            "alg": "HS256",

            "typ": "JWT"

        }

        """

        

        let payload = """

        {

            "appKey": "\(key)",

            "iat": \(iat),

            "exp": \(exp),

            "tokenExp": \(exp),

            "userID": "1234567890",

            "userName": "John Doe"

        }

        """

        

        guard let headerData = header.data(using: .utf8),

              let payloadData = payload.data(using: .utf8) else {

            return nil

        }

        

        let base64UrlEncodedHeader = headerData.base64EncodedString()

            .replacingOccurrences(of: "+", with: "-")

            .replacingOccurrences(of: "/", with: "_")

            .replacingOccurrences(of: "=", with: "")

        

        let base64UrlEncodedPayload = payloadData.base64EncodedString()

            .replacingOccurrences(of: "+", with: "-")

            .replacingOccurrences(of: "/", with: "_")

            .replacingOccurrences(of: "=", with: "")

        

        let signatureData = HMAC<SHA256>.authenticationCode(for: (base64UrlEncodedHeader + "." + base64UrlEncodedPayload).data(using: .utf8)!, using: SymmetricKey(data: secret.data(using: .utf8)!))

        

        let base64UrlEncodedSignature = Data(signatureData).base64EncodedString()

            .replacingOccurrences(of: "+", with: "-")

            .replacingOccurrences(of: "/", with: "_")

            .replacingOccurrences(of: "=", with: "")

        

        let jwtToken = "\(base64UrlEncodedHeader).\(base64UrlEncodedPayload).\(base64UrlEncodedSignature)"

        return jwtToken

    }

    

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

        let key = clientId

        let secret = clientSecret

        let meetingNumber = 123456789

        let role = 0

        

        if let jwtToken = generateSignature(key: key, secret: secret, meetingNumber: meetingNumber, role: role) {

            print("JWT Token: \(jwtToken)")

            

            // Initiate Zoom SDK

            let context = MobileRTCSDKInitContext()

            context.domain = "zoom.us" // Set the domain as "zoom.us" or your Zoom instance domain

            context.enableLog = true // Enable or disable SDK logs as per your requirement

            

            // Set the JWT token

            let authService = MobileRTC.shared().getAuthService()

            authService?.delegate = self


            

            print("Zoom SDK initiated successfully") // This line should be executed upon successful initialization.

            

        } else {

            print("Failed to generate JWT token")

        }

        

        return true

    }

    

    // MARK: MobileRTCMeetingServiceDelegate

    

    func onMeetingError(_ error: MobileRTCMeetError, message: String?) {

        // Handle meeting errors

    }

    

    // Implement other delegate methods as needed

}




Conclusion: By following the steps outlined in this tutorial, you should now be able to solve the Zoom meeting SDK upgrade issue using a JWT token and SDK initialization in your iOS app. This approach ensures smooth integration and compatibility with the latest version of the Zoom meeting SDK.

Remember to handle any errors or edge cases specific to your application. Happy coding and enjoy your upgraded Zoom meeting experience!


Feel free to modify and enhance this blog post template to fit your writing style and specific details about the problem and solution you encountered.




Comments