appsflyer-capacitor-plugin 6.4.4 → 6.8.0-rc1

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.
@@ -5,599 +5,604 @@ import AppsFlyerLib
5
5
 
6
6
  @objc(AppsFlyerPlugin)
7
7
  public class AppsFlyerPlugin: CAPPlugin {
8
- private var conversion = true
9
- private var oaoa = true
10
- private var udl = false
8
+ private var conversion = true
9
+ private var oaoa = true
10
+ private var udl = false
11
+
12
+ override public func load() {
11
13
 
12
- override public func load() {
13
-
14
- NotificationCenter.default.addObserver(self, selector: #selector(self.handleUrlOpened(notification:)), name: Notification.Name.capacitorOpenURL, object: nil)
15
- NotificationCenter.default.addObserver(self, selector: #selector(self.handleUniversalLink(notification:)), name: Notification.Name.capacitorOpenUniversalLink, object: nil)
16
-
17
- }
18
-
19
-
20
- @objc func initSDK(_ call: CAPPluginCall){
21
- let appsflyer = AppsFlyerLib.shared()
22
- guard let devKey = call.getString(AppsFlyerConstants.AF_DEV_KEY) else{
23
- call.reject("devkey is missing")
24
- return
25
- }
26
- guard let appID = call.getString(AppsFlyerConstants.AF_APP_ID) else{
27
- call.reject("appID is missing")
28
- return
29
- }
30
- let attInterval = call.getInt(AppsFlyerConstants.AF_ATT)
31
-
32
- let debug = call.getBool(AppsFlyerConstants.AF_DEBUG, false)
33
- let sandbox = call.getBool(AppsFlyerConstants.AF_SANDBOX, false)
34
- let receiptSandbox = call.getBool(AppsFlyerConstants.AF_RECEIPT_SANDBOX , false)
35
-
36
- conversion = call.getBool(AppsFlyerConstants.AF_CONVERSION_LISTENER, true)
37
- oaoa = call.getBool(AppsFlyerConstants.AF_OAOA, true)
38
- udl = call.getBool(AppsFlyerConstants.AF_UDL, false)
39
-
40
- appsflyer.isDebug = debug
41
- appsflyer.appsFlyerDevKey = devKey
42
- appsflyer.appleAppID = appID
43
- appsflyer.useUninstallSandbox = sandbox
44
- appsflyer.useReceiptValidationSandbox = receiptSandbox
45
-
46
- if let minTime = call.getInt(AppsFlyerConstants.AF_MIN_TIME){
47
- appsflyer.minTimeBetweenSessions = UInt(minTime)
48
- }
49
-
50
- if let timeout = call.getInt(AppsFlyerConstants.AF_DEEP_LINK_TIME_OUT){
51
- appsflyer.deepLinkTimeout = UInt(timeout)
52
- }
53
-
54
- if conversion || oaoa {
55
- appsflyer.delegate = self
56
- }
57
-
58
- if udl {
59
- appsflyer.deepLinkDelegate = self
60
- }
61
-
62
- reportBridgeReady()
63
-
64
- #if !AFSDK_NO_IDFA
65
- if attInterval != nil {
66
- appsflyer.waitForATTUserAuthorization(timeoutInterval: Double(attInterval!))
67
- }
68
- #endif
69
-
70
- NotificationCenter.default.addObserver(self, selector: #selector(sendLaunch), name: UIApplication.didBecomeActiveNotification, object: nil)
71
-
72
- appsflyer.start(completionHandler: { (dictionnary, error) in
73
- if (error != nil){
74
- call.reject(error!.localizedDescription)
75
- return
76
- } else {
77
- call.resolve(["res":"ok"])
78
- return
79
- }
80
- })
81
- }
82
-
83
- @objc func logEvent(_ call: CAPPluginCall){
84
- guard let eventName = call.getString(AppsFlyerConstants.AF_EVENT_NAME) else{
85
- call.reject("missing event name")
86
- return
87
- }
88
- let eventValue = call.getObject(AppsFlyerConstants.AF_EVENT_VALUE)
89
-
90
- AppsFlyerLib.shared().logEvent(name: eventName, values: eventValue) { (response: [String : Any]?, error: Error?) in
91
- if let response = response {
92
- call.resolve(["res":response])
93
- }
94
- if let error = error {
95
- call.reject(error.localizedDescription, nil, error)
96
- }
97
- }
98
- }
99
-
100
- @objc func setCustomerUserId(_ call: CAPPluginCall){
101
- guard let cuid = call.getString(AppsFlyerConstants.AF_CUID) else {
102
- call.reject("Invalid Customer User ID")
103
- return
104
- }
105
- AppsFlyerLib.shared().customerUserID = cuid
106
-
107
- }
14
+ NotificationCenter.default.addObserver(self, selector: #selector(self.handleUrlOpened(notification:)), name: Notification.Name.capacitorOpenURL, object: nil)
15
+ NotificationCenter.default.addObserver(self, selector: #selector(self.handleUniversalLink(notification:)), name: Notification.Name.capacitorOpenUniversalLink, object: nil)
108
16
 
109
- @objc func setCurrencyCode(_ call: CAPPluginCall){
110
- guard let code = call.getString(AppsFlyerConstants.AF_CURRENCY_CODE) else {
111
- call.reject("Invalid Currency Code")
112
- return
113
- }
114
- AppsFlyerLib.shared().currencyCode = code
115
-
116
-
17
+ }
18
+
19
+
20
+ @objc func initSDK(_ call: CAPPluginCall){
21
+ let appsflyer = AppsFlyerLib.shared()
22
+ guard let devKey = call.getString(AppsFlyerConstants.AF_DEV_KEY) else{
23
+ call.reject("devkey is missing")
24
+ return
117
25
  }
118
-
119
- @objc func updateServerUninstallToken(_ call: CAPPluginCall){
120
- guard let token = call.getString(AppsFlyerConstants.AF_TOKEN) else {
121
- call.reject("Invalid device token")
122
-
123
- return
124
- }
125
-
126
- guard let deviceTokenData = token.hexadecimalToData else{
127
- call.reject("Invalid device token")
128
- return
129
- }
130
- AppsFlyerLib.shared().registerUninstall(deviceTokenData)
26
+ guard let appID = call.getString(AppsFlyerConstants.AF_APP_ID) else{
27
+ call.reject("appID is missing")
28
+ return
131
29
  }
30
+ let attInterval = call.getInt(AppsFlyerConstants.AF_ATT)
132
31
 
133
- @objc func setAppInviteOneLink(_ call: CAPPluginCall){
134
- guard let id = call.getString(AppsFlyerConstants.AF_ONELINK_ID) else {
135
- call.reject("Onelink id is missing")
136
- return
137
- }
138
- AppsFlyerLib.shared().appInviteOneLinkID = id
139
-
140
- }
32
+ let debug = call.getBool(AppsFlyerConstants.AF_DEBUG, false)
33
+ let sandbox = call.getBool(AppsFlyerConstants.AF_SANDBOX, false)
34
+ let receiptSandbox = call.getBool(AppsFlyerConstants.AF_RECEIPT_SANDBOX , false)
35
+
36
+ conversion = call.getBool(AppsFlyerConstants.AF_CONVERSION_LISTENER, true)
37
+ oaoa = call.getBool(AppsFlyerConstants.AF_OAOA, true)
38
+ udl = call.getBool(AppsFlyerConstants.AF_UDL, false)
141
39
 
142
- @objc func setOneLinkCustomDomain(_ call: CAPPluginCall){
143
- guard let arr = call.getArray(AppsFlyerConstants.AF_ONELINK_DOMAIN) else {
144
- call.reject("Domains are missing")
145
- return
146
- }
147
- var domains :[String] = []
148
- for dom in arr {
149
- domains.append(dom as! String)
150
- }
151
- AppsFlyerLib.shared().oneLinkCustomDomains = domains
152
-
40
+ appsflyer.isDebug = debug
41
+ appsflyer.appsFlyerDevKey = devKey
42
+ appsflyer.appleAppID = appID
43
+ appsflyer.useUninstallSandbox = sandbox
44
+ appsflyer.useReceiptValidationSandbox = receiptSandbox
45
+
46
+ if let minTime = call.getInt(AppsFlyerConstants.AF_MIN_TIME){
47
+ appsflyer.minTimeBetweenSessions = UInt(minTime)
48
+ }
49
+
50
+ if let timeout = call.getInt(AppsFlyerConstants.AF_DEEP_LINK_TIME_OUT){
51
+ appsflyer.deepLinkTimeout = UInt(timeout)
153
52
  }
154
53
 
155
- @objc func appendParametersToDeepLinkingURL(_ call: CAPPluginCall){
156
- guard let contains = call.getString(AppsFlyerConstants.AF_CONTAINS) else {
157
- return
158
- }
159
- guard let parameters = call.getObject(AppsFlyerConstants.AF_PARAMETERS) else {
160
- return
161
- }
162
- var params: [String:String] = [:]
163
- for (k,v) in parameters{
164
- params[k] = (v as! String)
165
- }
166
- AppsFlyerLib.shared().appendParametersToDeeplinkURL(contains: contains, parameters:params )
167
-
168
- }
169
-
170
-
171
- @objc func setResolveDeepLinkURLs(_ call: CAPPluginCall){
172
- guard let arr = call.getArray(AppsFlyerConstants.AF_DEEPLINK_URLS) else {
173
- call.reject("URLs are missing")
174
- return
175
- }
176
- var urls :[String] = []
177
- for url in arr {
178
- urls.append(url as! String)
179
- }
180
- AppsFlyerLib.shared().oneLinkCustomDomains = urls
181
-
182
- }
183
-
184
- @objc func addPushNotificationDeepLinkPath(_ call: CAPPluginCall){
185
- guard let arr = call.getArray(AppsFlyerConstants.AF_PATH) else {
186
- call.reject("Path is missing")
187
- return
188
- }
189
- var path :[String] = []
190
- for p in arr {
191
- path.append(p as! String)
192
- }
193
- AppsFlyerLib.shared().addPushNotificationDeepLinkPath(path)
194
-
195
- }
196
-
197
- @available(*, deprecated, message: "Use setSharingFilterForPartners")
198
- @objc func setSharingFilter(_ call: CAPPluginCall){
199
- let filters = call.getArray(AppsFlyerConstants.AF_FILTERS , String.self)
200
-
201
- AppsFlyerLib.shared().sharingFilter = filters
202
-
203
- }
204
-
205
- @available(*, deprecated, message: "Use setSharingFilterForPartners")
206
- @objc func setSharingFilterForAllPartners(_ call: CAPPluginCall){
207
-
208
- AppsFlyerLib.shared().setSharingFilterForAllPartners()
209
-
210
- }
211
-
212
- @objc func setSharingFilterForPartners(_ call: CAPPluginCall){
213
- guard let filters = call.getArray(AppsFlyerConstants.AF_FILTERS , String.self) else{
214
- return call.reject("cannot extract the filters value")
215
- }
216
-
217
- AppsFlyerLib.shared().setSharingFilterForPartners(filters)
218
-
219
- }
220
-
221
- @objc func setAdditionalData(_ call: CAPPluginCall){
222
- guard let data = call.getObject(AppsFlyerConstants.AF_ADDITIONAL_DATA) else {
223
- call.reject("Data is missing")
224
- return
225
- }
226
- AppsFlyerLib.shared().customData = data
227
-
228
- }
229
-
230
-
231
- @objc func getAppsFlyerUID(_ call: CAPPluginCall){
232
- let uid = AppsFlyerLib.shared().getAppsFlyerUID()
233
- call.resolve(["uid":uid])
234
-
235
- }
236
-
237
- @objc func anonymizeUser(_ call: CAPPluginCall){
238
- guard let anonymize = call.getBool(AppsFlyerConstants.AF_ANONYMIZE_USER) else{
239
- call.reject("Missing boolean value anonymizeUser")
240
- return
241
- }
242
- AppsFlyerLib.shared().anonymizeUser = anonymize
243
-
244
- }
245
-
246
- @objc func stop(_ call: CAPPluginCall){
247
- let stop = call.getBool(AppsFlyerConstants.AF_STOP)
248
- if stop != nil {
249
- AppsFlyerLib.shared().isStopped = stop!
250
- }
251
- call.resolve([AppsFlyerConstants.AF_IS_STOP : AppsFlyerLib.shared().isStopped ])
252
- }
253
-
254
- @objc func disableSKAdNetwork(_ call: CAPPluginCall){
255
- guard let disable = call.getBool(AppsFlyerConstants.AF_DISABLE_SKAD) else {
256
- call.reject("Missing boolean value shouldDisable")
257
- return
258
- }
259
- AppsFlyerLib.shared().disableSKAdNetwork = disable
260
-
261
- }
262
-
263
- #if !AFSDK_NO_IDFA
264
- @objc func disableAdvertisingIdentifier(_ call: CAPPluginCall){
265
- guard let disable = call.getBool(AppsFlyerConstants.AF_DISABLE_SKAD) else {
266
- call.reject("Missing boolean value shouldDisable")
267
- return
268
- }
269
- AppsFlyerLib.shared().disableAdvertisingIdentifier = disable
270
-
271
- }
272
- #endif
54
+ if conversion || oaoa {
55
+ appsflyer.delegate = self
56
+ }
57
+
58
+ if udl {
59
+ appsflyer.deepLinkDelegate = self
60
+ }
273
61
 
274
- @objc func disableCollectASA(_ call: CAPPluginCall){
275
- guard let disable = call.getBool(AppsFlyerConstants.AF_DISABLE_SKAD) else {
276
- call.reject("Missing boolean value shouldDisable")
277
- return
278
- }
279
- AppsFlyerLib.shared().disableCollectASA = disable
280
-
281
- }
282
- @objc func setHost(_ call: CAPPluginCall){
283
- let pre = call.getString(AppsFlyerConstants.AF_HOST_PREFIX)
284
- let post = call.getString(AppsFlyerConstants.AF_HOST_POSTFIX)
285
- if (pre != nil && post != nil) {
286
- AppsFlyerLib.shared().setHost(post!, withHostPrefix: pre!)
287
- } else {
288
- call.reject("Missing host prefix and/or host name")
289
- }
62
+ reportBridgeReady()
63
+
64
+ #if !AFSDK_NO_IDFA
65
+ if attInterval != nil {
66
+ appsflyer.waitForATTUserAuthorization(timeoutInterval: Double(attInterval!))
290
67
  }
68
+ #endif
291
69
 
292
- @objc func generateInviteLink(_ call: CAPPluginCall){
293
- AppsFlyerShareInviteHelper.generateInviteUrl(linkGenerator:
294
- {(_ generator: AppsFlyerLinkGenerator) -> AppsFlyerLinkGenerator in
295
- if let channel = call.getString(AppsFlyerConstants.AF_CHANNEL){
296
- generator.setChannel(channel)
297
- }
298
- if let brandDomain = call.getString(AppsFlyerConstants.AF_BRAND_DOMAIN){
299
- generator.brandDomain = brandDomain
300
- }
301
- if let campaign = call.getString(AppsFlyerConstants.AF_CAMPAIGN){
302
- generator.setCampaign(campaign)
303
- }
304
- if let referrerName = call.getString(AppsFlyerConstants.AF_REFERRER_NAME){
305
- generator.setReferrerName(referrerName)
306
- }
307
- if let referrerImageURL = call.getString(AppsFlyerConstants.AF_REFERRER_IMAGE_URL){
308
- generator.setReferrerImageURL(referrerImageURL)
309
- }
310
- if let referrerCustomerId = call.getString(AppsFlyerConstants.AF_REFERRER_CUSTOMER_ID){
311
- generator.setReferrerCustomerId(referrerCustomerId)
312
- }
313
- if let baseDeeplink = call.getString(AppsFlyerConstants.AF_BASE_DEEPLINK){
314
- generator.setBaseDeeplink(baseDeeplink)
315
- }
316
- if let addParameters = call.getObject(AppsFlyerConstants.AF_ADD_PARAMETERS){
317
- generator.addParameters(addParameters)
318
- }
319
-
320
- return generator },completionHandler: {url in
321
- if url != nil{
322
- call.resolve([AppsFlyerConstants.AF_LINK_READY: url!.absoluteString])
323
- }else{
324
- call.reject("Failed to generate a link")
325
- }
326
- }
327
- )
328
-
329
- }
330
- @objc func validateAndLogInAppPurchaseAndroid(_ call: CAPPluginCall){
331
- call.unavailable()
332
- }
333
-
334
- @objc func validateAndLogInAppPurchaseIos(_ call: CAPPluginCall){
335
- let currency = call.getString(AppsFlyerConstants.AF_CURRENCY)
336
- let price = call.getString(AppsFlyerConstants.AF_PRICE)
337
- let _inAppPurchase = call.getString(AppsFlyerConstants.AF_IN_APP_PURCHASE)
338
- let transactionId = call.getString(AppsFlyerConstants.AF_TRANSACTION_ID)
339
- let additionalParameters = call.getObject(AppsFlyerConstants.AF_ADDITIONAL_PARAMETERS) ?? [:]
340
-
341
- if currency != nil && price != nil && _inAppPurchase != nil && transactionId != nil && currency != nil {
342
- AppsFlyerLib.shared().validateAndLog(
343
- inAppPurchase: _inAppPurchase,
344
- price: price,
345
- currency: currency,
346
- transactionId: transactionId,
347
- additionalParameters: additionalParameters,
348
- success: {result in
349
- call.resolve(["res":result])
350
- },
351
- failure: { error, result in
352
- guard let emptyInApp = result as? [String:Any]
353
- else
354
- {
355
- call.reject((error)?.localizedDescription ?? "error" )
356
- return
357
- }
358
- call.reject((error)?.localizedDescription ?? "error" , emptyInApp.jsonStringRepresentation)
359
-
360
- })
361
- }else{
362
- call.reject("Missing some fields")
363
- }
364
-
365
-
70
+ NotificationCenter.default.addObserver(self, selector: #selector(sendLaunch), name: UIApplication.didBecomeActiveNotification, object: nil)
71
+
72
+ appsflyer.start(completionHandler: { (dictionnary, error) in
73
+ if (error != nil){
74
+ call.reject(error!.localizedDescription)
75
+ return
76
+ } else {
77
+ call.resolve(["res":"ok"])
78
+ return
79
+ }
80
+ })
81
+ }
82
+
83
+ @objc func logEvent(_ call: CAPPluginCall){
84
+ guard let eventName = call.getString(AppsFlyerConstants.AF_EVENT_NAME) else{
85
+ call.reject("missing event name")
86
+ return
87
+ }
88
+ let eventValue = call.getObject(AppsFlyerConstants.AF_EVENT_VALUE)
89
+
90
+ AppsFlyerLib.shared().logEvent(name: eventName, values: eventValue) { (response: [String : Any]?, error: Error?) in
91
+ if let response = response {
92
+ call.resolve(["res":response])
93
+ }
94
+ if let error = error {
95
+ call.reject(error.localizedDescription, nil, error)
96
+ }
97
+ }
98
+ }
99
+
100
+ @objc func setCustomerUserId(_ call: CAPPluginCall){
101
+ guard let cuid = call.getString(AppsFlyerConstants.AF_CUID) else {
102
+ call.reject("Invalid Customer User ID")
103
+ return
104
+ }
105
+ AppsFlyerLib.shared().customerUserID = cuid
106
+
107
+ }
108
+
109
+ @objc func setCurrencyCode(_ call: CAPPluginCall){
110
+ guard let code = call.getString(AppsFlyerConstants.AF_CURRENCY_CODE) else {
111
+ call.reject("Invalid Currency Code")
112
+ return
366
113
  }
114
+ AppsFlyerLib.shared().currencyCode = code
367
115
 
368
- @objc func getSdkVersion(_ call: CAPPluginCall){
369
-
370
- call.resolve(["res": AppsFlyerLib.shared().getSDKVersion()])
371
- }
372
116
 
373
- @objc func enableFacebookDeferredApplinks(_ call: CAPPluginCall){
374
- guard let enable = call.getBool(AppsFlyerConstants.AF_FB) else {
375
- call.reject("missing boolean value: \(AppsFlyerConstants.AF_FB)")
376
- return
377
- }
378
- if enable{
379
- #if canImport(FacebookCore)
380
- AppsFlyerLib.shared().enableFacebookDeferredApplinks(with: FBSDKAppLinkUtility.self)
381
- call.resolve(["res": "enabled"])
382
- #else
383
- call.reject("Please install FBSDK First!")
384
- #endif
385
- }else{
386
- AppsFlyerLib.shared().enableFacebookDeferredApplinks(with: nil)
387
- call.resolve(["res": "disabled"])
388
-
389
- }
390
-
117
+ }
118
+
119
+ @objc func updateServerUninstallToken(_ call: CAPPluginCall){
120
+ guard let token = call.getString(AppsFlyerConstants.AF_TOKEN) else {
121
+ call.reject("Invalid device token")
122
+
123
+ return
391
124
  }
392
125
 
393
- @objc func sendPushNotificationData(_ call: CAPPluginCall){
394
- let json = call.getObject(AppsFlyerConstants.AF_PUSH_PAYLOAD)
395
- AppsFlyerLib.shared().handlePushNotification(json)
396
-
126
+ guard let deviceTokenData = token.hexadecimalToData else{
127
+ call.reject("Invalid device token")
128
+ return
397
129
  }
398
-
399
-
400
- @objc func setCurrentDeviceLanguage(_ call: CAPPluginCall){
401
- guard let language = call.getString(AppsFlyerConstants.AF_LANGUAGE) else {
402
- call.reject("cannot extract the language value")
403
- return
404
- }
405
- AppsFlyerLib.shared().currentDeviceLanguage = language
406
- call.resolve(["res": "ok"])
407
-
130
+ AppsFlyerLib.shared().registerUninstall(deviceTokenData)
131
+ }
132
+
133
+ @objc func setAppInviteOneLink(_ call: CAPPluginCall){
134
+ guard let id = call.getString(AppsFlyerConstants.AF_ONELINK_ID) else {
135
+ call.reject("Onelink id is missing")
136
+ return
408
137
  }
138
+ AppsFlyerLib.shared().appInviteOneLinkID = id
409
139
 
410
- @objc func logCrossPromoteImpression(_ call: CAPPluginCall){
411
- guard let appID = call.getString(AppsFlyerConstants.AF_APP_ID) else {
412
- call.reject("cannot extract the appID value")
413
- return
414
- }
415
- guard let campaign = call.getString(AppsFlyerConstants.AF_CAMPAIGN) else {
416
- call.reject("cannot extract the campaign value")
417
- return
418
- }
419
- guard let parameters = call.getObject(AppsFlyerConstants.AF_PARAMETERS) else {
420
- call.reject("cannot extract the parameters value")
421
- return
422
- }
423
- AppsFlyerCrossPromotionHelper.logCrossPromoteImpression(appID, campaign: campaign, parameters: parameters)
424
- call.resolve(["res": "ok"])
425
-
140
+ }
141
+
142
+ @objc func setOneLinkCustomDomain(_ call: CAPPluginCall){
143
+ guard let arr = call.getArray(AppsFlyerConstants.AF_ONELINK_DOMAIN) else {
144
+ call.reject("Domains are missing")
145
+ return
426
146
  }
427
-
428
- @objc func setUserEmails(_ call: CAPPluginCall){
429
- guard let emails = call.getArray(AppsFlyerConstants.AF_EMAILS, String.self) else {
430
- call.reject("cannot extract the emails value")
431
- return
432
- }
433
- if let enc = call.getBool(AppsFlyerConstants.AF_ENCODE) , enc == true{
434
- AppsFlyerLib.shared().setUserEmails(emails, with: EmailCryptTypeSHA256)
147
+ var domains :[String] = []
148
+ for dom in arr {
149
+ domains.append(dom as! String)
150
+ }
151
+ AppsFlyerLib.shared().oneLinkCustomDomains = domains
152
+
153
+ }
154
+
155
+ @objc func appendParametersToDeepLinkingURL(_ call: CAPPluginCall){
156
+ guard let contains = call.getString(AppsFlyerConstants.AF_CONTAINS) else {
157
+ return
158
+ }
159
+ guard let parameters = call.getObject(AppsFlyerConstants.AF_PARAMETERS) else {
160
+ return
161
+ }
162
+ var params: [String:String] = [:]
163
+ for (k,v) in parameters{
164
+ params[k] = (v as! String)
165
+ }
166
+ AppsFlyerLib.shared().appendParametersToDeeplinkURL(contains: contains, parameters:params )
167
+
168
+ }
169
+
170
+
171
+ @objc func setResolveDeepLinkURLs(_ call: CAPPluginCall){
172
+ guard let arr = call.getArray(AppsFlyerConstants.AF_DEEPLINK_URLS) else {
173
+ call.reject("URLs are missing")
174
+ return
175
+ }
176
+ var urls :[String] = []
177
+ for url in arr {
178
+ urls.append(url as! String)
179
+ }
180
+ AppsFlyerLib.shared().oneLinkCustomDomains = urls
181
+
182
+ }
183
+
184
+ @objc func addPushNotificationDeepLinkPath(_ call: CAPPluginCall){
185
+ guard let arr = call.getArray(AppsFlyerConstants.AF_PATH) else {
186
+ call.reject("Path is missing")
187
+ return
188
+ }
189
+ var path :[String] = []
190
+ for p in arr {
191
+ path.append(p as! String)
192
+ }
193
+ AppsFlyerLib.shared().addPushNotificationDeepLinkPath(path)
194
+
195
+ }
196
+
197
+ @available(*, deprecated, message: "Use setSharingFilterForPartners")
198
+ @objc func setSharingFilter(_ call: CAPPluginCall){
199
+ let filters = call.getArray(AppsFlyerConstants.AF_FILTERS , String.self)
200
+
201
+ AppsFlyerLib.shared().sharingFilter = filters
202
+
203
+ }
204
+
205
+ @available(*, deprecated, message: "Use setSharingFilterForPartners")
206
+ @objc func setSharingFilterForAllPartners(_ call: CAPPluginCall){
207
+
208
+ AppsFlyerLib.shared().setSharingFilterForAllPartners()
209
+
210
+ }
211
+
212
+ @objc func setSharingFilterForPartners(_ call: CAPPluginCall){
213
+ guard let filters = call.getArray(AppsFlyerConstants.AF_FILTERS , String.self) else{
214
+ return call.reject("cannot extract the filters value")
215
+ }
216
+
217
+ AppsFlyerLib.shared().setSharingFilterForPartners(filters)
218
+
219
+ }
220
+
221
+ @objc func setAdditionalData(_ call: CAPPluginCall){
222
+ guard let data = call.getObject(AppsFlyerConstants.AF_ADDITIONAL_DATA) else {
223
+ call.reject("Data is missing")
224
+ return
225
+ }
226
+ AppsFlyerLib.shared().customData = data
227
+
228
+ }
229
+
230
+
231
+ @objc func getAppsFlyerUID(_ call: CAPPluginCall){
232
+ let uid = AppsFlyerLib.shared().getAppsFlyerUID()
233
+ call.resolve(["uid":uid])
234
+
235
+ }
236
+
237
+ @objc func setDisableNetworkData(_ call: CAPPluginCall){
238
+ call.unavailable("Android only method - has no effact on iOS apps")
239
+ }
435
240
 
241
+ @objc func anonymizeUser(_ call: CAPPluginCall){
242
+ guard let anonymize = call.getBool(AppsFlyerConstants.AF_ANONYMIZE_USER) else{
243
+ call.reject("Missing boolean value anonymizeUser")
244
+ return
245
+ }
246
+ AppsFlyerLib.shared().anonymizeUser = anonymize
247
+
248
+ }
249
+
250
+ @objc func stop(_ call: CAPPluginCall){
251
+ let stop = call.getBool(AppsFlyerConstants.AF_STOP)
252
+ if stop != nil {
253
+ AppsFlyerLib.shared().isStopped = stop!
254
+ }
255
+ call.resolve([AppsFlyerConstants.AF_IS_STOP : AppsFlyerLib.shared().isStopped ])
256
+ }
257
+
258
+ @objc func disableSKAdNetwork(_ call: CAPPluginCall){
259
+ guard let disable = call.getBool(AppsFlyerConstants.AF_DISABLE_SKAD) else {
260
+ call.reject("Missing boolean value shouldDisable")
261
+ return
262
+ }
263
+ AppsFlyerLib.shared().disableSKAdNetwork = disable
264
+
265
+ }
266
+
267
+ #if !AFSDK_NO_IDFA
268
+ @objc func disableAdvertisingIdentifier(_ call: CAPPluginCall){
269
+ guard let disable = call.getBool(AppsFlyerConstants.AF_DISABLE_SKAD) else {
270
+ call.reject("Missing boolean value shouldDisable")
271
+ return
272
+ }
273
+ AppsFlyerLib.shared().disableAdvertisingIdentifier = disable
274
+
275
+ }
276
+ #endif
277
+
278
+ @objc func disableCollectASA(_ call: CAPPluginCall){
279
+ guard let disable = call.getBool(AppsFlyerConstants.AF_DISABLE_SKAD) else {
280
+ call.reject("Missing boolean value shouldDisable")
281
+ return
282
+ }
283
+ AppsFlyerLib.shared().disableCollectASA = disable
284
+
285
+ }
286
+ @objc func setHost(_ call: CAPPluginCall){
287
+ let pre = call.getString(AppsFlyerConstants.AF_HOST_PREFIX)
288
+ let post = call.getString(AppsFlyerConstants.AF_HOST_POSTFIX)
289
+ if (pre != nil && post != nil) {
290
+ AppsFlyerLib.shared().setHost(post!, withHostPrefix: pre!)
291
+ } else {
292
+ call.reject("Missing host prefix and/or host name")
293
+ }
294
+ }
295
+
296
+ @objc func generateInviteLink(_ call: CAPPluginCall){
297
+ AppsFlyerShareInviteHelper.generateInviteUrl(linkGenerator:
298
+ {(_ generator: AppsFlyerLinkGenerator) -> AppsFlyerLinkGenerator in
299
+ if let channel = call.getString(AppsFlyerConstants.AF_CHANNEL){
300
+ generator.setChannel(channel)
301
+ }
302
+ if let brandDomain = call.getString(AppsFlyerConstants.AF_BRAND_DOMAIN){
303
+ generator.brandDomain = brandDomain
304
+ }
305
+ if let campaign = call.getString(AppsFlyerConstants.AF_CAMPAIGN){
306
+ generator.setCampaign(campaign)
307
+ }
308
+ if let referrerName = call.getString(AppsFlyerConstants.AF_REFERRER_NAME){
309
+ generator.setReferrerName(referrerName)
310
+ }
311
+ if let referrerImageURL = call.getString(AppsFlyerConstants.AF_REFERRER_IMAGE_URL){
312
+ generator.setReferrerImageURL(referrerImageURL)
313
+ }
314
+ if let referrerCustomerId = call.getString(AppsFlyerConstants.AF_REFERRER_CUSTOMER_ID){
315
+ generator.setReferrerCustomerId(referrerCustomerId)
316
+ }
317
+ if let baseDeeplink = call.getString(AppsFlyerConstants.AF_BASE_DEEPLINK){
318
+ generator.setBaseDeeplink(baseDeeplink)
319
+ }
320
+ if let addParameters = call.getObject(AppsFlyerConstants.AF_ADD_PARAMETERS){
321
+ generator.addParameters(addParameters)
322
+ }
323
+
324
+ return generator },completionHandler: {url in
325
+ if url != nil{
326
+ call.resolve([AppsFlyerConstants.AF_LINK_READY: url!.absoluteString])
436
327
  }else{
437
- AppsFlyerLib.shared().setUserEmails(emails, with: EmailCryptTypeNone)
438
-
439
- }
440
- call.resolve(["res": "ok"])
441
-
442
- }
443
-
444
- @objc func logLocation(_ call: CAPPluginCall){
445
- guard let longitude = call.getDouble(AppsFlyerConstants.AF_LONGITUDE) else {
446
- call.reject("cannot extract the longitude value")
447
- return
448
- }
449
- guard let latitude = call.getDouble(AppsFlyerConstants.AF_LATITUDE) else {
450
- call.reject("cannot extract the longitude value")
451
- return
452
- }
453
-
454
- AppsFlyerLib.shared().logLocation(longitude: longitude, latitude: latitude)
455
- call.resolve(["res": "ok"])
456
-
457
- }
458
-
459
- @objc func setPhoneNumber(_ call: CAPPluginCall){
460
- guard let phone = call.getString(AppsFlyerConstants.AF_PHONE) else {
461
- call.reject("cannot extract the phone value")
462
- return
463
- }
464
-
465
- AppsFlyerLib.shared().phoneNumber = phone
466
- call.resolve(["res": "ok"])
467
-
468
- }
469
-
470
- @objc func setPartnerData(_ call: CAPPluginCall){
471
- guard let data = call.getObject(AppsFlyerConstants.AF_DATA) else {
472
- call.reject("cannot extract the data value")
473
- return
474
- }
475
- guard let pid = call.getString(AppsFlyerConstants.AF_PARTNER_ID) else {
476
- call.reject("cannot extract the partnerId value")
477
- return
478
- }
479
-
480
- AppsFlyerLib.shared().setPartnerData(partnerId: pid, partnerInfo: data)
481
- call.resolve(["res": "ok"])
482
-
483
- }
484
-
485
- @objc func logInvite(_ call: CAPPluginCall){
486
- guard let data = call.getObject(AppsFlyerConstants.AF_EVENT_PARAMETERS) else {
487
- call.reject("cannot extract the eventParameters value")
488
- return
489
- }
490
- guard let channel = call.getString(AppsFlyerConstants.AF_CHANNEL) else {
491
- call.reject("cannot extract the channel value")
492
- return
493
- }
494
-
495
- AppsFlyerShareInviteHelper.logInvite(channel, parameters: data)
496
- call.resolve(["res": "ok"])
497
-
328
+ call.reject("Failed to generate a link")
329
+ }
330
+ }
331
+ )
332
+
333
+ }
334
+ @objc func validateAndLogInAppPurchaseAndroid(_ call: CAPPluginCall){
335
+ call.unavailable()
336
+ }
337
+
338
+ @objc func validateAndLogInAppPurchaseIos(_ call: CAPPluginCall){
339
+ let currency = call.getString(AppsFlyerConstants.AF_CURRENCY)
340
+ let price = call.getString(AppsFlyerConstants.AF_PRICE)
341
+ let _inAppPurchase = call.getString(AppsFlyerConstants.AF_IN_APP_PURCHASE)
342
+ let transactionId = call.getString(AppsFlyerConstants.AF_TRANSACTION_ID)
343
+ let additionalParameters = call.getObject(AppsFlyerConstants.AF_ADDITIONAL_PARAMETERS) ?? [:]
344
+
345
+ if currency != nil && price != nil && _inAppPurchase != nil && transactionId != nil && currency != nil {
346
+ AppsFlyerLib.shared().validateAndLog(
347
+ inAppPurchase: _inAppPurchase,
348
+ price: price,
349
+ currency: currency,
350
+ transactionId: transactionId,
351
+ additionalParameters: additionalParameters,
352
+ success: {result in
353
+ call.resolve(["res":result])
354
+ },
355
+ failure: { error, result in
356
+ guard let emptyInApp = result as? [String:Any]
357
+ else
358
+ {
359
+ call.reject((error)?.localizedDescription ?? "error" )
360
+ return
361
+ }
362
+ call.reject((error)?.localizedDescription ?? "error" , emptyInApp.jsonStringRepresentation)
363
+
364
+ })
365
+ }else{
366
+ call.reject("Missing some fields")
367
+ }
368
+
369
+
370
+ }
371
+
372
+ @objc func getSdkVersion(_ call: CAPPluginCall){
373
+
374
+ call.resolve(["res": AppsFlyerLib.shared().getSDKVersion()])
375
+ }
376
+
377
+ @objc func enableFacebookDeferredApplinks(_ call: CAPPluginCall){
378
+ guard let enable = call.getBool(AppsFlyerConstants.AF_FB) else {
379
+ call.reject("missing boolean value: \(AppsFlyerConstants.AF_FB)")
380
+ return
381
+ }
382
+ if enable{
383
+ #if canImport(FacebookCore)
384
+ AppsFlyerLib.shared().enableFacebookDeferredApplinks(with: FBSDKAppLinkUtility.self)
385
+ call.resolve(["res": "enabled"])
386
+ #else
387
+ call.reject("Please install FBSDK First!")
388
+ #endif
389
+ }else{
390
+ AppsFlyerLib.shared().enableFacebookDeferredApplinks(with: nil)
391
+ call.resolve(["res": "disabled"])
392
+
393
+ }
394
+
395
+ }
396
+
397
+ @objc func sendPushNotificationData(_ call: CAPPluginCall){
398
+ let json = call.getObject(AppsFlyerConstants.AF_PUSH_PAYLOAD)
399
+ AppsFlyerLib.shared().handlePushNotification(json)
400
+
401
+ }
402
+
403
+
404
+ @objc func setCurrentDeviceLanguage(_ call: CAPPluginCall){
405
+ guard let language = call.getString(AppsFlyerConstants.AF_LANGUAGE) else {
406
+ call.reject("cannot extract the language value")
407
+ return
408
+ }
409
+ AppsFlyerLib.shared().currentDeviceLanguage = language
410
+ call.resolve(["res": "ok"])
411
+
412
+ }
413
+
414
+ @objc func logCrossPromoteImpression(_ call: CAPPluginCall){
415
+ guard let appID = call.getString(AppsFlyerConstants.AF_APP_ID) else {
416
+ call.reject("cannot extract the appID value")
417
+ return
418
+ }
419
+ guard let campaign = call.getString(AppsFlyerConstants.AF_CAMPAIGN) else {
420
+ call.reject("cannot extract the campaign value")
421
+ return
422
+ }
423
+ guard let parameters = call.getObject(AppsFlyerConstants.AF_PARAMETERS) else {
424
+ call.reject("cannot extract the parameters value")
425
+ return
426
+ }
427
+ AppsFlyerCrossPromotionHelper.logCrossPromoteImpression(appID, campaign: campaign, parameters: parameters)
428
+ call.resolve(["res": "ok"])
429
+
430
+ }
431
+
432
+ @objc func setUserEmails(_ call: CAPPluginCall){
433
+ guard let emails = call.getArray(AppsFlyerConstants.AF_EMAILS, String.self) else {
434
+ call.reject("cannot extract the emails value")
435
+ return
436
+ }
437
+ if let enc = call.getBool(AppsFlyerConstants.AF_ENCODE) , enc == true{
438
+ AppsFlyerLib.shared().setUserEmails(emails, with: EmailCryptTypeSHA256)
439
+
440
+ }else{
441
+ AppsFlyerLib.shared().setUserEmails(emails, with: EmailCryptTypeNone)
442
+
443
+ }
444
+ call.resolve(["res": "ok"])
445
+
446
+ }
447
+
448
+ @objc func logLocation(_ call: CAPPluginCall){
449
+ guard let longitude = call.getDouble(AppsFlyerConstants.AF_LONGITUDE) else {
450
+ call.reject("cannot extract the longitude value")
451
+ return
452
+ }
453
+ guard let latitude = call.getDouble(AppsFlyerConstants.AF_LATITUDE) else {
454
+ call.reject("cannot extract the longitude value")
455
+ return
456
+ }
457
+
458
+ AppsFlyerLib.shared().logLocation(longitude: longitude, latitude: latitude)
459
+ call.resolve(["res": "ok"])
460
+
461
+ }
462
+
463
+ @objc func setPhoneNumber(_ call: CAPPluginCall){
464
+ guard let phone = call.getString(AppsFlyerConstants.AF_PHONE) else {
465
+ call.reject("cannot extract the phone value")
466
+ return
467
+ }
468
+
469
+ AppsFlyerLib.shared().phoneNumber = phone
470
+ call.resolve(["res": "ok"])
471
+
472
+ }
473
+
474
+ @objc func setPartnerData(_ call: CAPPluginCall){
475
+ guard let data = call.getObject(AppsFlyerConstants.AF_DATA) else {
476
+ call.reject("cannot extract the data value")
477
+ return
478
+ }
479
+ guard let pid = call.getString(AppsFlyerConstants.AF_PARTNER_ID) else {
480
+ call.reject("cannot extract the partnerId value")
481
+ return
482
+ }
483
+
484
+ AppsFlyerLib.shared().setPartnerData(partnerId: pid, partnerInfo: data)
485
+ call.resolve(["res": "ok"])
486
+
487
+ }
488
+
489
+ @objc func logInvite(_ call: CAPPluginCall){
490
+ guard let data = call.getObject(AppsFlyerConstants.AF_EVENT_PARAMETERS) else {
491
+ call.reject("cannot extract the eventParameters value")
492
+ return
498
493
  }
494
+ guard let channel = call.getString(AppsFlyerConstants.AF_CHANNEL) else {
495
+ call.reject("cannot extract the channel value")
496
+ return
497
+ }
498
+
499
+ AppsFlyerShareInviteHelper.logInvite(channel, parameters: data)
500
+ call.resolve(["res": "ok"])
501
+
502
+ }
499
503
  }
500
504
 
501
505
  extension AppsFlyerPlugin{
502
- private func reportBridgeReady(){
503
- AppsFlyerAttribution.shared.bridgReady = true
504
- NotificationCenter.default.post(name: Notification.Name.appsflyerBridge, object: nil)
505
- }
506
-
507
- @objc private func sendLaunch(){
508
- AppsFlyerLib.shared().start()
509
- }
510
-
511
- @objc func handleUrlOpened(notification: NSNotification) {
512
- guard let object = notification.object as? [String: Any?] else {
513
- return
514
- }
515
- guard let url = object["url"] else {
516
- afLogger(msg: "handleUrlOpened url is nil")
517
- return
518
- }
519
- guard let options = object["options"] else {
520
- afLogger(msg: "handleUrlOpened options is nil")
521
-
522
- return
523
- }
524
- afLogger(msg: "handleUrlOpened with \((url as! URL).absoluteString)")
525
- AppsFlyerAttribution.shared.handleOpenUrl(open: url as! URL, options: options as! [UIApplication.OpenURLOptionsKey: Any])
526
-
527
- }
528
-
529
- @objc func handleUniversalLink(notification: NSNotification) {
530
- guard let object = notification.object as? [String: Any?] else {
531
- return
532
- }
533
- let user = NSUserActivity(activityType: NSUserActivityTypeBrowsingWeb)
534
- guard let url = object["url"] else {
535
- afLogger(msg: "handleUrlOpened options is url")
536
- return
537
- }
538
- user.webpageURL = (url as! URL)
539
- afLogger(msg: "handleUniversalLink with \(user.webpageURL?.absoluteString ?? "null")")
540
- AppsFlyerAttribution.shared.continueUserActivity(userActivity: user)
541
-
542
- }
543
-
506
+ private func reportBridgeReady(){
507
+ AppsFlyerAttribution.shared.bridgReady = true
508
+ NotificationCenter.default.post(name: Notification.Name.appsflyerBridge, object: nil)
509
+ }
510
+
511
+ @objc private func sendLaunch(){
512
+ AppsFlyerLib.shared().start()
513
+ }
514
+
515
+ @objc func handleUrlOpened(notification: NSNotification) {
516
+ guard let object = notification.object as? [String: Any?] else {
517
+ return
518
+ }
519
+ guard let url = object["url"] else {
520
+ afLogger(msg: "handleUrlOpened url is nil")
521
+ return
522
+ }
523
+ guard let options = object["options"] else {
524
+ afLogger(msg: "handleUrlOpened options is nil")
525
+
526
+ return
527
+ }
528
+ afLogger(msg: "handleUrlOpened with \((url as! URL).absoluteString)")
529
+ AppsFlyerAttribution.shared.handleOpenUrl(open: url as! URL, options: options as! [UIApplication.OpenURLOptionsKey: Any])
530
+
531
+ }
532
+
533
+ @objc func handleUniversalLink(notification: NSNotification) {
534
+ guard let object = notification.object as? [String: Any?] else {
535
+ return
536
+ }
537
+ let user = NSUserActivity(activityType: NSUserActivityTypeBrowsingWeb)
538
+ guard let url = object["url"] else {
539
+ afLogger(msg: "handleUrlOpened options is url")
540
+ return
541
+ }
542
+ user.webpageURL = (url as! URL)
543
+ afLogger(msg: "handleUniversalLink with \(user.webpageURL?.absoluteString ?? "null")")
544
+ AppsFlyerAttribution.shared.continueUserActivity(userActivity: user)
545
+
546
+ }
547
+
544
548
  }
545
549
 
546
550
  extension AppsFlyerPlugin : AppsFlyerLibDelegate {
547
- public func onConversionDataSuccess(_ conversionInfo: [AnyHashable : Any]) {
548
- let json : [String: Any] = ["callbackName":"onConversionDataSuccess", "data":conversionInfo]
549
- self.notifyListeners(AppsFlyerConstants.CONVERSION_CALLBACK, data: json)
550
-
551
- }
552
-
553
- public func onConversionDataFail(_ error: Error) {
554
- let json : [String: Any] = ["callbackName":"onConversionDataFail", "status":error.localizedDescription]
555
- self.notifyListeners(AppsFlyerConstants.CONVERSION_CALLBACK, data: json)
556
- }
557
- public func onAppOpenAttribution(_ attributionData: [AnyHashable : Any]) {
558
- let json : [String: Any] = ["callbackName":"onAppOpenAttribution", "data":attributionData]
559
- self.notifyListeners(AppsFlyerConstants.OAOA_CALLBACK, data: json)
560
- }
561
-
562
- public func onAppOpenAttributionFailure(_ error: Error) {
563
- let json : [String: Any] = ["callbackName":"onAppOpenAttributionFailure", "status":error.localizedDescription]
564
- self.notifyListeners(AppsFlyerConstants.OAOA_CALLBACK, data: json)
565
-
566
- }
567
-
551
+ public func onConversionDataSuccess(_ conversionInfo: [AnyHashable : Any]) {
552
+ let json : [String: Any] = ["callbackName":"onConversionDataSuccess", "data":conversionInfo]
553
+ self.notifyListeners(AppsFlyerConstants.CONVERSION_CALLBACK, data: json)
554
+
555
+ }
556
+
557
+ public func onConversionDataFail(_ error: Error) {
558
+ let json : [String: Any] = ["callbackName":"onConversionDataFail", "status":error.localizedDescription]
559
+ self.notifyListeners(AppsFlyerConstants.CONVERSION_CALLBACK, data: json)
560
+ }
561
+ public func onAppOpenAttribution(_ attributionData: [AnyHashable : Any]) {
562
+ let json : [String: Any] = ["callbackName":"onAppOpenAttribution", "data":attributionData]
563
+ self.notifyListeners(AppsFlyerConstants.OAOA_CALLBACK, data: json)
564
+ }
565
+
566
+ public func onAppOpenAttributionFailure(_ error: Error) {
567
+ let json : [String: Any] = ["callbackName":"onAppOpenAttributionFailure", "status":error.localizedDescription]
568
+ self.notifyListeners(AppsFlyerConstants.OAOA_CALLBACK, data: json)
569
+
570
+ }
571
+
568
572
  }
569
573
 
570
574
 
571
575
  // Mark -
572
576
  extension AppsFlyerPlugin : DeepLinkDelegate{
573
- public func didResolveDeepLink(_ result: DeepLinkResult) {
574
- var json : [String: Any] = [:]
575
-
576
- switch result.status {
577
- case .notFound :
578
- json["status"] = "NOT_FOUND"
579
- case .failure :
580
- json["status"] = "FAILURE"
581
- case .found :
582
- json["status"] = "FOUND"
583
- }
584
-
585
- if result.error != nil {
586
- json["error"] = result.error!.localizedDescription
587
- }
588
- if result.deepLink != nil {
589
- json["deepLink"] = result.deepLink!.clickEvent
590
-
591
- }
592
- self.notifyListeners(AppsFlyerConstants.UDL_CALLBACK, data: json)
577
+ public func didResolveDeepLink(_ result: DeepLinkResult) {
578
+ var json : [String: Any] = [:]
579
+
580
+ switch result.status {
581
+ case .notFound :
582
+ json["status"] = "NOT_FOUND"
583
+ case .failure :
584
+ json["status"] = "FAILURE"
585
+ case .found :
586
+ json["status"] = "FOUND"
593
587
  }
594
588
 
589
+ if result.error != nil {
590
+ json["error"] = result.error!.localizedDescription
591
+ }
592
+ if result.deepLink != nil {
593
+ var deepLinkDic = result.deepLink!.clickEvent
594
+ deepLinkDic["is_deferred"] = result.deepLink!.isDeferred
595
+ json["deepLink"] = deepLinkDic
596
+ }
597
+ self.notifyListeners(AppsFlyerConstants.UDL_CALLBACK, data: json)
598
+ }
599
+
595
600
  }
596
601
 
597
602
  extension AppsFlyerPlugin{
598
- private func afLogger(msg : String){
599
- NSLog ("AppsFlyer [Debug][Capacitor]: \(msg)");
600
- }
603
+ private func afLogger(msg : String){
604
+ NSLog ("AppsFlyer [Debug][Capacitor]: \(msg)");
605
+ }
601
606
  }
602
607
 
603
608