diff --git a/SodaLive/Sources/App/AppViewModel.swift b/SodaLive/Sources/App/AppViewModel.swift index c542ff7..ee94163 100644 --- a/SodaLive/Sources/App/AppViewModel.swift +++ b/SodaLive/Sources/App/AppViewModel.swift @@ -18,32 +18,36 @@ final class AppViewModel: ObservableObject { DEBUG_LOG("fetchAndUpdateIdfa") ATTrackingManager.requestTrackingAuthorization { [unowned self] status in if status == .authorized { - let idfa = ASIdentifierManager.shared().advertisingIdentifier.uuidString - let pid = UserDefaults.string(forKey: .marketingPid) - self.userRepository.updateMarketingInfo(request: MarketingInfoUpdateRequest(adid: idfa, pid: pid)) - .sink { result in - switch result { - case .finished: - DEBUG_LOG("finish") - case .failure(let error): - ERROR_LOG(error.localizedDescription) + if !UserDefaults.string(forKey: UserDefaultsKey.token).trimmingCharacters(in: .whitespacesAndNewlines).isEmpty { + let idfa = ASIdentifierManager.shared().advertisingIdentifier.uuidString + let pid = UserDefaults.string(forKey: .marketingPid) + self.userRepository.updateMarketingInfo(request: MarketingInfoUpdateRequest(adid: idfa, pid: pid)) + .sink { result in + switch result { + case .finished: + DEBUG_LOG("finish") + case .failure(let error): + ERROR_LOG(error.localizedDescription) + } + } receiveValue: { _ in } - } receiveValue: { _ in - } - .store(in: &self.subscription) + .store(in: &self.subscription) + } } else { - let pid = UserDefaults.string(forKey: .marketingPid) - self.userRepository.updateMarketingInfo(request: MarketingInfoUpdateRequest(adid: "", pid: pid)) - .sink { result in - switch result { - case .finished: - DEBUG_LOG("finish") - case .failure(let error): - ERROR_LOG(error.localizedDescription) + if !UserDefaults.string(forKey: UserDefaultsKey.token).trimmingCharacters(in: .whitespacesAndNewlines).isEmpty { + let pid = UserDefaults.string(forKey: .marketingPid) + self.userRepository.updateMarketingInfo(request: MarketingInfoUpdateRequest(adid: "", pid: pid)) + .sink { result in + switch result { + case .finished: + DEBUG_LOG("finish") + case .failure(let error): + ERROR_LOG(error.localizedDescription) + } + } receiveValue: { _ in } - } receiveValue: { _ in - } - .store(in: &self.subscription) + .store(in: &self.subscription) + } } } }