@tyrads.com/tyrads-sdk 1.1.6-beta.1 → 1.1.6-beta.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,151 +1,151 @@
1
- import Foundation
2
- import UIKit
3
- import AppTrackingTransparency
4
- import AdSupport
5
-
6
-
7
-
8
- /// The TyradsSdk class provides methods for configuring the SDK and displaying offers.
9
- public class Tyrads {
10
- /// Shared instance of the TyradsSdk.
11
- public static let instance = Tyrads()
12
-
13
- private var apiKey: String = ""
14
- private var apiSecret: String = ""
15
- private var publisherUserID: String = ""
16
- private var newUser: Bool = false
17
- private var loginData: AcmoInitModel?
18
- var initializationWait = DispatchSemaphore(value: 0)
19
- private var debugMode: Bool = false
20
-
21
- private func log(_ message: String) {
22
- if debugMode {
23
- NSLog(message)
24
- }
25
- }
26
-
27
- /// Configures the Tyrads SDK with the provided API key and secret key.
28
- ///
29
- /// - Parameters:
30
- /// - apiKey: The API key provided by Tyrads.
31
- /// - secretKey: The secret key provided by Tyrads.
32
- @objc public func configure( apiKey: String, secretKey: String, debugMode: Bool = false) {
33
- self.apiKey = apiKey
34
- self.apiSecret = secretKey
35
- self.debugMode = debugMode
36
- }
37
-
38
- /// Logs in the user with the provided user ID or retrieves the user ID from UserDefaults.
39
- ///
40
- /// - Parameter userID: Optional. The user ID to log in with. If nil, the SDK will attempt to retrieve the user ID from UserDefaults.
41
- @objc public func loginUser(_ userID: String? = nil) {
42
- do {
43
- let userId = userID ?? UserDefaults.standard.string(forKey: "acmo-tyrads-sdk-user-id") ?? ""
44
-
45
- let identifierType = "IDFA"
46
- var advertisingId = ""
47
- if #available(iOS 14, *) {
48
- log("Requesting tracking authorization for iOS 14+")
49
- ATTrackingManager.requestTrackingAuthorization { status in
50
- switch status {
51
- case .authorized:
52
- advertisingId = ASIdentifierManager.shared().advertisingIdentifier.uuidString
53
- self.log("Tracking authorized. Advertising ID: \(advertisingId)")
54
- case .denied:
55
- advertisingId = ""
56
- self.log("Tracking denied")
57
- case .restricted:
58
- advertisingId = ""
59
- self.log("Tracking restricted")
60
- case .notDetermined:
61
- advertisingId = ""
62
- self.log("Tracking not determined")
63
- @unknown default:
64
- self.log("Unknown tracking status")
65
- }
66
- }
67
- } else {
68
- advertisingId = ASIdentifierManager.shared().advertisingIdentifier.uuidString
69
- log("iOS version < 14. Advertising ID: \(advertisingId)")
70
- }
71
- let fd: [String: Any] = [
72
- "publisherUserId": userId,
73
- "platform": "iOS",
74
- "identifierType": identifierType,
75
- "identifier": advertisingId
76
- ]
77
-
78
- log("Initializing with data: \(fd)")
79
-
80
- guard let url = URL(string: AcmoConfig.BASE_URL + "initialize") else {
81
- log("Failed to create URL")
82
- return
83
- }
84
-
85
- var request = URLRequest(url: url)
86
- request.httpMethod = "POST"
87
- request.setValue(AcmoConfig.SDK_PLATFORM, forHTTPHeaderField: "X-SDK-Platform")
88
- request.setValue(AcmoConfig.SDK_VERSION, forHTTPHeaderField: "X-SDK-Version")
89
- request.setValue("application/json", forHTTPHeaderField: "Content-Type")
90
- request.setValue(self.apiKey, forHTTPHeaderField: "X-API-Key")
91
- request.setValue(self.apiSecret, forHTTPHeaderField: "X-API-Secret")
92
-
93
- do {
94
- request.httpBody = try JSONSerialization.data(withJSONObject: fd)
95
- } catch {
96
- log("Failed to serialize request body: \(error)")
97
- return
98
- }
99
-
100
- let task = URLSession.shared.dataTask(with: request) { data, response, error in
101
-
102
- if let error = error {
103
- self.log("Network request failed: \(error)")
104
- return
105
- }
106
-
107
- guard let data = data else {
108
- self.log("No data received from the server")
109
- return
110
- }
111
-
112
- if let responseString = String(data: data, encoding: .utf8) {
113
- self.log("Received response: \(responseString)")
114
-
115
- let jsonData = responseString.data(using: .utf8)!
116
- let decoder = JSONDecoder()
117
- guard let acmoInitModel = try? decoder.decode(AcmoInitModel.self, from: jsonData) else {
118
- self.log("Failed to decode response")
119
- return
120
- }
121
- self.loginData = acmoInitModel
122
- self.publisherUserID = self.loginData?.data.user.publisherUserId ?? ""
123
- self.newUser = self.loginData?.data.newRegisteredUser ?? false
124
- self.log("Login successful. Publisher User ID: \(self.publisherUserID), New User: \(self.newUser)")
125
- self.initializationWait.signal()
126
- }
127
-
128
-
129
- }
130
-
131
- task.resume()
132
- log("Network request started")
133
-
134
-
135
- } catch {
136
- log("An error occurred: \(error)")
137
- }
138
- }
139
-
140
-
141
-
142
- /// Shows the Tyrads offer wall.
143
- @objc public func showOffers() {
144
- self.initializationWait.wait()
145
- let urlString: String = "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 ?? "")";
146
-
147
- if let url = URL(string: urlString) {
148
- UIApplication.shared.open(url, options: [:], completionHandler: { _ in })
149
- }
150
- }
151
- }
1
+ import Foundation
2
+ import UIKit
3
+ import AppTrackingTransparency
4
+ import AdSupport
5
+
6
+
7
+
8
+ /// The TyradsSdk class provides methods for configuring the SDK and displaying offers.
9
+ public class Tyrads {
10
+ /// Shared instance of the TyradsSdk.
11
+ public static let instance = Tyrads()
12
+
13
+ private var apiKey: String = ""
14
+ private var apiSecret: String = ""
15
+ private var publisherUserID: String = ""
16
+ private var newUser: Bool = false
17
+ private var loginData: AcmoInitModel?
18
+ var initializationWait = DispatchSemaphore(value: 0)
19
+ private var debugMode: Bool = false
20
+
21
+ private func log(_ message: String) {
22
+ if debugMode {
23
+ NSLog(message)
24
+ }
25
+ }
26
+
27
+ /// Configures the Tyrads SDK with the provided API key and secret key.
28
+ ///
29
+ /// - Parameters:
30
+ /// - apiKey: The API key provided by Tyrads.
31
+ /// - secretKey: The secret key provided by Tyrads.
32
+ @objc public func configure( apiKey: String, secretKey: String, debugMode: Bool = false) {
33
+ self.apiKey = apiKey
34
+ self.apiSecret = secretKey
35
+ self.debugMode = debugMode
36
+ }
37
+
38
+ /// Logs in the user with the provided user ID or retrieves the user ID from UserDefaults.
39
+ ///
40
+ /// - Parameter userID: Optional. The user ID to log in with. If nil, the SDK will attempt to retrieve the user ID from UserDefaults.
41
+ @objc public func loginUser(_ userID: String? = nil) {
42
+ do {
43
+ let userId = userID ?? UserDefaults.standard.string(forKey: "acmo-tyrads-sdk-user-id") ?? ""
44
+
45
+ let identifierType = "IDFA"
46
+ var advertisingId = ""
47
+ if #available(iOS 14, *) {
48
+ log("Requesting tracking authorization for iOS 14+")
49
+ ATTrackingManager.requestTrackingAuthorization { status in
50
+ switch status {
51
+ case .authorized:
52
+ advertisingId = ASIdentifierManager.shared().advertisingIdentifier.uuidString
53
+ self.log("Tracking authorized. Advertising ID: \(advertisingId)")
54
+ case .denied:
55
+ advertisingId = ""
56
+ self.log("Tracking denied")
57
+ case .restricted:
58
+ advertisingId = ""
59
+ self.log("Tracking restricted")
60
+ case .notDetermined:
61
+ advertisingId = ""
62
+ self.log("Tracking not determined")
63
+ @unknown default:
64
+ self.log("Unknown tracking status")
65
+ }
66
+ }
67
+ } else {
68
+ advertisingId = ASIdentifierManager.shared().advertisingIdentifier.uuidString
69
+ log("iOS version < 14. Advertising ID: \(advertisingId)")
70
+ }
71
+ let fd: [String: Any] = [
72
+ "publisherUserId": userId,
73
+ "platform": "iOS",
74
+ "identifierType": identifierType,
75
+ "identifier": advertisingId
76
+ ]
77
+
78
+ log("Initializing with data: \(fd)")
79
+
80
+ guard let url = URL(string: AcmoConfig.BASE_URL + "initialize") else {
81
+ log("Failed to create URL")
82
+ return
83
+ }
84
+
85
+ var request = URLRequest(url: url)
86
+ request.httpMethod = "POST"
87
+ request.setValue(AcmoConfig.SDK_PLATFORM, forHTTPHeaderField: "X-SDK-Platform")
88
+ request.setValue(AcmoConfig.SDK_VERSION, forHTTPHeaderField: "X-SDK-Version")
89
+ request.setValue("application/json", forHTTPHeaderField: "Content-Type")
90
+ request.setValue(self.apiKey, forHTTPHeaderField: "X-API-Key")
91
+ request.setValue(self.apiSecret, forHTTPHeaderField: "X-API-Secret")
92
+
93
+ do {
94
+ request.httpBody = try JSONSerialization.data(withJSONObject: fd)
95
+ } catch {
96
+ log("Failed to serialize request body: \(error)")
97
+ return
98
+ }
99
+
100
+ let task = URLSession.shared.dataTask(with: request) { data, response, error in
101
+
102
+ if let error = error {
103
+ self.log("Network request failed: \(error)")
104
+ return
105
+ }
106
+
107
+ guard let data = data else {
108
+ self.log("No data received from the server")
109
+ return
110
+ }
111
+
112
+ if let responseString = String(data: data, encoding: .utf8) {
113
+ self.log("Received response: \(responseString)")
114
+
115
+ let jsonData = responseString.data(using: .utf8)!
116
+ let decoder = JSONDecoder()
117
+ guard let acmoInitModel = try? decoder.decode(AcmoInitModel.self, from: jsonData) else {
118
+ self.log("Failed to decode response")
119
+ return
120
+ }
121
+ self.loginData = acmoInitModel
122
+ self.publisherUserID = self.loginData?.data.user.publisherUserId ?? ""
123
+ self.newUser = self.loginData?.data.newRegisteredUser ?? false
124
+ self.log("Login successful. Publisher User ID: \(self.publisherUserID), New User: \(self.newUser)")
125
+ self.initializationWait.signal()
126
+ }
127
+
128
+
129
+ }
130
+
131
+ task.resume()
132
+ log("Network request started")
133
+
134
+
135
+ } catch {
136
+ log("An error occurred: \(error)")
137
+ }
138
+ }
139
+
140
+
141
+
142
+ /// Shows the Tyrads offer wall.
143
+ @objc public func showOffers() {
144
+ self.initializationWait.wait()
145
+ let urlString: String = "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 ?? "")";
146
+
147
+ if let url = URL(string: urlString) {
148
+ UIApplication.shared.open(url, options: [:], completionHandler: { _ in })
149
+ }
150
+ }
151
+ }
@@ -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,9 +1,9 @@
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)
8
-
9
- @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(showOffers)
8
+
9
+ @end
@@ -1,26 +1,26 @@
1
- import Foundation
2
- import UIKit
3
-
4
-
5
- @objc(TyradsSdk)
6
- class TyradsSdk: NSObject {
7
-
8
- @objc
9
- func `init`(_ apiKey: String, secretKey: String) {
10
- NSLog("TyradsModule: init called with apiKey: \(apiKey) and secretKey: \(secretKey)")
11
- Tyrads.instance.configure(apiKey: apiKey, secretKey: secretKey)
12
- }
13
-
14
- @objc
15
- func loginUser(_ userId: String) {
16
- NSLog("TyradsModule: loginUser called with userId: \(userId)")
17
- Tyrads.instance.loginUser(userId)
18
- // Implement your login logic here
19
- }
20
-
21
- @objc
22
- func showOffers() {
23
- NSLog("TyradsModule: showOffers called")
24
- Tyrads.instance.showOffers()
25
- }
26
- }
1
+ import Foundation
2
+ import UIKit
3
+
4
+
5
+ @objc(TyradsSdk)
6
+ class TyradsSdk: NSObject {
7
+
8
+ @objc
9
+ func `init`(_ apiKey: String, secretKey: String) {
10
+ NSLog("TyradsModule: init called with apiKey: \(apiKey) and secretKey: \(secretKey)")
11
+ Tyrads.instance.configure(apiKey: apiKey, secretKey: secretKey)
12
+ }
13
+
14
+ @objc
15
+ func loginUser(_ userId: String) {
16
+ NSLog("TyradsModule: loginUser called with userId: \(userId)")
17
+ Tyrads.instance.loginUser(userId)
18
+ // Implement your login logic here
19
+ }
20
+
21
+ @objc
22
+ func showOffers() {
23
+ NSLog("TyradsModule: showOffers called")
24
+ Tyrads.instance.showOffers()
25
+ }
26
+ }
@@ -1 +1 @@
1
- {"version":3,"names":["_reactNative","require","LINKING_ERROR","Platform","select","ios","default","Tyrads","NativeModules","TyradsSdk","Proxy","get","Error","_default","exports"],"sourceRoot":"..\\..\\src","sources":["index.tsx"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAEA,MAAMC,aAAa,GACjB,qEAAqE,GACrEC,qBAAQ,CAACC,MAAM,CAAC;EAAEC,GAAG,EAAE,gCAAgC;EAAEC,OAAO,EAAE;AAAG,CAAC,CAAC,GACvE,sDAAsD,GACtD,+BAA+B;AAEjC,MAAMC,MAAM,GAAGC,0BAAa,CAACC,SAAS,GAClCD,0BAAa,CAACC,SAAS,GACvB,IAAIC,KAAK,CACP,CAAC,CAAC,EACF;EACEC,GAAGA,CAAA,EAAG;IACJ,MAAM,IAAIC,KAAK,CAACV,aAAa,CAAC;EAChC;AACF,CACF,CAAC;AAAC,IAAAW,QAAA,GAAAC,OAAA,CAAAR,OAAA,GACSC,MAAM","ignoreList":[]}
1
+ {"version":3,"names":["_reactNative","require","LINKING_ERROR","Platform","select","ios","default","Tyrads","NativeModules","TyradsSdk","Proxy","get","Error","_default","exports"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAEA,MAAMC,aAAa,GACjB,qEAAqE,GACrEC,qBAAQ,CAACC,MAAM,CAAC;EAAEC,GAAG,EAAE,gCAAgC;EAAEC,OAAO,EAAE;AAAG,CAAC,CAAC,GACvE,sDAAsD,GACtD,+BAA+B;AAEjC,MAAMC,MAAM,GAAGC,0BAAa,CAACC,SAAS,GAClCD,0BAAa,CAACC,SAAS,GACvB,IAAIC,KAAK,CACP,CAAC,CAAC,EACF;EACEC,GAAGA,CAAA,EAAG;IACJ,MAAM,IAAIC,KAAK,CAACV,aAAa,CAAC;EAChC;AACF,CACF,CAAC;AAAC,IAAAW,QAAA,GAAAC,OAAA,CAAAR,OAAA,GACSC,MAAM","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"names":["NativeModules","Platform","LINKING_ERROR","select","ios","default","Tyrads","TyradsSdk","Proxy","get","Error"],"sourceRoot":"..\\..\\src","sources":["index.tsx"],"mappings":";;AAAA,SAASA,aAAa,EAAEC,QAAQ,QAAQ,cAAc;AAEtD,MAAMC,aAAa,GACjB,qEAAqE,GACrED,QAAQ,CAACE,MAAM,CAAC;EAAEC,GAAG,EAAE,gCAAgC;EAAEC,OAAO,EAAE;AAAG,CAAC,CAAC,GACvE,sDAAsD,GACtD,+BAA+B;AAEjC,MAAMC,MAAM,GAAGN,aAAa,CAACO,SAAS,GAClCP,aAAa,CAACO,SAAS,GACvB,IAAIC,KAAK,CACP,CAAC,CAAC,EACF;EACEC,GAAGA,CAAA,EAAG;IACJ,MAAM,IAAIC,KAAK,CAACR,aAAa,CAAC;EAChC;AACF,CACF,CAAC;AACL,eAAeI,MAAM","ignoreList":[]}
1
+ {"version":3,"names":["NativeModules","Platform","LINKING_ERROR","select","ios","default","Tyrads","TyradsSdk","Proxy","get","Error"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;AAAA,SAASA,aAAa,EAAEC,QAAQ,QAAQ,cAAc;AAEtD,MAAMC,aAAa,GACjB,qEAAqE,GACrED,QAAQ,CAACE,MAAM,CAAC;EAAEC,GAAG,EAAE,gCAAgC;EAAEC,OAAO,EAAE;AAAG,CAAC,CAAC,GACvE,sDAAsD,GACtD,+BAA+B;AAEjC,MAAMC,MAAM,GAAGN,aAAa,CAACO,SAAS,GAClCP,aAAa,CAACO,SAAS,GACvB,IAAIC,KAAK,CACP,CAAC,CAAC,EACF;EACEC,GAAGA,CAAA,EAAG;IACJ,MAAM,IAAIC,KAAK,CAACR,aAAa,CAAC;EAChC;AACF,CACF,CAAC;AACL,eAAeI,MAAM","ignoreList":[]}