diff --git a/AffiseAttributionLib.podspec b/AffiseAttributionLib.podspec index 1610026..123f049 100644 --- a/AffiseAttributionLib.podspec +++ b/AffiseAttributionLib.podspec @@ -5,7 +5,7 @@ Pod::Spec.new do |spec| spec.name = "AffiseAttributionLib" - spec.version = ENV['LIB_VERSION'] || "1.6.34" + spec.version = ENV['LIB_VERSION'] || "1.6.35" spec.summary = "Affise Attribution iOS library" spec.description = "Affise SDK is a software you can use to collect app usage statistics, device identifiers, deeplink usage, track install referrer." spec.homepage = "https://github.com/affise/sdk-ios" diff --git a/AffiseAttributionLib/Classes/AffiseComponent.swift b/AffiseAttributionLib/Classes/AffiseComponent.swift index 14b04d6..346025b 100644 --- a/AffiseAttributionLib/Classes/AffiseComponent.swift +++ b/AffiseAttributionLib/Classes/AffiseComponent.swift @@ -36,7 +36,9 @@ internal class AffiseComponent: AffiseApi { dependencies: [ stringToSha256Converter, networkService, - providersToJsonStringConverter + providersToJsonStringConverter, + postBackModelFactory, + postBackModelToJsonStringConverter ] ) @@ -90,10 +92,11 @@ internal class AffiseComponent: AffiseApi { eventsStorage: internalEventsStorage ) lazy var networkService:NetworkService = NetworkServiceImpl(urlSession: urlSession) + lazy var postBackModelToJsonStringConverter:PostBackModelToJsonStringConverter = PostBackModelToJsonStringConverter() lazy var cloudRepository:CloudRepository = CloudRepositoryImpl( networkService: networkService, userAgentProvider: postBackModelFactory.getProvider(), - converter: PostBackModelToJsonStringConverter() + converter: postBackModelToJsonStringConverter ) lazy var sessionManager:SessionManager = SessionManagerImpl( preferences: preferences, diff --git a/AffiseAttributionLib/Classes/converter/Converter.swift b/AffiseAttributionLib/Classes/converter/Converter.swift index ef9e523..f8d5907 100644 --- a/AffiseAttributionLib/Classes/converter/Converter.swift +++ b/AffiseAttributionLib/Classes/converter/Converter.swift @@ -1,11 +1,3 @@ -// -// Converter.swift -// app -// -// Created by Sergey Korney -// - - /** * Interface for convert object to another object * diff --git a/AffiseAttributionLib/Classes/converter/PostBackModelToJsonStringConverter.swift b/AffiseAttributionLib/Classes/converter/PostBackModelToJsonStringConverter.swift index 3d45a55..2572a21 100644 --- a/AffiseAttributionLib/Classes/converter/PostBackModelToJsonStringConverter.swift +++ b/AffiseAttributionLib/Classes/converter/PostBackModelToJsonStringConverter.swift @@ -1,10 +1,10 @@ /** * Converter List to String */ -class PostBackModelToJsonStringConverter : Converter { +public class PostBackModelToJsonStringConverter : Converter { - typealias T = Array - typealias R = String + public typealias T = Array + public typealias R = String private let EVENTS_KEY = "events" private let SDK_EVENTS_KEY = "sdk_events" @@ -14,7 +14,7 @@ class PostBackModelToJsonStringConverter : Converter { /** * Convert [from] list of PostBackModel to json string */ - func convert(from: Array) -> String { + public func convert(from: Array) -> String { let res = from.map { model in parameters(obj: model) }.joined(separator: ",") diff --git a/AffiseAttributionLib/Classes/events/base/SerializedEvent.swift b/AffiseAttributionLib/Classes/events/base/SerializedEvent.swift index c11feae..f742a98 100644 --- a/AffiseAttributionLib/Classes/events/base/SerializedEvent.swift +++ b/AffiseAttributionLib/Classes/events/base/SerializedEvent.swift @@ -1,7 +1,7 @@ /** * Serialized event to store */ -struct SerializedEvent { +public struct SerializedEvent { /** * Event id */ diff --git a/AffiseAttributionLib/Classes/internal/BuildConfig.swift b/AffiseAttributionLib/Classes/internal/BuildConfig.swift index 8efe90b..23c3ac0 100644 --- a/AffiseAttributionLib/Classes/internal/BuildConfig.swift +++ b/AffiseAttributionLib/Classes/internal/BuildConfig.swift @@ -1,5 +1,5 @@ import Foundation internal struct BuildConfig { - static let AFFISE_VERSION = "1.6.34" + static let AFFISE_VERSION = "1.6.35" } diff --git a/AffiseAttributionLib/Classes/logs/SerializedLog.swift b/AffiseAttributionLib/Classes/logs/SerializedLog.swift index 4629dec..18a5b96 100644 --- a/AffiseAttributionLib/Classes/logs/SerializedLog.swift +++ b/AffiseAttributionLib/Classes/logs/SerializedLog.swift @@ -1,15 +1,7 @@ -// -// SerializedLog.swift -// app -// -// Created by Sergey Korney -// - - /** * Serialized log contains [id] identification, [type] and log [data] */ -struct SerializedLog{ +public struct SerializedLog{ /** * Log id diff --git a/AffiseAttributionLib/Classes/modules/exceptions/AffiseModuleError.swift b/AffiseAttributionLib/Classes/modules/exceptions/AffiseModuleError.swift index ee32943..7216f18 100644 --- a/AffiseAttributionLib/Classes/modules/exceptions/AffiseModuleError.swift +++ b/AffiseAttributionLib/Classes/modules/exceptions/AffiseModuleError.swift @@ -1,7 +1,8 @@ import Foundation -enum AffiseModuleError: Error { +public enum AffiseModuleError: Error { case version(name: AffiseModules, module: AffiseModule) + case initModule(name: AffiseModules) } extension AffiseModuleError : LocalizedError { @@ -9,6 +10,8 @@ extension AffiseModuleError : LocalizedError { switch self { case .version(name: let name, module: let module): return NSLocalizedString("AffiseModuleError.version(module [\(name.description.lowercased()):\(module.version)] version is incompatible with [attribution:\(BuildConfig.AFFISE_VERSION)], use same version as attribution)", comment: "") + case .initModule(name: let name): + return NSLocalizedString("module [\(name.description)] init failed", comment: "") } } } diff --git a/AffiseAttributionLib/Classes/network/CloudRepositoryImpl.swift b/AffiseAttributionLib/Classes/network/CloudRepositoryImpl.swift index b1d40cc..e1f5943 100644 --- a/AffiseAttributionLib/Classes/network/CloudRepositoryImpl.swift +++ b/AffiseAttributionLib/Classes/network/CloudRepositoryImpl.swift @@ -48,7 +48,7 @@ extension CloudRepositoryImpl: CloudRepository { //Create request let response = createRequest(url: url, data: data) - if isHttpValid(response.code) { + if response.isHttpValid() { //Send is ok send = true } else { diff --git a/AffiseAttributionLib/Classes/network/entity/PostBackModel.swift b/AffiseAttributionLib/Classes/network/entity/PostBackModel.swift index d7a0211..78991b4 100644 --- a/AffiseAttributionLib/Classes/network/entity/PostBackModel.swift +++ b/AffiseAttributionLib/Classes/network/entity/PostBackModel.swift @@ -1,4 +1,4 @@ -struct PostBackModel { +public struct PostBackModel { let parameters: [(ProviderType, Any?)] let events: Array? diff --git a/AffiseAttributionLib/Classes/parameters/providers/factory/PostBackModelFactory.swift b/AffiseAttributionLib/Classes/parameters/providers/factory/PostBackModelFactory.swift index 113f38c..532e23c 100644 --- a/AffiseAttributionLib/Classes/parameters/providers/factory/PostBackModelFactory.swift +++ b/AffiseAttributionLib/Classes/parameters/providers/factory/PostBackModelFactory.swift @@ -1,4 +1,4 @@ -internal class PostBackModelFactory { +public class PostBackModelFactory { private var providers: [Provider] @@ -11,7 +11,7 @@ internal class PostBackModelFactory { * * @return PostBackModel */ - func create( + public func create( events: Array = [], logs: Array = [], metrics: Array = [], diff --git a/AffiseAttributionLib/Classes/usecase/ImmediateSendToServerUseCaseImpl.swift b/AffiseAttributionLib/Classes/usecase/ImmediateSendToServerUseCaseImpl.swift index 4e8444e..25713c6 100644 --- a/AffiseAttributionLib/Classes/usecase/ImmediateSendToServerUseCaseImpl.swift +++ b/AffiseAttributionLib/Classes/usecase/ImmediateSendToServerUseCaseImpl.swift @@ -46,7 +46,7 @@ extension ImmediateSendToServerUseCaseImpl: ImmediateSendToServerUseCase { guard let self = self else { return } let response = self.sendNow(event: event, url: it) - if isHttpValid(response.code) { + if response.isHttpValid() { success() } else { let _ = failed(response) diff --git a/AffiseInternal.podspec b/AffiseInternal.podspec index 773ebd8..0737b8d 100644 --- a/AffiseInternal.podspec +++ b/AffiseInternal.podspec @@ -8,7 +8,7 @@ Pod::Spec.new do |spec| spec.name = "AffiseInternal" - spec.version = ENV['LIB_VERSION'] || "1.6.34" + spec.version = ENV['LIB_VERSION'] || "1.6.35" spec.summary = "Affise Internal library" spec.description = "Affise Internal wrapper library for crossplatform" spec.homepage = "https://github.com/affise/sdk-ios" diff --git a/AffiseModule.podspec b/AffiseModule.podspec index 969feff..b5b4ae1 100644 --- a/AffiseModule.podspec +++ b/AffiseModule.podspec @@ -8,7 +8,7 @@ Pod::Spec.new do |s| s.name = "AffiseModule" - s.version = ENV["LIB_VERSION"] || "1.6.34" + s.version = ENV["LIB_VERSION"] || "1.6.35" s.summary = "Affise Modules" s.description = "Affise module collection" s.homepage = "https://github.com/affise/sdk-ios" diff --git a/AffiseModule/Advertising/Classes/AdvertisingModule.swift b/AffiseModule/Advertising/Classes/AdvertisingModule.swift index 85d566f..63a2bac 100644 --- a/AffiseModule/Advertising/Classes/AdvertisingModule.swift +++ b/AffiseModule/Advertising/Classes/AdvertisingModule.swift @@ -4,7 +4,7 @@ import Foundation @objc(AffiseAdvertisingModule) public final class AdvertisingModule: AffiseModule { - public override var version: String { "1.6.34" } + public override var version: String { "1.6.35" } private lazy var advertisingIdManager: AdvertisingIdManager = AdvertisingIdManagerImpl() diff --git a/AffiseModule/Link/Classes/LinkModule.swift b/AffiseModule/Link/Classes/LinkModule.swift index 3388b11..228f060 100644 --- a/AffiseModule/Link/Classes/LinkModule.swift +++ b/AffiseModule/Link/Classes/LinkModule.swift @@ -5,15 +5,20 @@ import AffiseAttributionLib @objc(AffiseLinkModule) public final class LinkModule: AffiseModule { - public override var version: String { "1.6.34" } + public override var version: String { "1.6.35" } private var useCase: LinkResolveUseCase? = nil public override func start() { - guard let networkService: NetworkService = get() else { return } + let networkService: NetworkService? = get() + if networkService == nil + { + print(AffiseModuleError.initModule(name: .Link).localizedDescription) + return + } useCase = LinkResolveUseCaseImpl( - networkService: networkService + networkService: networkService! ) } } diff --git a/AffiseModule/Status/Classes/StatusModule.swift b/AffiseModule/Status/Classes/StatusModule.swift index e601762..d79e625 100644 --- a/AffiseModule/Status/Classes/StatusModule.swift +++ b/AffiseModule/Status/Classes/StatusModule.swift @@ -5,7 +5,7 @@ import AffiseAttributionLib @objc(AffiseStatusModule) public final class StatusModule: AffiseModule { - public override var version: String { "1.6.34" } + public override var version: String { "1.6.35" } private var checkStatusUseCase: CheckStatusUseCase? = nil private var referrerUseCase: ReferrerUseCase? = nil @@ -13,15 +13,28 @@ public final class StatusModule: AffiseModule { private lazy var stringToKeyValueConverter: StringToKeyValueConverter = StringToKeyValueConverter() public override func start() { - guard let providersToJsonStringConverter: ProvidersToJsonStringConverter = get() else { return } - guard let networkService: NetworkService = get() else { return } + let providersToJsonStringConverter: ProvidersToJsonStringConverter? = get() + let networkService: NetworkService? = get() + let postBackModelFactory: PostBackModelFactory? = get() + let postBackModelToJsonStringConverter: PostBackModelToJsonStringConverter? = get() + + if providersToJsonStringConverter == nil || + networkService == nil || + postBackModelFactory == nil || + postBackModelToJsonStringConverter == nil + { + print(AffiseModuleError.initModule(name: .Status).localizedDescription) + return + } checkStatusUseCase = CheckStatusUseCaseImpl( affiseModule: self, logsManager: logsManager, - networkService: networkService, - converter: providersToJsonStringConverter, - keyValueConverter: stringToKeyValueConverter + networkService: networkService!, + converter: providersToJsonStringConverter!, + keyValueConverter: stringToKeyValueConverter, + postBackModelFactory: postBackModelFactory!, + postBackModelToJsonStringConverter: postBackModelToJsonStringConverter! ) referrerUseCase = ReferrerUseCaseImpl( diff --git a/AffiseModule/Status/Classes/usecase/CheckStatusUseCaseImpl.swift b/AffiseModule/Status/Classes/usecase/CheckStatusUseCaseImpl.swift index cc18c00..67d4c8b 100644 --- a/AffiseModule/Status/Classes/usecase/CheckStatusUseCaseImpl.swift +++ b/AffiseModule/Status/Classes/usecase/CheckStatusUseCaseImpl.swift @@ -9,11 +9,15 @@ internal class CheckStatusUseCaseImpl { let PATH: String = "check_status" var url: String = "" + var isPostBackSend: Bool = false let logsManager: LogsManager? let converter: ProvidersToJsonStringConverter let keyValueConverter: StringToKeyValueConverter let networkService: NetworkService + let postBackModelFactory: PostBackModelFactory + let postBackModelToJsonStringConverter: PostBackModelToJsonStringConverter + let providers: [Provider] init( @@ -21,30 +25,43 @@ internal class CheckStatusUseCaseImpl { logsManager: LogsManager?, networkService: NetworkService, converter: ProvidersToJsonStringConverter, - keyValueConverter: StringToKeyValueConverter + keyValueConverter: StringToKeyValueConverter, + postBackModelFactory: PostBackModelFactory, + postBackModelToJsonStringConverter: PostBackModelToJsonStringConverter ) { self.logsManager = logsManager self.converter = converter self.keyValueConverter = keyValueConverter self.networkService = networkService + self.postBackModelFactory = postBackModelFactory + self.postBackModelToJsonStringConverter = postBackModelToJsonStringConverter self.providers = affiseModule.getRequestProviders() self.url = CloudConfig.getURL(PATH) } - private func createRequest() -> HttpResponse { + private func createRequest(_ data: String) -> HttpResponse { guard let httpsUrl = url.toURL() else { return HttpResponse(0, "", nil) } //Create request return networkService.executeRequest( httpsUrl: httpsUrl, method: .POST, - data: converter.convert(from: providers).toData(), + data: data.toData(), timeout: TIMEOUT_SEND, headers: CloudConfig.headers, redirect: true ) } + + func providersData() -> String { + return converter.convert(from: providers) + } + + func postBackData() -> String { + let data = postBackModelFactory.create(events: [], logs: [], metrics: [], internalEvents: []) + return postBackModelToJsonStringConverter.convert(from: [data]) + } } extension CheckStatusUseCaseImpl: CheckStatusUseCase { @@ -66,9 +83,22 @@ extension CheckStatusUseCaseImpl: CheckStatusUseCase { //While has attempts and not send while (attempts != 0 && !send) { - let response = createRequest() - if isHttpValid(response.code) { - onComplete(keyValueConverter.convert(from: response.body)) + var postBackResponse: HttpResponse? = nil + var response: HttpResponse? = nil + + if isPostBackSend == false { + postBackResponse = createRequest(postBackData()) + if let postBackResponse = postBackResponse { + isPostBackSend = postBackResponse.isHttpValid() + } + } + + if isPostBackSend == true { + response = createRequest(providersData()) + } + + if isPostBackSend && response?.isHttpValid() == true { + onComplete(keyValueConverter.convert(from: response?.body ?? "")) //Send is ok send = true @@ -77,7 +107,9 @@ extension CheckStatusUseCaseImpl: CheckStatusUseCase { //Check attempts if (attempts == 0) { onComplete([]) - let error = AffiseError.network(status: response.code, message: response.body) + + let httpResponse = response ?? postBackResponse + let error = AffiseError.network(status: httpResponse?.code ?? 0, message: httpResponse?.body) //Log error logsManager?.addSdkError(error: AffiseError.cloud(url: url, error: error, attempts: ATTEMPTS_TO_SEND, retry: true)) } else { diff --git a/AffiseModule/Subscription/Classes/SubscriptionModule.swift b/AffiseModule/Subscription/Classes/SubscriptionModule.swift index 71ec3ad..5cd7eac 100644 --- a/AffiseModule/Subscription/Classes/SubscriptionModule.swift +++ b/AffiseModule/Subscription/Classes/SubscriptionModule.swift @@ -6,7 +6,7 @@ import AffiseAttributionLib @objc(AffiseSubscriptionModule) public final class SubscriptionModule: AffiseModule { - public override var version: String { "1.6.34" } + public override var version: String { "1.6.35" } lazy var storeManager: StoreManager = StoreManager() diff --git a/AffiseSKAdNetwork.podspec b/AffiseSKAdNetwork.podspec index 617ffc0..7ce53aa 100644 --- a/AffiseSKAdNetwork.podspec +++ b/AffiseSKAdNetwork.podspec @@ -5,7 +5,7 @@ Pod::Spec.new do |spec| spec.name = "AffiseSKAdNetwork" - spec.version = ENV['LIB_VERSION'] || "1.6.34" + spec.version = ENV['LIB_VERSION'] || "1.6.35" spec.summary = "AffiseSKAdNetwork iOS library" spec.description = "Affise library for StoreKit Ad Network (SKAdNetwork)" spec.homepage = "https://github.com/affise/sdk-ios" diff --git a/CHANGELOG.md b/CHANGELOG.md index f7b54b7..9ae9af4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## [1.6.35] - 2024-07-29 + +### Fixed + +- Api `Affise.Module.getStatus`. + ## [1.6.34] - 2024-07-26 ### Added diff --git a/README.md b/README.md index ca1c160..6abb77a 100644 --- a/README.md +++ b/README.md @@ -4,11 +4,11 @@ | Pod | Version | | ---- |:-------:| -| `AffiseAttributionLib` | [`1.6.34`](https://github.com/CocoaPods/Specs/tree/master/Specs/a/9/3/AffiseAttributionLib) | -| `AffiseSKAdNetwork` | [`1.6.34`](https://github.com/CocoaPods/Specs/tree/master/Specs/3/6/f/AffiseSKAdNetwork) | -| `AffiseModule/Advertising` | [`1.6.34`](https://github.com/CocoaPods/Specs/tree/master/Specs/0/3/d/AffiseModule/) | -| `AffiseModule/Link` | [`1.6.34`](https://github.com/CocoaPods/Specs/tree/master/Specs/0/3/d/AffiseModule/) | -| `AffiseModule/Status` | [`1.6.34`](https://github.com/CocoaPods/Specs/tree/master/Specs/0/3/d/AffiseModule/) | +| `AffiseAttributionLib` | [`1.6.35`](https://github.com/CocoaPods/Specs/tree/master/Specs/a/9/3/AffiseAttributionLib) | +| `AffiseSKAdNetwork` | [`1.6.35`](https://github.com/CocoaPods/Specs/tree/master/Specs/3/6/f/AffiseSKAdNetwork) | +| `AffiseModule/Advertising` | [`1.6.35`](https://github.com/CocoaPods/Specs/tree/master/Specs/0/3/d/AffiseModule/) | +| `AffiseModule/Link` | [`1.6.35`](https://github.com/CocoaPods/Specs/tree/master/Specs/0/3/d/AffiseModule/) | +| `AffiseModule/Status` | [`1.6.35`](https://github.com/CocoaPods/Specs/tree/master/Specs/0/3/d/AffiseModule/) | - [Affise Attribution iOS Library](#affise-attribution-ios-library) - [Description](#description) @@ -80,22 +80,22 @@ To add the SDK using Cocoapods, specify the version you want to use in your Podf ```ruby # Affise SDK library -pod 'AffiseAttributionLib', '~> 1.6.34' +pod 'AffiseAttributionLib', '~> 1.6.35' # Affise modules -pod 'AffiseModule/Advertising', '~> 1.6.34' -pod 'AffiseModule/Link', '~> 1.6.34' -pod 'AffiseModule/Status', '~> 1.6.34' +pod 'AffiseModule/Advertising', '~> 1.6.35' +pod 'AffiseModule/Link', '~> 1.6.35' +pod 'AffiseModule/Status', '~> 1.6.35' ``` Get source directly from GitHub ```ruby # Affise SDK library -pod 'AffiseAttributionLib', :git => 'https://github.com/affise/sdk-ios.git', :tag => '1.6.34' +pod 'AffiseAttributionLib', :git => 'https://github.com/affise/sdk-ios.git', :tag => '1.6.35' # Affise modules -pod 'AffiseModule/Advertising', :git => 'https://github.com/affise/sdk-ios.git', :tag => '1.6.34' -pod 'AffiseModule/Link', :git => 'https://github.com/affise/sdk-ios.git', :tag => '1.6.34' -pod 'AffiseModule/Status', :git => 'https://github.com/affise/sdk-ios.git', :tag => '1.6.34' +pod 'AffiseModule/Advertising', :git => 'https://github.com/affise/sdk-ios.git', :tag => '1.6.35' +pod 'AffiseModule/Link', :git => 'https://github.com/affise/sdk-ios.git', :tag => '1.6.35' +pod 'AffiseModule/Status', :git => 'https://github.com/affise/sdk-ios.git', :tag => '1.6.35' ``` ### Integrate as Swift Package Manager @@ -197,9 +197,9 @@ Affise | Module | Version | Start | | ------------- |:------------------------------------------------------------------------------------:|----------| -| `Advertising` | [`1.6.34`](https://github.com/CocoaPods/Specs/tree/master/Specs/0/3/d/AffiseModule/) | `Manual` | -| `Link` | [`1.6.34`](https://github.com/CocoaPods/Specs/tree/master/Specs/0/3/d/AffiseModule/) | `Auto` | -| `Status` | [`1.6.34`](https://github.com/CocoaPods/Specs/tree/master/Specs/0/3/d/AffiseModule/) | `Auto` | +| `Advertising` | [`1.6.35`](https://github.com/CocoaPods/Specs/tree/master/Specs/0/3/d/AffiseModule/) | `Manual` | +| `Link` | [`1.6.35`](https://github.com/CocoaPods/Specs/tree/master/Specs/0/3/d/AffiseModule/) | `Auto` | +| `Status` | [`1.6.35`](https://github.com/CocoaPods/Specs/tree/master/Specs/0/3/d/AffiseModule/) | `Auto` | If module start type is `manual`, then call: @@ -263,14 +263,14 @@ To add the SDK using Cocoapods, specify the version you want to use in your Podf ```ruby # Wrapper for StoreKit Ad Network -pod 'AffiseSKAdNetwork', '~> 1.6.34' +pod 'AffiseSKAdNetwork', '~> 1.6.35' ``` Get source directly from GitHub ```ruby # Wrapper for StoreKit Ad Network -pod 'AffiseSKAdNetwork', :git => 'https://github.com/affise/sdk-ios.git', :tag => '1.6.34' +pod 'AffiseSKAdNetwork', :git => 'https://github.com/affise/sdk-ios.git', :tag => '1.6.35' ``` For `swift` use: diff --git a/example/app/app/AppDelegate.swift b/example/app/app/AppDelegate.swift index d2d4db3..af8218c 100644 --- a/example/app/app/AppDelegate.swift +++ b/example/app/app/AppDelegate.swift @@ -46,7 +46,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate { // } // Get module state https://github.com/affise/sdk-ios#get-module-state -// Affise.getStatus(AffiseModules.Status) { result in +// Affise.Module.getStatus(AffiseModules.Status) { result in // // handle status // }