From 656cc451d9aa648c80de556fad4a24ff2cfa5f95 Mon Sep 17 00:00:00 2001 From: Morgan Chen Date: Sat, 15 Mar 2025 19:04:56 +0800 Subject: [PATCH] Fix KVSSigner iso8601() issue with 12-hour format If the phone's time format is set to a 12-hour system, the iso8601() method in KVSSigner returns a timestamp with a space, e.g., "20250315T73633 AMZ". This causes a crash at line 147 in KVSSigner, where components.percentEncodedQueryItems = queryParamsBuilderArray. This issue has been fixed. --- .../KVSiOSApp/ChannelConfigurationViewController.swift | 10 ++++++++++ Swift/KVSiOSApp/KVSSigner.swift | 3 +++ 2 files changed, 13 insertions(+) diff --git a/Swift/KVSiOSApp/ChannelConfigurationViewController.swift b/Swift/KVSiOSApp/ChannelConfigurationViewController.swift index 8fee8fd..e3362d0 100755 --- a/Swift/KVSiOSApp/ChannelConfigurationViewController.swift +++ b/Swift/KVSiOSApp/ChannelConfigurationViewController.swift @@ -170,7 +170,17 @@ class ChannelConfigurationViewController: UIViewController, UITextFieldDelegate } // get signalling channel endpoints let endpoints = getSignallingEndpoints(channelARN: channelARN!, region: awsRegionValue, isMaster: self.isMaster, useMediaServer: usingMediaServer) + //// Ensure that the WebSocket (WSS) endpoint is available; WebRTC requires a valid signaling endpoint. + if endpoints["WSS"] == nil { + popUpError(title: "Invalid SignallingEndpoints", message: "SignallingEndpoints is required for WebRTC connection") + return + } let wssURL = createSignedWSSUrl(channelARN: channelARN!, region: awsRegionValue, wssEndpoint: endpoints["WSS"]!, isMaster: self.isMaster) + // Ensure that the signed WebSocket URL is successfully created; a valid signed URL is required to establish a WebRTC connection. + if wssURL == nil { + popUpError(title: "Failed to create signed WSSUrl", message: "SignedWSSUrl is required for WebRTC connection") + return + } print("WSS URL :", wssURL?.absoluteString as Any) // get ice candidates using https endpoint let httpsEndpoint = diff --git a/Swift/KVSiOSApp/KVSSigner.swift b/Swift/KVSiOSApp/KVSSigner.swift index 5ea7bf2..e1ad3b4 100755 --- a/Swift/KVSiOSApp/KVSSigner.swift +++ b/Swift/KVSiOSApp/KVSSigner.swift @@ -63,6 +63,8 @@ class KVSSigner { static func iso8601() -> (fullDateTimestamp: String, shortDate: String) { let dateFormatter: DateFormatter = DateFormatter() dateFormatter.dateFormat = utcDateFormatter + // Ensures the date format is consistent regardless of the device's regional settings, preventing issues with 12-hour vs. 24-hour time formats. + dateFormatter.locale = Locale(identifier: "en_US_POSIX") dateFormatter.timeZone = TimeZone(abbreviation: utcTimezone) let date = Date() let dateString = dateFormatter.string(from: date) @@ -143,6 +145,7 @@ class KVSSigner { queryParamsBuilderArray.append(URLQueryItem(name: xAmzSignature, value: signature)) if #available(iOS 11.0, *) { + // ensuring that special characters (such as spaces in timestamps) are handled correctly. components.percentEncodedQueryItems = queryParamsBuilderArray } else {