From e03f87886584e611ac512c4e55ebd0fe4fbd644d Mon Sep 17 00:00:00 2001 From: advplyr Date: Thu, 28 Apr 2022 18:05:33 -0500 Subject: [PATCH] iOS fix: Logging out when player is open crashing because server config is nil, added nil check in Api requests --- ios/App/Podfile | 14 +++++++------- ios/App/Shared/player/AudioPlayer.swift | 6 +++++- ios/App/Shared/util/ApiClient.swift | 12 ++++++++++++ 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/ios/App/Podfile b/ios/App/Podfile index 44119188..584acebb 100644 --- a/ios/App/Podfile +++ b/ios/App/Podfile @@ -9,13 +9,13 @@ install! 'cocoapods', :disable_input_output_paths => true def capacitor_pods pod 'Capacitor', :path => '../../node_modules/@capacitor/ios' pod 'CapacitorCordova', :path => '../../node_modules/@capacitor/ios' - pod 'CapacitorApp', :path => '..\..\node_modules\@capacitor\app' - pod 'CapacitorDialog', :path => '..\..\node_modules\@capacitor\dialog' - pod 'CapacitorHaptics', :path => '..\..\node_modules\@capacitor\haptics' - pod 'CapacitorNetwork', :path => '..\..\node_modules\@capacitor\network' - pod 'CapacitorStatusBar', :path => '..\..\node_modules\@capacitor\status-bar' - pod 'CapacitorStorage', :path => '..\..\node_modules\@capacitor\storage' - pod 'RobingenzCapacitorAppUpdate', :path => '..\..\node_modules\@robingenz\capacitor-app-update' + pod 'CapacitorApp', :path => '../../node_modules/@capacitor/app' + pod 'CapacitorDialog', :path => '../../node_modules/@capacitor/dialog' + pod 'CapacitorHaptics', :path => '../../node_modules/@capacitor/haptics' + pod 'CapacitorNetwork', :path => '../../node_modules/@capacitor/network' + pod 'CapacitorStatusBar', :path => '../../node_modules/@capacitor/status-bar' + pod 'CapacitorStorage', :path => '../../node_modules/@capacitor/storage' + pod 'RobingenzCapacitorAppUpdate', :path => '../../node_modules/@robingenz/capacitor-app-update' end target 'App' do diff --git a/ios/App/Shared/player/AudioPlayer.swift b/ios/App/Shared/player/AudioPlayer.swift index 88550c27..d088400e 100644 --- a/ios/App/Shared/player/AudioPlayer.swift +++ b/ios/App/Shared/player/AudioPlayer.swift @@ -67,6 +67,8 @@ class AudioPlayer: NSObject { destroy() } public func destroy() { + // Pause is not synchronous causing this error on below lines: + // AVAudioSession_iOS.mm:1206 Deactivating an audio session that has running I/O. All I/O should be stopped or paused prior to deactivating the audio session pause() audioPlayer.replaceCurrentItem(with: nil) @@ -77,9 +79,11 @@ class AudioPlayer: NSObject { print(error) } + // Throws error Possibly related to the error above // DispatchQueue.main.sync { - UIApplication.shared.endReceivingRemoteControlEvents() +// UIApplication.shared.endReceivingRemoteControlEvents() // } + NotificationCenter.default.post(name: NSNotification.Name(PlayerEvents.closed.rawValue), object: nil) } diff --git a/ios/App/Shared/util/ApiClient.swift b/ios/App/Shared/util/ApiClient.swift index ffe1ff27..2b3f06bd 100644 --- a/ios/App/Shared/util/ApiClient.swift +++ b/ios/App/Shared/util/ApiClient.swift @@ -10,6 +10,11 @@ import Alamofire class ApiClient { public static func postResource(endpoint: String, parameters: [String: String], decodable: T.Type = T.self, callback: ((_ param: T) -> Void)?) { + if (Store.serverConfig == nil) { + NSLog("Server config not set") + return + } + let headers: HTTPHeaders = [ "Authorization": "Bearer \(Store.serverConfig!.token)" ] @@ -25,6 +30,12 @@ class ApiClient { } } public static func postResource(endpoint: String, parameters: [String: String], callback: ((_ success: Bool) -> Void)?) { + if (Store.serverConfig == nil) { + NSLog("Server config not set") + callback?(false) + return + } + let headers: HTTPHeaders = [ "Authorization": "Bearer \(Store.serverConfig!.token)" ] @@ -43,6 +54,7 @@ class ApiClient { } public static func startPlaybackSession(libraryItemId: String, episodeId: String?, callback: @escaping (_ param: PlaybackSession) -> Void) { + var endpoint = "api/items/\(libraryItemId)/play" if episodeId != nil { endpoint += "/\(episodeId!)"