@@ -52,18 +52,11 @@ public class OptableSDK: NSObject {
5252 let config : OptableConfig
5353 let api : EdgeAPI
5454
55- /// Initializes the SDK with the provided OptableConfig. On iOS 14+, requests tracking authorization unless skipAdvertisingIdDetection is true.
55+ /// Initializes the SDK with the provided OptableConfig.
5656 @objc
5757 public init ( config: OptableConfig ) {
5858 self . config = config
5959 self . api = EdgeAPI ( config)
60-
61- // Automatically request Tracking Authorization
62- if #available( iOS 14 , * ) {
63- if config. skipAdvertisingIdDetection == false , ATT . canAuthorize {
64- ATT . requestATTAuthorization ( )
65- }
66- }
6760 }
6861
6962 /// OptableSDK version
@@ -98,7 +91,7 @@ public extension OptableSDK {
9891 }
9992 ```
10093 */
101- func identify( _ ids: [ OptableIdentifier ] , _ completion: @escaping ( Result < HTTPURLResponse , Error > ) -> Void ) throws {
94+ func identify( _ ids: [ OptableIdentifier ] , completion: @escaping ( Result < HTTPURLResponse , Error > ) -> Void ) throws {
10295 try _identify ( ids, completion: completion)
10396 }
10497
@@ -327,8 +320,8 @@ public extension OptableSDK {
327320 }
328321}
329322
330- // MARK: - Private
331- private extension OptableSDK {
323+ // MARK: - Internal
324+ extension OptableSDK {
332325 func _identify( _ ids: [ OptableIdentifier ] , completion: @escaping ( Result < HTTPURLResponse , Error > ) -> Void ) throws {
333326 var ids = ids
334327
@@ -360,7 +353,7 @@ private extension OptableSDK {
360353 var ids = ids ?? [ ]
361354
362355 enrichIfNeeded ( ids: & ids)
363-
356+
364357 guard let request = try api. targeting ( ids: ids) else {
365358 throw OptableError . targeting ( " Failed to create targeting request " )
366359 }
@@ -448,19 +441,29 @@ private extension OptableSDK {
448441 }
449442 } ) . resume ( )
450443 }
451-
452- private func enrichIfNeeded( ids: inout [ OptableIdentifier ] ) {
444+
445+ func enrichIfNeeded( ids: inout [ OptableIdentifier ] ) {
453446 // Enrich with Apple IDFA
454447 if config. skipAdvertisingIdDetection == false ,
455448 ATT . advertisingIdentifierAvailable,
456- ATT . advertisingIdentifier != UUID ( uuid: uuid_t ( 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ) ) ,
457- ids. contains ( where: { eid in
458- if case let . appleIDFA( value) = eid, value. isEmpty == false {
459- return true
460- }
461- return false
462- } ) == false {
463- ids. append ( . appleIDFA( ATT . advertisingIdentifier. uuidString) )
449+ ATT . advertisingIdentifier != UUID ( uuid: uuid_t ( 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ) ) {
450+ let systemIDFA = ATT . advertisingIdentifier. uuidString
451+
452+ var idfaMatchingSystemIdxs : [ Int ] = [ ]
453+
454+ for idx in ids. indices {
455+ if case let . appleIDFA( value) = ids [ idx] {
456+ if value == systemIDFA {
457+ idfaMatchingSystemIdxs. append ( idx)
458+ }
459+ }
460+ }
461+
462+ // Remove all matching systemIDFA (deduplicate)
463+ ids. removeCompat ( atOffsets: IndexSet ( idfaMatchingSystemIdxs) )
464+
465+ // Prepend all identifiers with systemIDFA
466+ ids. insert ( . appleIDFA( systemIDFA) , at: ids. startIndex)
464467 }
465468 }
466469
0 commit comments