From c20bf661027d504f7d8286cfb1ad0f4ffe324783 Mon Sep 17 00:00:00 2001 From: Abhijeet Ranjan Date: Tue, 29 Oct 2024 15:24:37 +0530 Subject: [PATCH] Updated the podspec file for ChatUI with or without Zendesk SDK and made the code of Zendesk SDK Optional --- Kommunicate.podspec | 17 ++++++++++++++--- .../Classes/KMConversationViewController.swift | 18 ++++++++++-------- Sources/Kommunicate/Classes/Kommunicate.swift | 4 ++++ 3 files changed, 28 insertions(+), 11 deletions(-) diff --git a/Kommunicate.podspec b/Kommunicate.podspec index c8eea2af..21cabf1a 100644 --- a/Kommunicate.podspec +++ b/Kommunicate.podspec @@ -8,7 +8,18 @@ Pod::Spec.new do |s| s.source = { :git => 'https://github.com/Kommunicate-io/Kommunicate-iOS-SDK.git', :tag => s.version } s.ios.deployment_target = '13.0' s.swift_version = '5.0' - s.source_files = 'Sources/Kommunicate/Classes/**/*.{swift}' - s.resources = 'Sources/Resources/**/*{lproj,storyboard,xib,xcassets,json,strings}' - s.dependency 'KommunicateChatUI-iOS-SDK' , '1.3.6' + + s.default_subspec = 'Complete' + + s.subspec 'Zendesk' do |with_zendesk| + with_zendesk.source_files = 'Sources/Kommunicate/Classes/**/*.{swift}' + with_zendesk.resources = 'Sources/Resources/**/*{lproj,storyboard,xib,xcassets,json,strings}' + with_zendesk.dependency 'KommunicateChatUI-iOS-SDK/Zendesk', '1.3.6' + end + + s.subspec 'Complete' do |complete| + complete.source_files = 'Sources/Kommunicate/Classes/**/*.{swift}' + complete.resources = 'Sources/Resources/**/*{lproj,storyboard,xib,xcassets,json,strings}' + complete.dependency 'KommunicateChatUI-iOS-SDK', '1.3.6' + end end diff --git a/Sources/Kommunicate/Classes/KMConversationViewController.swift b/Sources/Kommunicate/Classes/KMConversationViewController.swift index 44676e0e..50e0bf7a 100644 --- a/Sources/Kommunicate/Classes/KMConversationViewController.swift +++ b/Sources/Kommunicate/Classes/KMConversationViewController.swift @@ -516,13 +516,14 @@ open class KMConversationViewController: ALKConversationViewController, KMUpdate if let channelId = weakSelf.viewModel.channelKey { KMCustomEventHandler.shared.publish(triggeredEvent: KMCustomEvent.restartConversationClick, data: ["conversationId":channelId]) } - - guard let zendeskAcckountKey = ALApplozicSettings.getZendeskSdkAccountKey(), - !zendeskAcckountKey.isEmpty else { return } - // if zendesk is integrated, create a new conversation instead of restarting the conversation - let zendeskHandler = KMZendeskChatHandler.shared - zendeskHandler.resetConfiguration() - zendeskHandler.initiateZendesk(key: zendeskAcckountKey) + #if canImport(ChatProvidersSDK) + guard let zendeskAcckountKey = ALApplozicSettings.getZendeskSdkAccountKey(), + !zendeskAcckountKey.isEmpty else { return } + // if zendesk is integrated, create a new conversation instead of restarting the conversation + let zendeskHandler = KMZendeskChatHandler.shared + zendeskHandler.resetConfiguration() + zendeskHandler.initiateZendesk(key: zendeskAcckountKey) + #endif weakSelf.loadingStarted() // Create a new conversation let kmConversation = KMConversationBuilder() @@ -531,8 +532,9 @@ open class KMConversationViewController: ALKConversationViewController, KMUpdate Kommunicate.createConversation(conversation: kmConversation) { result in switch result { case .success(let conversationId): + #if canImport(ChatProvidersSDK) ALApplozicSettings.setLastZendeskConversationId(NSNumber(value: Int(conversationId) ?? 0)) - + #endif let convViewModel = ALKConversationViewModel(contactId: nil, channelKey: NSNumber(value: Int(conversationId) ?? 0), localizedStringFileName: Kommunicate.defaultConfiguration.localizedStringFileName, prefilledMessage: nil) // Update the View Model & refresh the View Controller weakSelf.updateViewModelAndRefreshViewController(convViewModel, conversationId: NSNumber(value: Int(conversationId) ?? 0)) diff --git a/Sources/Kommunicate/Classes/Kommunicate.swift b/Sources/Kommunicate/Classes/Kommunicate.swift index fe54df9b..ca3b74bd 100644 --- a/Sources/Kommunicate/Classes/Kommunicate.swift +++ b/Sources/Kommunicate/Classes/Kommunicate.swift @@ -403,7 +403,9 @@ open class Kommunicate: NSObject, Localizable { let applozicClient = applozicClientType.init(applicationKey: KMUserDefaultHandler.getApplicationKey()) applozicClient?.logoutUser(completion: { error, _ in Kommunicate.shared.clearUserDefaults() + #if canImport(ChatProvidersSDK) KMZendeskChatHandler.shared.endChat() + #endif guard error == nil else { completion(.failure(KMError.api(error))) return @@ -676,6 +678,7 @@ open class Kommunicate: NSObject, Localizable { - viewController: ViewController from which the group chat will be launched. */ open class func openZendeskChat(from: UIViewController,completion: @escaping (_ error: KommunicateError?) -> Void) { + #if canImport(ChatProvidersSDK) let zendeskHandler = KMZendeskChatHandler.shared guard let accountKey = ALApplozicSettings.getZendeskSdkAccountKey(), !accountKey.isEmpty else { completion(.zendeskKeyNotPresent) @@ -735,6 +738,7 @@ open class Kommunicate: NSObject, Localizable { bool == true ? completion(nil) : completion(.conversationOpenFailed) print("Opening Existing conversation which is assigned to BOT") }) + #endif } /**