diff --git a/ios/AppsFlyerLib.h b/ios/AppsFlyerLib.h index 5207ca75..fba7d4a0 100644 --- a/ios/AppsFlyerLib.h +++ b/ios/AppsFlyerLib.h @@ -13,7 +13,7 @@ #import #import #import -#import +#import NS_ASSUME_NONNULL_BEGIN diff --git a/ios/PCAppsFlyer.h b/ios/PCAppsFlyer.h index 4c2208ef..3bc86ec4 100644 --- a/ios/PCAppsFlyer.h +++ b/ios/PCAppsFlyer.h @@ -9,7 +9,7 @@ #import #if __has_include() #import - +@class TransactionFetcher; @interface PCAppsFlyer: RCTEventEmitter // This is the PCAppsFlyer if the AppsFlyerPurchaseConnector is set to true in the podfile @end diff --git a/ios/PCAppsFlyer.m b/ios/PCAppsFlyer.m index 52ab75a1..e3a3654a 100644 --- a/ios/PCAppsFlyer.m +++ b/ios/PCAppsFlyer.m @@ -7,6 +7,7 @@ #if __has_include() #import +#import "RNAppsFlyer-Swift.h" @implementation PCAppsFlyer @synthesize bridge = _bridge; diff --git a/ios/RNAppsFlyer-Bridging-Header.h b/ios/RNAppsFlyer-Bridging-Header.h index 68728491..43398958 100644 --- a/ios/RNAppsFlyer-Bridging-Header.h +++ b/ios/RNAppsFlyer-Bridging-Header.h @@ -9,7 +9,6 @@ #ifndef _RNAppsFlyer_Bridging_Header_h #define _RNAppsFlyer_Bridging_Header_h -#import #import #import #import diff --git a/ios/RNAppsFlyer.xcodeproj/project.pbxproj b/ios/RNAppsFlyer.xcodeproj/project.pbxproj index 9194410a..a5fa0e62 100644 --- a/ios/RNAppsFlyer.xcodeproj/project.pbxproj +++ b/ios/RNAppsFlyer.xcodeproj/project.pbxproj @@ -196,6 +196,7 @@ CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; COPY_PHASE_STRIP = NO; + DEFINES_MODULE = YES; ENABLE_STRICT_OBJC_MSGSEND = YES; GCC_C_LANGUAGE_STANDARD = gnu99; GCC_DYNAMIC_NO_PIC = NO; @@ -236,6 +237,7 @@ CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; COPY_PHASE_STRIP = YES; + DEFINES_MODULE = YES; ENABLE_NS_ASSERTIONS = NO; ENABLE_STRICT_OBJC_MSGSEND = YES; GCC_C_LANGUAGE_STANDARD = gnu99; diff --git a/ios/TransactionFetcher.swift b/ios/TransactionFetcher.swift index 9bb802e1..8389af2e 100644 --- a/ios/TransactionFetcher.swift +++ b/ios/TransactionFetcher.swift @@ -11,26 +11,37 @@ import StoreKit #if canImport(PurchaseConnector) import PurchaseConnector -@objc class TransactionFetcher: NSObject { - @objc static func fetchTransaction(withId transactionId: String, completion: @escaping (AFSDKTransactionSK2?) -> Void) { - Task { - if #available(iOS 15.0, *) { +@objc(TransactionFetcher) +class TransactionFetcher: NSObject, RCTBridgeModule { + @objc func fetchTransaction(_ transactionId: String, callback: @escaping RCTResponseSenderBlock) { + if #available(iOS 15.0, *) { + Task { do { let allTransactions = try await Transaction.all - if let matchingTransaction = allTransactions.first(where: { $0.id == UInt64(transactionId) }) { + // Unwrap verified transactions + let verifiedTransactions = allTransactions.compactMap { verificationResult -> Transaction? in + switch verificationResult { + case .verified(let transaction): + return transaction + case .unverified(_, _): + return nil + } + } + + if let matchingTransaction = await verifiedTransactions.first(where: { $0.id == UInt64(transactionId) }) { let afTransaction = AFSDKTransactionSK2(transaction: matchingTransaction) - completion(afTransaction) + callback([NSNull(), afTransaction]) } else { - completion(nil) + callback([NSNull(), NSNull()]) } } catch { print("Error fetching transactions: \(error)") - completion(nil) + callback([error.localizedDescription, NSNull()]) } - } else { - print("StoreKit 2 is not available on this iOS version.") - completion(nil) } + } else { + print("StoreKit 2 is not available on this iOS version.") + callback(["StoreKit 2 is not available on this iOS version.", NSNull()]) } } } diff --git a/react-native-appsflyer.podspec b/react-native-appsflyer.podspec index 4790e8cd..89857823 100644 --- a/react-native-appsflyer.podspec +++ b/react-native-appsflyer.podspec @@ -10,7 +10,7 @@ Pod::Spec.new do |s| s.homepage = pkg["homepage"] s.author = pkg["author"] s.source = { :git => pkg["repository"]["url"] } - s.source_files = 'ios/**/*.{h,m}' + s.source_files = 'ios/**/*.{h,m,swift}' s.platform = :ios, "12.0" s.static_framework = true s.dependency 'React'