@tyrads.com/tyrads-sdk 2.0.0-beta.2 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (122) hide show
  1. package/LICENSE +11 -11
  2. package/android/build.gradle +117 -117
  3. package/android/gradle.properties +5 -5
  4. package/android/src/main/AndroidManifest.xml +3 -3
  5. package/android/src/main/AndroidManifestNew.xml +2 -2
  6. package/android/src/main/java/com/tyradssdk/TyradsSdkComposeViewManager.kt +112 -112
  7. package/android/src/main/java/com/tyradssdk/TyradsSdkModule.kt +56 -56
  8. package/android/src/main/java/com/tyradssdk/TyradsSdkPackage.kt +18 -21
  9. package/ios/Tyrads/AcmoConfig.swift +32 -31
  10. package/ios/Tyrads/ApiHeaders.swift +12 -0
  11. package/ios/Tyrads/InitModel.swift +48 -46
  12. package/ios/Tyrads/Tyrads.swift +199 -176
  13. package/ios/TyradsSdk-Bridging-Header.h +2 -2
  14. package/ios/TyradsSdk.mm +14 -11
  15. package/ios/TyradsSdk.swift +47 -27
  16. package/lib/commonjs/acmo/core/marquee.js.map +1 -1
  17. package/lib/commonjs/acmo/core/storage/storage.js.map +1 -1
  18. package/lib/commonjs/acmo/core/types/types.d.js.map +1 -1
  19. package/lib/commonjs/acmo/modules/dashboard/components/auto_scroller.js.map +1 -1
  20. package/lib/commonjs/acmo/modules/dashboard/components/custom_card.js.map +1 -1
  21. package/lib/commonjs/acmo/modules/dashboard/components/my_games_button.js +3 -5
  22. package/lib/commonjs/acmo/modules/dashboard/components/my_games_button.js.map +1 -1
  23. package/lib/commonjs/acmo/modules/dashboard/components/offer_info_section.js +3 -8
  24. package/lib/commonjs/acmo/modules/dashboard/components/offer_info_section.js.map +1 -1
  25. package/lib/commonjs/acmo/modules/dashboard/components/premium_header.js +3 -3
  26. package/lib/commonjs/acmo/modules/dashboard/components/premium_header.js.map +1 -1
  27. package/lib/commonjs/acmo/modules/dashboard/components/premium_option_1.js +2 -7
  28. package/lib/commonjs/acmo/modules/dashboard/components/premium_option_1.js.map +1 -1
  29. package/lib/commonjs/acmo/modules/dashboard/components/premium_option_2.js +4 -6
  30. package/lib/commonjs/acmo/modules/dashboard/components/premium_option_2.js.map +1 -1
  31. package/lib/commonjs/acmo/modules/dashboard/components/premium_option_3.js +4 -6
  32. package/lib/commonjs/acmo/modules/dashboard/components/premium_option_3.js.map +1 -1
  33. package/lib/commonjs/acmo/modules/dashboard/components/premium_option_4.js +5 -6
  34. package/lib/commonjs/acmo/modules/dashboard/components/premium_option_4.js.map +1 -1
  35. package/lib/commonjs/acmo/modules/dashboard/repository.js.map +1 -1
  36. package/lib/commonjs/acmo/modules/dashboard/top_offers.js +23 -7
  37. package/lib/commonjs/acmo/modules/dashboard/top_offers.js.map +1 -1
  38. package/lib/commonjs/i18n.js.map +1 -1
  39. package/lib/commonjs/index.js +12 -2
  40. package/lib/commonjs/index.js.map +1 -1
  41. package/lib/module/acmo/core/marquee.js.map +1 -1
  42. package/lib/module/acmo/core/storage/storage.js.map +1 -1
  43. package/lib/module/acmo/core/types/types.d.js.map +1 -1
  44. package/lib/module/acmo/modules/dashboard/components/auto_scroller.js.map +1 -1
  45. package/lib/module/acmo/modules/dashboard/components/custom_card.js.map +1 -1
  46. package/lib/module/acmo/modules/dashboard/components/my_games_button.js +3 -5
  47. package/lib/module/acmo/modules/dashboard/components/my_games_button.js.map +1 -1
  48. package/lib/module/acmo/modules/dashboard/components/offer_info_section.js +3 -8
  49. package/lib/module/acmo/modules/dashboard/components/offer_info_section.js.map +1 -1
  50. package/lib/module/acmo/modules/dashboard/components/premium_header.js +3 -3
  51. package/lib/module/acmo/modules/dashboard/components/premium_header.js.map +1 -1
  52. package/lib/module/acmo/modules/dashboard/components/premium_option_1.js +2 -7
  53. package/lib/module/acmo/modules/dashboard/components/premium_option_1.js.map +1 -1
  54. package/lib/module/acmo/modules/dashboard/components/premium_option_2.js +4 -6
  55. package/lib/module/acmo/modules/dashboard/components/premium_option_2.js.map +1 -1
  56. package/lib/module/acmo/modules/dashboard/components/premium_option_3.js +4 -6
  57. package/lib/module/acmo/modules/dashboard/components/premium_option_3.js.map +1 -1
  58. package/lib/module/acmo/modules/dashboard/components/premium_option_4.js +5 -6
  59. package/lib/module/acmo/modules/dashboard/components/premium_option_4.js.map +1 -1
  60. package/lib/module/acmo/modules/dashboard/repository.js.map +1 -1
  61. package/lib/module/acmo/modules/dashboard/top_offers.js +23 -7
  62. package/lib/module/acmo/modules/dashboard/top_offers.js.map +1 -1
  63. package/lib/module/i18n.js.map +1 -1
  64. package/lib/module/index.js +12 -2
  65. package/lib/module/index.js.map +1 -1
  66. package/lib/typescript/commonjs/src/acmo/core/storage/storage.d.ts.map +1 -1
  67. package/lib/typescript/commonjs/src/acmo/modules/dashboard/components/my_games_button.d.ts +1 -0
  68. package/lib/typescript/commonjs/src/acmo/modules/dashboard/components/my_games_button.d.ts.map +1 -1
  69. package/lib/typescript/commonjs/src/acmo/modules/dashboard/components/offer_info_section.d.ts +1 -0
  70. package/lib/typescript/commonjs/src/acmo/modules/dashboard/components/offer_info_section.d.ts.map +1 -1
  71. package/lib/typescript/commonjs/src/acmo/modules/dashboard/components/premium_header.d.ts +1 -0
  72. package/lib/typescript/commonjs/src/acmo/modules/dashboard/components/premium_header.d.ts.map +1 -1
  73. package/lib/typescript/commonjs/src/acmo/modules/dashboard/components/premium_option_1.d.ts +1 -0
  74. package/lib/typescript/commonjs/src/acmo/modules/dashboard/components/premium_option_1.d.ts.map +1 -1
  75. package/lib/typescript/commonjs/src/acmo/modules/dashboard/components/premium_option_2.d.ts +1 -0
  76. package/lib/typescript/commonjs/src/acmo/modules/dashboard/components/premium_option_2.d.ts.map +1 -1
  77. package/lib/typescript/commonjs/src/acmo/modules/dashboard/components/premium_option_3.d.ts +1 -0
  78. package/lib/typescript/commonjs/src/acmo/modules/dashboard/components/premium_option_3.d.ts.map +1 -1
  79. package/lib/typescript/commonjs/src/acmo/modules/dashboard/components/premium_option_4.d.ts +1 -0
  80. package/lib/typescript/commonjs/src/acmo/modules/dashboard/components/premium_option_4.d.ts.map +1 -1
  81. package/lib/typescript/commonjs/src/acmo/modules/dashboard/repository.d.ts.map +1 -1
  82. package/lib/typescript/commonjs/src/acmo/modules/dashboard/top_offers.d.ts +1 -0
  83. package/lib/typescript/commonjs/src/acmo/modules/dashboard/top_offers.d.ts.map +1 -1
  84. package/lib/typescript/commonjs/src/index.d.ts.map +1 -1
  85. package/lib/typescript/module/src/acmo/core/storage/storage.d.ts.map +1 -1
  86. package/lib/typescript/module/src/acmo/modules/dashboard/components/my_games_button.d.ts +1 -0
  87. package/lib/typescript/module/src/acmo/modules/dashboard/components/my_games_button.d.ts.map +1 -1
  88. package/lib/typescript/module/src/acmo/modules/dashboard/components/offer_info_section.d.ts +1 -0
  89. package/lib/typescript/module/src/acmo/modules/dashboard/components/offer_info_section.d.ts.map +1 -1
  90. package/lib/typescript/module/src/acmo/modules/dashboard/components/premium_header.d.ts +1 -0
  91. package/lib/typescript/module/src/acmo/modules/dashboard/components/premium_header.d.ts.map +1 -1
  92. package/lib/typescript/module/src/acmo/modules/dashboard/components/premium_option_1.d.ts +1 -0
  93. package/lib/typescript/module/src/acmo/modules/dashboard/components/premium_option_1.d.ts.map +1 -1
  94. package/lib/typescript/module/src/acmo/modules/dashboard/components/premium_option_2.d.ts +1 -0
  95. package/lib/typescript/module/src/acmo/modules/dashboard/components/premium_option_2.d.ts.map +1 -1
  96. package/lib/typescript/module/src/acmo/modules/dashboard/components/premium_option_3.d.ts +1 -0
  97. package/lib/typescript/module/src/acmo/modules/dashboard/components/premium_option_3.d.ts.map +1 -1
  98. package/lib/typescript/module/src/acmo/modules/dashboard/components/premium_option_4.d.ts +1 -0
  99. package/lib/typescript/module/src/acmo/modules/dashboard/components/premium_option_4.d.ts.map +1 -1
  100. package/lib/typescript/module/src/acmo/modules/dashboard/repository.d.ts.map +1 -1
  101. package/lib/typescript/module/src/acmo/modules/dashboard/top_offers.d.ts +1 -0
  102. package/lib/typescript/module/src/acmo/modules/dashboard/top_offers.d.ts.map +1 -1
  103. package/lib/typescript/module/src/index.d.ts.map +1 -1
  104. package/package.json +197 -197
  105. package/readme.md +95 -97
  106. package/src/acmo/core/marquee.tsx +61 -61
  107. package/src/acmo/core/storage/storage.ts +27 -27
  108. package/src/acmo/core/types/types.d.ts +93 -93
  109. package/src/acmo/modules/dashboard/components/auto_scroller.tsx +84 -84
  110. package/src/acmo/modules/dashboard/components/custom_card.tsx +30 -30
  111. package/src/acmo/modules/dashboard/components/my_games_button.tsx +39 -39
  112. package/src/acmo/modules/dashboard/components/offer_info_section.tsx +138 -143
  113. package/src/acmo/modules/dashboard/components/premium_header.tsx +80 -80
  114. package/src/acmo/modules/dashboard/components/premium_option_1.tsx +155 -160
  115. package/src/acmo/modules/dashboard/components/premium_option_2.tsx +99 -103
  116. package/src/acmo/modules/dashboard/components/premium_option_3.tsx +41 -45
  117. package/src/acmo/modules/dashboard/components/premium_option_4.tsx +184 -183
  118. package/src/acmo/modules/dashboard/repository.ts +94 -94
  119. package/src/acmo/modules/dashboard/top_offers.tsx +144 -131
  120. package/src/i18n.ts +114 -114
  121. package/src/index.tsx +89 -81
  122. package/tyrads-sdk.podspec +41 -41
@@ -1,21 +1,18 @@
1
- package com.tyradssdk
2
-
3
- import com.facebook.react.ReactPackage
4
- import com.facebook.react.bridge.NativeModule
5
- import com.facebook.react.bridge.ReactApplicationContext
6
- import com.facebook.react.uimanager.ViewManager
7
-
8
-
9
- class TyradsSdkPackage : ReactPackage {
10
-
11
- override fun createNativeModules(reactContext: ReactApplicationContext): List<NativeModule> {
12
- return listOf(TyradsSdkModule(reactContext))
13
- }
14
-
15
- override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> {
16
- return emptyList()
17
- }
18
- // override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> {
19
- // return listOf(ComposeViewManager())
20
- // }
21
- }
1
+ package com.tyradssdk
2
+
3
+ import com.facebook.react.ReactPackage
4
+ import com.facebook.react.bridge.NativeModule
5
+ import com.facebook.react.bridge.ReactApplicationContext
6
+ import com.facebook.react.uimanager.ViewManager
7
+
8
+
9
+ class TyradsSdkPackage : ReactPackage {
10
+
11
+ override fun createNativeModules(reactContext: ReactApplicationContext): List<NativeModule> {
12
+ return listOf(TyradsSdkModule(reactContext))
13
+ }
14
+
15
+ override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> {
16
+ return listOf(ComposeViewManager())
17
+ }
18
+ }
@@ -1,31 +1,32 @@
1
- //
2
- // AcmoConfig.swift
3
- // TyradsSdk
4
- //
5
- // Created by ibnShamas on 8/13/24.
6
- //
7
-
8
- import Foundation
9
- import UIKit
10
-
11
- struct AcmoConfig {
12
- static let API_VERSION = "1.1"
13
- static let BUILD_VERSION = "2"
14
- static let SDK_VERSION = "\(API_VERSION).\(BUILD_VERSION)"
15
- static let SDK_PLATFORM = "React Native"
16
- static let BASE_URL = "https://api.tyrads.com/v\(API_VERSION)/"
17
- static let TAG = "TyrAds SDK"
18
-
19
- static let PRIMARY_COLOR = UIColor(red: 0/255, green: 36/255, blue: 51/255, alpha: 1)
20
- static let PRIMARY_COLOR_LIGHT = UIColor(red: 153/255, green: 145/255, blue: 145/255, alpha: 1)
21
- static let PRIMARY_COLOR_DARK = UIColor.black
22
-
23
- static let SECONDARY_COLOR = UIColor(red: 44/255, green: 179/255, blue: 136/255, alpha: 1)
24
- static let SECONDARY_COLOR_LIGHT = UIColor(red: 203/255, green: 235/255, blue: 207/255, alpha: 1)
25
- static let SIDEBAR_BACKGROUND_COLOR_LIGHT = UIColor(white: 1, alpha: 0.54)
26
- static let SIDEBAR_BACKGROUND_COLOR_DARK = UIColor(red: 17/255, green: 45/255, blue: 30/255, alpha: 1)
27
- static let APPBAR_BG = UIColor(red: 0/255, green: 33/255, blue: 48/255, alpha: 1)
28
-
29
- // Note: ThemeMode.light doesn't have a direct equivalent in iOS
30
- // You would typically handle this in your app's theme configuration
31
- }
1
+ //
2
+ // AcmoConfig.swift
3
+ // TyradsSdk
4
+ //
5
+ // Created by ibnShamas on 8/13/24.
6
+ //
7
+
8
+ import Foundation
9
+ import UIKit
10
+
11
+ struct AcmoConfig {
12
+ static let API_VERSION = "2.0"
13
+ static let BUILD_VERSION = "1"
14
+ static let ACMO_VERSION = "3"
15
+ static let SDK_VERSION = "\(API_VERSION).\(BUILD_VERSION)"
16
+ static let SDK_PLATFORM = "React Native"
17
+ static let BASE_URL = "https://api.tyrads.com/v\(API_VERSION)/"
18
+ static let TAG = "TyrAds SDK"
19
+
20
+ static let PRIMARY_COLOR = UIColor(red: 0/255, green: 36/255, blue: 51/255, alpha: 1)
21
+ static let PRIMARY_COLOR_LIGHT = UIColor(red: 153/255, green: 145/255, blue: 145/255, alpha: 1)
22
+ static let PRIMARY_COLOR_DARK = UIColor.black
23
+
24
+ static let SECONDARY_COLOR = UIColor(red: 44/255, green: 179/255, blue: 136/255, alpha: 1)
25
+ static let SECONDARY_COLOR_LIGHT = UIColor(red: 203/255, green: 235/255, blue: 207/255, alpha: 1)
26
+ static let SIDEBAR_BACKGROUND_COLOR_LIGHT = UIColor(white: 1, alpha: 0.54)
27
+ static let SIDEBAR_BACKGROUND_COLOR_DARK = UIColor(red: 17/255, green: 45/255, blue: 30/255, alpha: 1)
28
+ static let APPBAR_BG = UIColor(red: 0/255, green: 33/255, blue: 48/255, alpha: 1)
29
+
30
+ // Note: ThemeMode.light doesn't have a direct equivalent in iOS
31
+ // You would typically handle this in your app's theme configuration
32
+ }
@@ -0,0 +1,12 @@
1
+ public struct ApiHeaders {
2
+ let xApiKey: String
3
+ let xApiSecret: String
4
+ let xUserId: String
5
+ let xSdkPlatform: String?
6
+ let xSdkVersion: String?
7
+ let userAgent: String
8
+ let languageCode: String
9
+ let premiumColor: String
10
+ let headerColor: String
11
+ let mainColor: String
12
+ }
@@ -1,46 +1,48 @@
1
- //
2
- // InitModel.swift
3
- // TyradsSdk
4
- //
5
- // Created by ibnShamas on 8/13/24.
6
- //
7
-
8
- import Foundation
9
-
10
- struct AcmoInitModel: Codable {
11
- let data: Data
12
- }
13
-
14
- struct Data: Codable {
15
- let newRegisteredUser: Bool
16
- let user: User
17
- let publisherApp: PublisherApp
18
-
19
- enum CodingKeys: String, CodingKey {
20
- case newRegisteredUser = "newRegisteredUser"
21
- case user
22
- case publisherApp
23
- }
24
-
25
- init(from decoder: Decoder) throws {
26
- let container = try decoder.container(keyedBy: CodingKeys.self)
27
- newRegisteredUser = try container.decodeIfPresent(Bool.self, forKey: .newRegisteredUser) ?? false
28
- user = try container.decode(User.self, forKey: .user)
29
- publisherApp = try container.decode(PublisherApp.self, forKey: .publisherApp)
30
- }
31
- }
32
-
33
- struct User: Codable {
34
- let publisherUserId: String
35
- }
36
-
37
- struct PublisherApp: Codable {
38
- let headerColor: String
39
- let mainColor: String
40
-
41
- init(from decoder: Decoder) throws {
42
- let container = try decoder.container(keyedBy: CodingKeys.self)
43
- headerColor = try container.decodeIfPresent(String.self, forKey: .headerColor) ?? ""
44
- mainColor = try container.decodeIfPresent(String.self, forKey: .mainColor) ?? ""
45
- }
46
- }
1
+ //
2
+ // InitModel.swift
3
+ // TyradsSdk
4
+ //
5
+ // Created by ibnShamas on 8/13/24.
6
+ //
7
+
8
+ import Foundation
9
+
10
+ struct AcmoInitModel: Codable {
11
+ let data: Data
12
+ }
13
+
14
+ struct Data: Codable {
15
+ let newRegisteredUser: Bool
16
+ let user: User
17
+ let publisherApp: PublisherApp
18
+
19
+ enum CodingKeys: String, CodingKey {
20
+ case newRegisteredUser = "newRegisteredUser"
21
+ case user
22
+ case publisherApp
23
+ }
24
+
25
+ init(from decoder: Decoder) throws {
26
+ let container = try decoder.container(keyedBy: CodingKeys.self)
27
+ newRegisteredUser = try container.decodeIfPresent(Bool.self, forKey: .newRegisteredUser) ?? false
28
+ user = try container.decode(User.self, forKey: .user)
29
+ publisherApp = try container.decode(PublisherApp.self, forKey: .publisherApp)
30
+ }
31
+ }
32
+
33
+ struct User: Codable {
34
+ let publisherUserId: String
35
+ }
36
+
37
+ struct PublisherApp: Codable {
38
+ let headerColor: String
39
+ let mainColor: String
40
+ let premiumColor: String
41
+
42
+ init(from decoder: Decoder) throws {
43
+ let container = try decoder.container(keyedBy: CodingKeys.self)
44
+ headerColor = try container.decodeIfPresent(String.self, forKey: .headerColor) ?? ""
45
+ mainColor = try container.decodeIfPresent(String.self, forKey: .mainColor) ?? ""
46
+ premiumColor = try container.decodeIfPresent(String.self, forKey: .premiumColor) ?? ""
47
+ }
48
+ }
@@ -1,176 +1,199 @@
1
- import Foundation
2
- import UIKit
3
- import AppTrackingTransparency
4
- import AdSupport
5
- import WebKit
6
-
7
-
8
-
9
- /// The TyradsSdk class provides methods for configuring the SDK and displaying offers.
10
- public class Tyrads {
11
- /// Shared instance of the TyradsSdk.
12
- public static let instance = Tyrads()
13
-
14
- private var apiKey: String = ""
15
- private var apiSecret: String = ""
16
- private var publisherUserID: String = ""
17
- private var newUser: Bool = false
18
- private var loginData: AcmoInitModel?
19
- var initializationWait = DispatchSemaphore(value: 0)
20
- private var debugMode: Bool = false
21
-
22
- private func log(_ message: String) {
23
- if debugMode {
24
- NSLog(message)
25
- }
26
- }
27
-
28
- /// Configures the Tyrads SDK with the provided API key and secret key.
29
- ///
30
- /// - Parameters:
31
- /// - apiKey: The API key provided by Tyrads.
32
- /// - secretKey: The secret key provided by Tyrads.
33
- @objc public func configure( apiKey: String, secretKey: String, debugMode: Bool = false) {
34
- self.apiKey = apiKey
35
- self.apiSecret = secretKey
36
- self.debugMode = debugMode
37
- }
38
-
39
- /// Logs in the user with the provided user ID or retrieves the user ID from UserDefaults.
40
- ///
41
- /// - Parameter userID: Optional. The user ID to log in with. If nil, the SDK will attempt to retrieve the user ID from UserDefaults.
42
- @objc public func loginUser(_ userID: String? = nil) {
43
- do {
44
- let userId = userID ?? UserDefaults.standard.string(forKey: "acmo-tyrads-sdk-user-id") ?? ""
45
-
46
- let identifierType = "IDFA"
47
- var advertisingId = ""
48
- if #available(iOS 14, *) {
49
- log("Requesting tracking authorization for iOS 14+")
50
- ATTrackingManager.requestTrackingAuthorization { status in
51
- switch status {
52
- case .authorized:
53
- advertisingId = ASIdentifierManager.shared().advertisingIdentifier.uuidString
54
- self.log("Tracking authorized. Advertising ID: \(advertisingId)")
55
- case .denied:
56
- advertisingId = ""
57
- self.log("Tracking denied")
58
- case .restricted:
59
- advertisingId = ""
60
- self.log("Tracking restricted")
61
- case .notDetermined:
62
- advertisingId = ""
63
- self.log("Tracking not determined")
64
- @unknown default:
65
- self.log("Unknown tracking status")
66
- }
67
- }
68
- } else {
69
- advertisingId = ASIdentifierManager.shared().advertisingIdentifier.uuidString
70
- log("iOS version < 14. Advertising ID: \(advertisingId)")
71
- }
72
- let fd: [String: Any] = [
73
- "publisherUserId": userId,
74
- "platform": "iOS",
75
- "identifierType": identifierType,
76
- "identifier": advertisingId
77
- ]
78
-
79
- log("Initializing with data: \(fd)")
80
-
81
- guard let url = URL(string: AcmoConfig.BASE_URL + "initialize") else {
82
- log("Failed to create URL")
83
- return
84
- }
85
-
86
- var request = URLRequest(url: url)
87
- request.httpMethod = "POST"
88
- request.setValue(AcmoConfig.SDK_PLATFORM, forHTTPHeaderField: "X-SDK-Platform")
89
- request.setValue(AcmoConfig.SDK_VERSION, forHTTPHeaderField: "X-SDK-Version")
90
- request.setValue("application/json", forHTTPHeaderField: "Content-Type")
91
- request.setValue(self.apiKey, forHTTPHeaderField: "X-API-Key")
92
- request.setValue(self.apiSecret, forHTTPHeaderField: "X-API-Secret")
93
-
94
- do {
95
- request.httpBody = try JSONSerialization.data(withJSONObject: fd)
96
- } catch {
97
- log("Failed to serialize request body: \(error)")
98
- return
99
- }
100
-
101
- let task = URLSession.shared.dataTask(with: request) { data, response, error in
102
-
103
- if let error = error {
104
- self.log("Network request failed: \(error)")
105
- return
106
- }
107
-
108
- guard let data = data else {
109
- self.log("No data received from the server")
110
- return
111
- }
112
-
113
- if let responseString = String(data: data, encoding: .utf8) {
114
- self.log("Received response: \(responseString)")
115
-
116
- let jsonData = responseString.data(using: .utf8)!
117
- let decoder = JSONDecoder()
118
- guard let acmoInitModel = try? decoder.decode(AcmoInitModel.self, from: jsonData) else {
119
- self.log("Failed to decode response")
120
- return
121
- }
122
- self.loginData = acmoInitModel
123
- self.publisherUserID = self.loginData?.data.user.publisherUserId ?? ""
124
- self.newUser = self.loginData?.data.newRegisteredUser ?? false
125
- self.log("Login successful. Publisher User ID: \(self.publisherUserID), New User: \(self.newUser)")
126
- self.initializationWait.signal()
127
- }
128
-
129
-
130
- }
131
-
132
- task.resume()
133
- log("Network request started")
134
-
135
-
136
- } catch {
137
- log("An error occurred: \(error)")
138
- }
139
- }
140
-
141
-
142
-
143
-
144
- public func showOffers(_ launchMode: Int = 3, route: String? = nil, campaignID: Int? = nil) {
145
- self.initializationWait.wait()
146
- var urlString =
147
- "https://websdk.tyrads.com/?apiKey=\(Tyrads.instance.apiKey)&apiSecret=\(Tyrads.instance.apiSecret)&userID=\(Tyrads.instance.publisherUserID)&newUser=\(Tyrads.instance.newUser)&platform=\(AcmoConfig.SDK_PLATFORM)&hc=\(Tyrads.instance.loginData?.data.publisherApp.headerColor ?? "")&mc=\(Tyrads.instance.loginData?.data.publisherApp.mainColor ?? "")&launchMode=\(launchMode)&route=\(route ?? "")&campaignID=\(campaignID)"
148
-
149
-
150
- if let url = URL(string: urlString) {
151
- switch launchMode {
152
- case 1, 2:
153
- DispatchQueue.main.async {
154
- let webView = WKWebView(frame: UIScreen.main.bounds)
155
- webView.load(URLRequest(url: url))
156
-
157
- let viewController = UIViewController()
158
- viewController.view = webView
159
- viewController.modalPresentationStyle = .fullScreen // Add this line to set the presentation style
160
-
161
- if let rootViewController = UIApplication.shared.windows.first?.rootViewController {
162
- rootViewController.present(viewController, animated: true, completion: nil)
163
- }
164
- }
165
- case 3:
166
- DispatchQueue.main.async {
167
- UIApplication.shared.open(url, options: [:], completionHandler: nil)
168
- }
169
- default:
170
- DispatchQueue.main.async {
171
- UIApplication.shared.open(url, options: [:], completionHandler: nil)
172
- }
173
- }
174
- }
175
- }
176
- }
1
+ import Foundation
2
+ import UIKit
3
+ import AppTrackingTransparency
4
+ import AdSupport
5
+ import WebKit
6
+
7
+
8
+
9
+ /// The TyradsSdk class provides methods for configuring the SDK and displaying offers.
10
+ public class Tyrads {
11
+ /// Shared instance of the TyradsSdk.
12
+ public static let instance = Tyrads()
13
+
14
+ private var apiKey: String = ""
15
+ private var apiSecret: String = ""
16
+ private var publisherUserID: String = ""
17
+ private var currentLanguage: String = "en"
18
+ private var newUser: Bool = false
19
+ private var loginData: AcmoInitModel?
20
+ var initializationWait = DispatchSemaphore(value: 0)
21
+ private var debugMode: Bool = false
22
+
23
+ private func log(_ message: String) {
24
+ if debugMode {
25
+ NSLog(message)
26
+ }
27
+ }
28
+
29
+ /// Configures the Tyrads SDK with the provided API key and secret key.
30
+ ///
31
+ /// - Parameters:
32
+ /// - apiKey: The API key provided by Tyrads.
33
+ /// - secretKey: The secret key provided by Tyrads.
34
+ @objc public func configure( apiKey: String, secretKey: String, debugMode: Bool = false) {
35
+ self.apiKey = apiKey
36
+ self.apiSecret = secretKey
37
+ self.debugMode = debugMode
38
+ self.currentLanguage = Locale.current.languageCode ?? ""
39
+ }
40
+
41
+ /// Logs in the user with the provided user ID or retrieves the user ID from UserDefaults.
42
+ ///
43
+ /// - Parameter userID: Optional. The user ID to log in with. If nil, the SDK will attempt to retrieve the user ID from UserDefaults.
44
+ public func loginUser(_ userID: String? = nil, completion: @escaping (ApiHeaders?) -> Void) {
45
+ let userId = userID ?? UserDefaults.standard.string(forKey: "acmo-tyrads-sdk-user-id") ?? ""
46
+
47
+ let identifierType = "IDFA"
48
+ var advertisingId = ""
49
+
50
+ func finalizeLogin() {
51
+ let fd: [String: Any] = [
52
+ "publisherUserId": userId,
53
+ "platform": "iOS",
54
+ "identifierType": identifierType,
55
+ "identifier": advertisingId
56
+ ]
57
+
58
+ self.log("Initializing with data: \(fd)")
59
+
60
+ guard let url = URL(string: AcmoConfig.BASE_URL + "initialize") else {
61
+ self.log("Failed to create URL")
62
+ completion(nil)
63
+ return
64
+ }
65
+
66
+ var request = URLRequest(url: url)
67
+ request.httpMethod = "POST"
68
+ request.setValue(AcmoConfig.SDK_PLATFORM, forHTTPHeaderField: "X-SDK-Platform")
69
+ request.setValue(AcmoConfig.SDK_VERSION, forHTTPHeaderField: "X-SDK-Version")
70
+ request.setValue("application/json", forHTTPHeaderField: "Content-Type")
71
+ request.setValue(self.apiKey, forHTTPHeaderField: "X-API-Key")
72
+ request.setValue(self.apiSecret, forHTTPHeaderField: "X-API-Secret")
73
+
74
+ do {
75
+ request.httpBody = try JSONSerialization.data(withJSONObject: fd)
76
+ } catch {
77
+ self.log("Failed to serialize request body: \(error)")
78
+ completion(nil)
79
+ return
80
+ }
81
+
82
+ let task = URLSession.shared.dataTask(with: request) { data, response, error in
83
+ if let error = error {
84
+ self.log("Network request failed: \(error)")
85
+ completion(nil)
86
+ return
87
+ }
88
+
89
+ guard let data = data else {
90
+ self.log("No data received from the server")
91
+ completion(nil)
92
+ return
93
+ }
94
+
95
+ if let responseString = String(data: data, encoding: .utf8) {
96
+ self.log("Received response: \(responseString)")
97
+
98
+ guard let jsonData = responseString.data(using: .utf8),
99
+ let acmoInitModel = try? JSONDecoder().decode(AcmoInitModel.self, from: jsonData) else {
100
+ self.log("Failed to decode response")
101
+ completion(nil)
102
+ return
103
+ }
104
+
105
+ self.loginData = acmoInitModel
106
+ self.publisherUserID = acmoInitModel.data.user.publisherUserId
107
+ self.newUser = acmoInitModel.data.newRegisteredUser
108
+ self.log("Login successful. Publisher User ID: \(self.publisherUserID), New User: \(self.newUser)")
109
+ self.initializationWait.signal()
110
+
111
+ // Build ApiHeaders object
112
+ let headers = ApiHeaders(
113
+ xApiKey: self.apiKey,
114
+ xApiSecret: self.apiSecret,
115
+ xUserId: self.publisherUserID,
116
+ xSdkPlatform: AcmoConfig.SDK_PLATFORM,
117
+ xSdkVersion: AcmoConfig.SDK_VERSION,
118
+ userAgent: UIDevice.current.systemName + "/" + UIDevice.current.systemVersion,
119
+ languageCode: Locale.current.languageCode ?? "en",
120
+ premiumColor: acmoInitModel.data.publisherApp.premiumColor,
121
+ headerColor: acmoInitModel.data.publisherApp.headerColor,
122
+ mainColor: acmoInitModel.data.publisherApp.mainColor
123
+ )
124
+
125
+ completion(headers)
126
+ }
127
+ }
128
+
129
+ task.resume()
130
+ self.log("Network request started")
131
+ }
132
+
133
+ if #available(iOS 14, *) {
134
+ self.log("Requesting tracking authorization for iOS 14+")
135
+ ATTrackingManager.requestTrackingAuthorization { status in
136
+ switch status {
137
+ case .authorized:
138
+ advertisingId = ASIdentifierManager.shared().advertisingIdentifier.uuidString
139
+ self.log("Tracking authorized. Advertising ID: \(advertisingId)")
140
+ case .denied, .restricted, .notDetermined:
141
+ advertisingId = ""
142
+ self.log("Tracking not authorized or restricted")
143
+ @unknown default:
144
+ self.log("Unknown tracking status")
145
+ }
146
+ finalizeLogin()
147
+ }
148
+ } else {
149
+ advertisingId = ASIdentifierManager.shared().advertisingIdentifier.uuidString
150
+ self.log("iOS version < 14. Advertising ID: \(advertisingId)")
151
+ finalizeLogin()
152
+ }
153
+ }
154
+
155
+
156
+
157
+
158
+ public func showOffers(_ launchMode: Int = 3, route: String? = nil, campaignID: Int? = nil) {
159
+ self.initializationWait.wait()
160
+ var campaignIDString: String = "0"
161
+ if let campaignIDValue = campaignID {
162
+ campaignIDString = String(campaignIDValue)
163
+ }
164
+ let urlString =
165
+ "https://websdk.tyrads.com/?apiKey=\(Tyrads.instance.apiKey)&apiSecret=\(Tyrads.instance.apiSecret)&userID=\(Tyrads.instance.publisherUserID)&newUser=\(Tyrads.instance.newUser)&platform=\(AcmoConfig.SDK_PLATFORM)&hc=\(Tyrads.instance.loginData?.data.publisherApp.headerColor ?? "")&mc=\(Tyrads.instance.loginData?.data.publisherApp.mainColor ?? "")&launchMode=\(launchMode)&route=\(route ?? "")&campaignID=\(campaignIDString)&lang=\(Tyrads.instance.currentLanguage)&av=\(AcmoConfig.ACMO_VERSION)"
166
+
167
+ do {
168
+ guard let url = URL(string: urlString) else {
169
+ throw NSError(domain: "TyradsSdk", code: 1, userInfo: [NSLocalizedDescriptionKey: "Invalid URL"])
170
+ }
171
+
172
+ switch launchMode {
173
+ case 1, 2:
174
+ DispatchQueue.main.async {
175
+ let webView = WKWebView(frame: UIScreen.main.bounds)
176
+ webView.load(URLRequest(url: url))
177
+
178
+ let viewController = UIViewController()
179
+ viewController.view = webView
180
+ viewController.modalPresentationStyle = .fullScreen // Add this line to set the presentation style
181
+
182
+ if let rootViewController = UIApplication.shared.windows.first?.rootViewController {
183
+ rootViewController.present(viewController, animated: true, completion: nil)
184
+ }
185
+ }
186
+ case 3:
187
+ DispatchQueue.main.async {
188
+ UIApplication.shared.open(url, options: [:], completionHandler: nil)
189
+ }
190
+ default:
191
+ DispatchQueue.main.async {
192
+ UIApplication.shared.open(url, options: [:], completionHandler: nil)
193
+ }
194
+ }
195
+ } catch {
196
+ print("An error occurred: \(error)")
197
+ }
198
+ }
199
+ }
@@ -1,2 +1,2 @@
1
- #import <React/RCTBridgeModule.h>
2
- #import <React/RCTViewManager.h>
1
+ #import <React/RCTBridgeModule.h>
2
+ #import <React/RCTViewManager.h>
package/ios/TyradsSdk.mm CHANGED
@@ -1,11 +1,14 @@
1
- #import <React/RCTBridgeModule.h>
2
-
3
- @interface RCT_EXTERN_MODULE(TyradsSdk, NSObject)
4
-
5
- RCT_EXTERN_METHOD(init:(NSString *)apiKey secretKey:(NSString *)secretKey)
6
- RCT_EXTERN_METHOD(loginUser:(NSString *)userId)
7
- RCT_EXTERN_METHOD(showOffers:(NSInteger)launchMode
8
- route:(NSString)route
9
- campaignID:(NSInteger)campaignID)
10
-
11
- @end
1
+ #import <React/RCTBridgeModule.h>
2
+
3
+ @interface RCT_EXTERN_MODULE(TyradsSdk, NSObject)
4
+
5
+ RCT_EXTERN_METHOD(init:(NSString *)apiKey secretKey:(NSString *)secretKey)
6
+ // RCT_EXTERN_METHOD(loginUser:(NSString *)userId)
7
+ RCT_EXTERN_METHOD(loginUser:(NSString *)userId
8
+ resolver:(RCTPromiseResolveBlock)resolve
9
+ rejecter:(RCTPromiseRejectBlock)reject)
10
+ RCT_EXTERN_METHOD(showOffers:(NSInteger)launchMode
11
+ route:(NSString)route
12
+ campaignID:(NSInteger)campaignID)
13
+
14
+ @end