Skip to content

Commit

Permalink
Adding swift file to ios pod target
Browse files Browse the repository at this point in the history
  • Loading branch information
al-af committed Jan 20, 2025
1 parent a7597a8 commit 02ecf3e
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 15 deletions.
2 changes: 1 addition & 1 deletion ios/AppsFlyerLib.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#import <AppsFlyerLib/AppsFlyerDeepLinkResult.h>
#import <AppsFlyerLib/AppsFlyerDeepLink.h>
#import <AppsFlyerLib/AppsFlyerConsent.h>
#import <AppsFlyerLib/AppsFlyerAdRevenueData.h>
#import <AppsFlyerLib/AFAdRevenueData.h>

NS_ASSUME_NONNULL_BEGIN

Expand Down
2 changes: 1 addition & 1 deletion ios/PCAppsFlyer.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#import <objc/message.h>
#if __has_include(<PurchaseConnector/PurchaseConnector.h>)
#import <PurchaseConnector/PurchaseConnector.h>

@class TransactionFetcher;
@interface PCAppsFlyer: RCTEventEmitter <RCTBridgeModule, AppsFlyerPurchaseRevenueDelegate, AppsFlyerPurchaseRevenueDataSource>
// This is the PCAppsFlyer if the AppsFlyerPurchaseConnector is set to true in the podfile
@end
Expand Down
1 change: 1 addition & 0 deletions ios/PCAppsFlyer.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#if __has_include(<PurchaseConnector/PurchaseConnector.h>)
#import <PurchaseConnector/PurchaseConnector.h>
#import "RNAppsFlyer-Swift.h"

@implementation PCAppsFlyer
@synthesize bridge = _bridge;
Expand Down
1 change: 0 additions & 1 deletion ios/RNAppsFlyer-Bridging-Header.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#ifndef _RNAppsFlyer_Bridging_Header_h
#define _RNAppsFlyer_Bridging_Header_h

#import <Foundation/Foundation.h>
#import <PurchaseConnector/PurchaseConnector.h>
#import <React/RCTBridgeModule.h>
#import <React/RCTViewManager.h>
Expand Down
2 changes: 2 additions & 0 deletions ios/RNAppsFlyer.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
33 changes: 22 additions & 11 deletions ios/TransactionFetcher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()])
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion react-native-appsflyer.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit 02ecf3e

Please sign in to comment.