Skip to content

Commit b1e2a84

Browse files
committed
Working logConsumable function
1 parent 5f529a8 commit b1e2a84

File tree

7 files changed

+195
-22
lines changed

7 files changed

+195
-22
lines changed

ios/AFTransactionFetcher.swift

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
//
2+
// AFTransactionFetcher.swift
3+
// RNAppsFlyer
4+
//
5+
// Created by Amit Levy on 03/03/2025.
6+
// Copyright © 2025 Facebook. All rights reserved.
7+
//
8+
9+
import Foundation
10+
import StoreKit
11+
12+
#if canImport(PurchaseConnector)
13+
import PurchaseConnector
14+
15+
@available(iOS 15.0, *)
16+
@objc(AFTransactionFetcher)
17+
@objcMembers public final class AFTransactionFetcher: NSObject {
18+
19+
@objc static func requiresMainQueueSetup() -> Bool {
20+
return false
21+
}
22+
23+
@objc public func fetchTransaction(transactionId: String, completion: @escaping (AFSDKTransactionSK2?) -> Void) {
24+
guard let transactionIdUInt64 = UInt64(transactionId) else {
25+
print("Invalid transaction ID format.")
26+
completion(nil)
27+
return
28+
}
29+
30+
Task {
31+
do {
32+
let allTransactions = try await Transaction.all
33+
let verifiedTransactions = allTransactions.compactMap { verificationResult -> Transaction? in
34+
if case .verified(let transaction) = verificationResult {
35+
return transaction
36+
}
37+
return nil
38+
}
39+
40+
if let matchingTransaction = await verifiedTransactions.first(where: { $0.id == transactionIdUInt64 }) {
41+
let afTransaction = AFSDKTransactionSK2(transaction: matchingTransaction)
42+
completion(afTransaction)
43+
} else {
44+
completion(nil)
45+
}
46+
} catch {
47+
print("Error fetching transactions: \(error)")
48+
completion(nil)
49+
}
50+
}
51+
}
52+
}
53+
54+
#endif

ios/AppsFlyerLib.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#import <AppsFlyerLib/AppsFlyerDeepLinkResult.h>
1414
#import <AppsFlyerLib/AppsFlyerDeepLink.h>
1515
#import <AppsFlyerLib/AppsFlyerConsent.h>
16-
#import <AppsFlyerLib/AppsFlyerAdRevenueData.h>
16+
#import <AppsFlyerLib/AFAdRevenueData.h>
1717

1818
NS_ASSUME_NONNULL_BEGIN
1919

ios/PCAppsFlyer.m

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
#if __has_include(<PurchaseConnector/PurchaseConnector.h>)
99
#import <PurchaseConnector/PurchaseConnector.h>
10+
#import <react_native_appsflyer-Swift.h>
1011

1112
@implementation PCAppsFlyer
1213
@synthesize bridge = _bridge;
@@ -72,30 +73,33 @@ @implementation PCAppsFlyer
7273
RCT_EXPORT_METHOD(logConsumableTransaction:(NSString *)transactionId
7374
resolver:(RCTPromiseResolveBlock)resolve
7475
rejecter:(RCTPromiseRejectBlock)reject) {
75-
NSLog(@"%@Logging consumable transaction with ID: %@", TAG, transactionId);
76+
NSLog(@"Logging consumable transaction with ID: %@", transactionId);
7677

7778
if (connector == nil) {
7879
reject(connectorNotConfiguredMessage, connectorNotConfiguredMessage, nil);
7980
return;
8081
}
8182

82-
// Call the Swift method via the TransactionFetcher class
83-
/*
84-
[TransactionFetcher fetchTransactionWithId:transactionId completion:^(AFSDKTransactionSK2 * _Nullable afTransaction) {
85-
if (afTransaction) {
86-
// Use the fetched transaction
87-
[connector logConsumableTransaction:afTransaction];
88-
NSLog(@"Logged transaction: %@", transactionId);
89-
resolve(nil);
90-
} else {
91-
// Handle the case where the transaction was not found
92-
NSError *error = [NSError errorWithDomain:@"PCAppsFlyer"
93-
code:404
94-
userInfo:@{NSLocalizedDescriptionKey: @"Transaction not found"}];
95-
reject(@"transaction_not_found", @"Transaction not found", error);
96-
}
97-
}];
98-
*/
83+
if (@available(iOS 15.0, *)) {
84+
AFTransactionFetcher *fetcher = [AFTransactionFetcher new];
85+
[fetcher fetchTransactionWithTransactionId:transactionId completion:^(AFSDKTransactionSK2 * _Nullable afTransaction) {
86+
if (afTransaction) {
87+
[connector logConsumableTransaction:afTransaction];
88+
NSLog(@"Logged transaction: %@", transactionId);
89+
resolve(nil);
90+
} else {
91+
NSError *error = [NSError errorWithDomain:@"PCAppsFlyer"
92+
code:404
93+
userInfo:@{NSLocalizedDescriptionKey: @"Transaction not found"}];
94+
reject(@"transaction_not_found", @"Transaction not found", error);
95+
}
96+
}];
97+
} else {
98+
NSError *error = [NSError errorWithDomain:@"PCAppsFlyer"
99+
code:501
100+
userInfo:@{NSLocalizedDescriptionKey: @"iOS version not supported"}];
101+
reject(@"ios_version_not_supported", @"iOS version not supported", error);
102+
}
99103
}
100104

101105
RCT_EXPORT_METHOD(startObservingTransactions:(RCTPromiseResolveBlock)resolve

ios/RNAppsFlyer-Bridging-Header.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//
2+
// RNAppsFlyer-Bridging-Header.h
3+
// RNAppsFlyer
4+
//
5+
// Created by Amit Levy on 03/03/2025.
6+
// Copyright © 2025 Facebook. All rights reserved.
7+
//
8+
9+
#ifndef RNAppsFlyer_Bridging_Header_h
10+
#define RNAppsFlyer_Bridging_Header_h
11+
12+
13+
#endif /* RNAppsFlyer_Bridging_Header_h */

ios/RNAppsFlyer.xcodeproj/project.pbxproj

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10+
7E7F839A2D75E11A009693C2 /* AppsFlyerAttribution.m in Sources */ = {isa = PBXBuildFile; fileRef = 7E7F83912D75E11A009693C2 /* AppsFlyerAttribution.m */; };
11+
7E7F839C2D75E1F5009693C2 /* AFTransactionFetcher.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7E7F839B2D75E1F5009693C2 /* AFTransactionFetcher.swift */; };
12+
7E7F83A02D75E943009693C2 /* PCAppsFlyer.m in Sources */ = {isa = PBXBuildFile; fileRef = 7E7F839F2D75E943009693C2 /* PCAppsFlyer.m */; };
1013
B3E7B58A1CC2AC0600A0062D /* RNAppsFlyer.m in Sources */ = {isa = PBXBuildFile; fileRef = B3E7B5891CC2AC0600A0062D /* RNAppsFlyer.m */; };
1114
/* End PBXBuildFile section */
1215

@@ -24,6 +27,18 @@
2427

2528
/* Begin PBXFileReference section */
2629
134814201AA4EA6300B7C361 /* libRNAppsFlyer.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libRNAppsFlyer.a; sourceTree = BUILT_PRODUCTS_DIR; };
30+
7E7F838F2D75E11A009693C2 /* AFAdRevenueData.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AFAdRevenueData.h; sourceTree = "<group>"; };
31+
7E7F83902D75E11A009693C2 /* AppsFlyerAttribution.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppsFlyerAttribution.h; sourceTree = "<group>"; };
32+
7E7F83912D75E11A009693C2 /* AppsFlyerAttribution.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppsFlyerAttribution.m; sourceTree = "<group>"; };
33+
7E7F83922D75E11A009693C2 /* AppsFlyerConsent.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppsFlyerConsent.h; sourceTree = "<group>"; };
34+
7E7F83932D75E11A009693C2 /* AppsFlyerDeepLink.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppsFlyerDeepLink.h; sourceTree = "<group>"; };
35+
7E7F83942D75E11A009693C2 /* AppsFlyerDeepLinkObserver.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppsFlyerDeepLinkObserver.h; sourceTree = "<group>"; };
36+
7E7F83952D75E11A009693C2 /* AppsFlyerDeepLinkResult.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppsFlyerDeepLinkResult.h; sourceTree = "<group>"; };
37+
7E7F83962D75E11A009693C2 /* AppsFlyerLib.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppsFlyerLib.h; sourceTree = "<group>"; };
38+
7E7F83972D75E11A009693C2 /* PCAppsFlyer.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PCAppsFlyer.h; sourceTree = "<group>"; };
39+
7E7F839B2D75E1F5009693C2 /* AFTransactionFetcher.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AFTransactionFetcher.swift; sourceTree = "<group>"; };
40+
7E7F839D2D75E257009693C2 /* RNAppsFlyer-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "RNAppsFlyer-Bridging-Header.h"; sourceTree = "<group>"; };
41+
7E7F839F2D75E943009693C2 /* PCAppsFlyer.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = PCAppsFlyer.m; sourceTree = "<group>"; };
2742
943704C6209F6734005B3A22 /* AppsFlyerShareInviteHelper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppsFlyerShareInviteHelper.h; sourceTree = "<group>"; };
2843
943704C7209F6734005B3A22 /* AppsFlyerLinkGenerator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppsFlyerLinkGenerator.h; sourceTree = "<group>"; };
2944
943704C9209F6735005B3A22 /* AppsFlyerCrossPromotionHelper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppsFlyerCrossPromotionHelper.h; sourceTree = "<group>"; };
@@ -56,8 +71,20 @@
5671
943704C9209F6735005B3A22 /* AppsFlyerCrossPromotionHelper.h */,
5772
943704C7209F6734005B3A22 /* AppsFlyerLinkGenerator.h */,
5873
943704C6209F6734005B3A22 /* AppsFlyerShareInviteHelper.h */,
74+
7E7F838F2D75E11A009693C2 /* AFAdRevenueData.h */,
75+
7E7F83922D75E11A009693C2 /* AppsFlyerConsent.h */,
76+
7E7F83932D75E11A009693C2 /* AppsFlyerDeepLink.h */,
77+
7E7F83942D75E11A009693C2 /* AppsFlyerDeepLinkObserver.h */,
78+
7E7F83952D75E11A009693C2 /* AppsFlyerDeepLinkResult.h */,
79+
7E7F83962D75E11A009693C2 /* AppsFlyerLib.h */,
80+
7E7F83902D75E11A009693C2 /* AppsFlyerAttribution.h */,
81+
7E7F83912D75E11A009693C2 /* AppsFlyerAttribution.m */,
82+
7E7F83972D75E11A009693C2 /* PCAppsFlyer.h */,
83+
7E7F839F2D75E943009693C2 /* PCAppsFlyer.m */,
5984
B3E7B5881CC2AC0600A0062D /* RNAppsFlyer.h */,
6085
B3E7B5891CC2AC0600A0062D /* RNAppsFlyer.m */,
86+
7E7F839D2D75E257009693C2 /* RNAppsFlyer-Bridging-Header.h */,
87+
7E7F839B2D75E1F5009693C2 /* AFTransactionFetcher.swift */,
6188
134814211AA4EA7D00B7C361 /* Products */,
6289
);
6390
sourceTree = "<group>";
@@ -121,6 +148,9 @@
121148
buildActionMask = 2147483647;
122149
files = (
123150
B3E7B58A1CC2AC0600A0062D /* RNAppsFlyer.m in Sources */,
151+
7E7F839A2D75E11A009693C2 /* AppsFlyerAttribution.m in Sources */,
152+
7E7F839C2D75E1F5009693C2 /* AFTransactionFetcher.swift in Sources */,
153+
7E7F83A02D75E943009693C2 /* PCAppsFlyer.m in Sources */,
124154
);
125155
runOnlyForDeploymentPostprocessing = 0;
126156
};
@@ -204,7 +234,9 @@
204234
58B511F01A9E6C8500147676 /* Debug */ = {
205235
isa = XCBuildConfiguration;
206236
buildSettings = {
237+
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
207238
CLANG_ENABLE_MODULES = YES;
239+
DEFINES_MODULE = YES;
208240
HEADER_SEARCH_PATHS = (
209241
"$(inherited)",
210242
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include,
@@ -216,7 +248,7 @@
216248
OTHER_LDFLAGS = "-ObjC";
217249
PRODUCT_NAME = RNAppsFlyer;
218250
SKIP_INSTALL = YES;
219-
SWIFT_OBJC_BRIDGING_HEADER = "RNAppsFlyer-Bridging-Header.h";
251+
SWIFT_OBJC_BRIDGING_HEADER = "$(SRCROOT)/RNAppsFlyer-Bridging-Header.h";
220252
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
221253
SWIFT_VERSION = 5.0;
222254
};
@@ -225,7 +257,9 @@
225257
58B511F11A9E6C8500147676 /* Release */ = {
226258
isa = XCBuildConfiguration;
227259
buildSettings = {
260+
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
228261
CLANG_ENABLE_MODULES = YES;
262+
DEFINES_MODULE = YES;
229263
HEADER_SEARCH_PATHS = (
230264
"$(inherited)",
231265
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include,
@@ -237,7 +271,7 @@
237271
OTHER_LDFLAGS = "-ObjC";
238272
PRODUCT_NAME = RNAppsFlyer;
239273
SKIP_INSTALL = YES;
240-
SWIFT_OBJC_BRIDGING_HEADER = "RNAppsFlyer-Bridging-Header.h";
274+
SWIFT_OBJC_BRIDGING_HEADER = "$(SRCROOT)/RNAppsFlyer-Bridging-Header.h";
241275
SWIFT_VERSION = 5.0;
242276
};
243277
name = Release;
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Scheme
3+
LastUpgradeVersion = "1620"
4+
version = "1.7">
5+
<BuildAction
6+
parallelizeBuildables = "YES"
7+
buildImplicitDependencies = "YES"
8+
buildArchitectures = "Automatic">
9+
<BuildActionEntries>
10+
<BuildActionEntry
11+
buildForTesting = "YES"
12+
buildForRunning = "YES"
13+
buildForProfiling = "YES"
14+
buildForArchiving = "YES"
15+
buildForAnalyzing = "YES">
16+
<BuildableReference
17+
BuildableIdentifier = "primary"
18+
BlueprintIdentifier = "58B511DA1A9E6C8500147676"
19+
BuildableName = "libRNAppsFlyer.a"
20+
BlueprintName = "RNAppsFlyer"
21+
ReferencedContainer = "container:RNAppsFlyer.xcodeproj">
22+
</BuildableReference>
23+
</BuildActionEntry>
24+
</BuildActionEntries>
25+
</BuildAction>
26+
<TestAction
27+
buildConfiguration = "Debug"
28+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
29+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
30+
shouldUseLaunchSchemeArgsEnv = "YES"
31+
shouldAutocreateTestPlan = "YES">
32+
</TestAction>
33+
<LaunchAction
34+
buildConfiguration = "Debug"
35+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
36+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
37+
launchStyle = "0"
38+
useCustomWorkingDirectory = "NO"
39+
ignoresPersistentStateOnLaunch = "NO"
40+
debugDocumentVersioning = "YES"
41+
debugServiceExtension = "internal"
42+
allowLocationSimulation = "YES">
43+
</LaunchAction>
44+
<ProfileAction
45+
buildConfiguration = "Release"
46+
shouldUseLaunchSchemeArgsEnv = "YES"
47+
savedToolIdentifier = ""
48+
useCustomWorkingDirectory = "NO"
49+
debugDocumentVersioning = "YES">
50+
<MacroExpansion>
51+
<BuildableReference
52+
BuildableIdentifier = "primary"
53+
BlueprintIdentifier = "58B511DA1A9E6C8500147676"
54+
BuildableName = "libRNAppsFlyer.a"
55+
BlueprintName = "RNAppsFlyer"
56+
ReferencedContainer = "container:RNAppsFlyer.xcodeproj">
57+
</BuildableReference>
58+
</MacroExpansion>
59+
</ProfileAction>
60+
<AnalyzeAction
61+
buildConfiguration = "Debug">
62+
</AnalyzeAction>
63+
<ArchiveAction
64+
buildConfiguration = "Release"
65+
revealArchiveInOrganizer = "YES">
66+
</ArchiveAction>
67+
</Scheme>

react-native-appsflyer.podspec

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ Pod::Spec.new do |s|
1010
s.homepage = pkg["homepage"]
1111
s.author = pkg["author"]
1212
s.source = { :git => pkg["repository"]["url"] }
13-
s.source_files = 'ios/**/*.{h,m}'
13+
s.source_files = 'ios/**/*.{h,m,swift}'
1414
s.platform = :ios, "12.0"
1515
s.static_framework = true
16+
s.swift_version = '5.0'
1617
s.dependency 'React'
1718

1819
# AppsFlyerPurchaseConnector

0 commit comments

Comments
 (0)