Skip to content

Commit 233f9ea

Browse files
committed
Merge branch 'BNC-Server-Request-Queue-Refactoring-And-Auto-Request-Processing' into feature/remove-bridging-code
2 parents cec44e4 + 0b4ae3c commit 233f9ea

File tree

14 files changed

+1042
-469
lines changed

14 files changed

+1042
-469
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
# Mac
2+
3+
.build
4+
.vscode
5+
26
.DS_Store
37
.LSOverride
48

Branch-TestBed/Branch-TestBed.xcodeproj/project.pbxproj

Lines changed: 269 additions & 381 deletions
Large diffs are not rendered by default.

Branch-TestBed/Branch-TestBed.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved

Lines changed: 0 additions & 23 deletions
This file was deleted.

BranchSDK.xcodeproj/project.pbxproj

Lines changed: 35 additions & 12 deletions
Large diffs are not rendered by default.

Package.swift

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,32 @@
33
import PackageDescription
44

55
let package = Package(
6-
name: "ios-branch-deep-linking-attribution",
6+
name: "BranchSDK",
77
platforms: [
88
.iOS(.v12),
99
.tvOS(.v12),
1010
],
1111
products: [
12+
// Main product that clients will import
1213
.library(
1314
name: "BranchSDK",
14-
targets: ["BranchSDK", "BranchSwiftSDK", "BranchObjCSDK"]),
15+
targets: ["BranchSDK", "BranchSwiftSDK"]),
1516
],
1617
dependencies: [
18+
// Add external dependencies here if needed
19+
// .package(url: "https://github.com/google/GoogleUtilities.git", from: "7.0.0"),
20+
// .package(url: "https://github.com/firebase/nanopb.git", from: "2.30909.0"),
1721
],
1822
targets: [
19-
.target(
20-
name: "BranchObjCSDK",
21-
path: "Sources/BranchSDK_ObjC",
22-
publicHeadersPath: "Public"
23-
),
24-
.target(
25-
name: "BranchSwiftSDK",
26-
dependencies: ["BranchObjCSDK"], // Swift code depends on Objective-C Constants
27-
path: "Sources/BranchSDK_Swift"
28-
29-
),
23+
// Main Objective-C SDK target
3024
.target(
3125
name: "BranchSDK",
32-
dependencies: ["BranchSwiftSDK"],
26+
dependencies: [],
3327
path: "Sources/BranchSDK",
3428
publicHeadersPath: "Public",
3529
cSettings: [
36-
.headerSearchPath("Private")
30+
.headerSearchPath("Private"),
31+
.define("SWIFT_PACKAGE")
3732
],
3833
linkerSettings: [
3934
.linkedFramework("CoreServices"),
@@ -42,6 +37,15 @@ let package = Package(
4237
.linkedFramework("CoreSpotlight", .when(platforms: [.iOS])),
4338
.linkedFramework("AdServices", .when(platforms: [.iOS]))
4439
]
40+
),
41+
// Swift Concurrency layer (depends on main SDK)
42+
.target(
43+
name: "BranchSwiftSDK",
44+
dependencies: ["BranchSDK"],
45+
path: "Sources/BranchSwiftSDK",
46+
swiftSettings: [
47+
.define("SWIFT_PACKAGE")
48+
]
4549
)
4650
]
4751
)

Sources/BranchSDK/BNCRequestFactory.m

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,20 @@
3333
#import "BNCAppGroupsData.h"
3434
#import "BNCSKAdNetwork.h"
3535

36-
#if SWIFT_PACKAGE
37-
@import BranchSwiftSDK;
38-
#else
36+
// Swift integration - BranchSwiftSDK module is loaded dynamically at runtime
37+
// No compile-time import needed to avoid circular dependencies in SPM
38+
#if !SWIFT_PACKAGE
39+
// Swift bridging header - auto-generated by Xcode when Swift files are present
40+
#if __has_include("BranchSDK/BranchSDK-Swift.h")
3941
#import "BranchSDK/BranchSDK-Swift.h"
4042
#endif
43+
#endif
4144

4245

4346
#import "BNCReferringURLUtility.h"
4447
#import "BNCPasteboard.h"
4548
#import "BNCODMInfoCollector.h"
49+
#import "Private/BranchConfigurationController.h"
4650

4751
@interface BNCRequestFactory()
4852

@@ -438,7 +442,31 @@ - (void)addLocalURLToOpenJSON:(NSMutableDictionary *)json {
438442

439443
// If the client uses a UIPasteControl, force a new open to fetch the payload
440444
- (void)addOperationalMetrics:(NSMutableDictionary *)json {
441-
[self safeSetValue:[[ConfigurationController shared] getConfiguration] forKey:BRANCH_REQUEST_KEY_OPERATIONAL_METRICS onDict:json];
445+
// Try Swift ConfigurationController first, fallback to Objective-C if not available
446+
id configuration = nil;
447+
448+
// Check if Swift ConfigurationController is available
449+
Class swiftConfigClass = NSClassFromString(@"ConfigurationController");
450+
if (swiftConfigClass) {
451+
SEL sharedSelector = NSSelectorFromString(@"shared");
452+
if ([swiftConfigClass respondsToSelector:sharedSelector]) {
453+
#pragma clang diagnostic push
454+
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
455+
id sharedInstance = [swiftConfigClass performSelector:sharedSelector];
456+
SEL getConfigSelector = NSSelectorFromString(@"getConfiguration");
457+
if ([sharedInstance respondsToSelector:getConfigSelector]) {
458+
configuration = [sharedInstance performSelector:getConfigSelector];
459+
}
460+
#pragma clang diagnostic pop
461+
}
462+
}
463+
464+
// Fallback to Objective-C implementation
465+
if (!configuration) {
466+
configuration = [[BranchConfigurationController sharedInstance] getConfiguration];
467+
}
468+
469+
[self safeSetValue:configuration forKey:BRANCH_REQUEST_KEY_OPERATIONAL_METRICS onDict:json];
442470
}
443471

444472

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//
2+
// Branch-Bridging-Header.h
3+
// Branch SDK
4+
//
5+
// Bridging header to expose Objective-C types to Swift within the Branch target
6+
//
7+
8+
#import "Public/Branch.h"
9+
#import "Public/BNCServerRequest.h"
10+
#import "Public/BNCServerInterface.h"
11+
#import "Public/BNCServerResponse.h"
12+
#import "Public/BNCPreferenceHelper.h"
13+
#import "Public/BranchLogger.h"
14+
#import "Private/NSError+Branch.h"

Sources/BranchSDK/Branch.m

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,17 @@
4545
#import "BNCServerAPI.h"
4646
#import "BranchPluginSupport.h"
4747
#import "BranchLogger.h"
48+
#import "Private/BranchConfigurationController.h"
4849

4950

50-
#if SWIFT_PACKAGE
51-
@import BranchSwiftSDK;
52-
#else
53-
#import "BranchSDK/BranchSDK-Swift.h"
51+
52+
// Swift integration - BranchSwiftSDK module is loaded dynamically at runtime
53+
// No compile-time import needed to avoid circular dependencies in SPM
54+
#if !SWIFT_PACKAGE
55+
// Swift bridging header - auto-generated by Xcode when Swift files are present
56+
#if __has_include("BranchSDK-Swift.h")
57+
#import "BranchSDK-Swift.h"
58+
#endif
5459
#endif
5560

5661
#if !TARGET_OS_TV
@@ -194,7 +199,7 @@ + (Branch *)getInstance {
194199

195200
+ (Branch *)getInstance:(NSString *)branchKey {
196201
self.branchKey = branchKey;
197-
[ConfigurationController shared].branchKeySource = BRANCH_KEY_SOURCE_GET_INSTANCE_API;
202+
[BranchConfigurationController sharedInstance].branchKeySource = BRANCH_KEY_SOURCE_GET_INSTANCE_API;
198203
return [Branch getInstanceInternal:self.branchKey];
199204
}
200205

@@ -254,8 +259,8 @@ - (id)initWithInterface:(BNCServerInterface *)interface
254259

255260
BranchJsonConfig *config = BranchJsonConfig.instance;
256261
self.deferInitForPluginRuntime = config.deferInitForPluginRuntime;
257-
[ConfigurationController shared].deferInitForPluginRuntime = self.deferInitForPluginRuntime;
258-
262+
[BranchConfigurationController sharedInstance].deferInitForPluginRuntime = self.deferInitForPluginRuntime;
263+
259264
if (config.apiUrl) {
260265
[Branch setAPIUrl:config.apiUrl];
261266
}
@@ -282,6 +287,7 @@ - (id)initWithInterface:(BNCServerInterface *)interface
282287
}
283288
}
284289

290+
[self.requestQueue configureWithServerInterface:_serverInterface branchKey:key preferenceHelper:preferenceHelper];
285291
return self;
286292
}
287293

@@ -416,7 +422,7 @@ + (void)setBranchKey:(NSString*)branchKey error:(NSError **)error {
416422
[[BranchLogger shared] logError:[NSString stringWithFormat:@"Invalid Branch key format. Did you add your Branch key to your Info.plist? Passed key is '%@'.", branchKey] error:*error];
417423
return;
418424
}
419-
[ConfigurationController shared].branchKeySource = BRANCH_KEY_SOURCE_SET_BRANCH_KEY_API;
425+
[BranchConfigurationController sharedInstance].branchKeySource = BRANCH_KEY_SOURCE_SET_BRANCH_KEY_API;
420426
bnc_branchKey = branchKey;
421427
}
422428
}
@@ -452,7 +458,7 @@ + (NSString *)branchKey {
452458
if (!bnc_branchKey) {
453459
[[BranchLogger shared] logError:@"Your Branch key is not set in your Info.plist file. See https://dev.branch.io/getting-started/sdk-integration-guide/guide/ios/#configure-xcode-project for configuration instructions." error:nil];
454460
}
455-
[ConfigurationController shared].branchKeySource = branchKeySource;
461+
[BranchConfigurationController sharedInstance].branchKeySource = branchKeySource;
456462
return bnc_branchKey;
457463
}
458464
}
@@ -1014,7 +1020,7 @@ - (void)startLoadingOfODMInfo {
10141020

10151021
- (void)checkPasteboardOnInstall {
10161022
[BNCPasteboard sharedInstance].checkOnInstall = YES;
1017-
[ConfigurationController shared].checkPasteboardOnInstall = YES;
1023+
[BranchConfigurationController sharedInstance].checkPasteboardOnInstall = YES;
10181024
}
10191025

10201026
- (BOOL)willShowPasteboardToast {
@@ -1150,7 +1156,6 @@ - (void)sendServerRequest:(BNCServerRequest*)request {
11501156
[self initSafetyCheck];
11511157
dispatch_async(self.isolationQueue, ^(){
11521158
[self.requestQueue enqueue:request];
1153-
[self processNextQueueItem];
11541159
});
11551160
}
11561161

@@ -1350,7 +1355,6 @@ - (void)getSpotlightUrlWithParams:(NSDictionary *)params callback:(callbackWithP
13501355
dispatch_async(self.isolationQueue, ^(){
13511356
BranchSpotlightUrlRequest *req = [[BranchSpotlightUrlRequest alloc] initWithParams:params callback:callback];
13521357
[self.requestQueue enqueue:req];
1353-
[self processNextQueueItem];
13541358
});
13551359
}
13561360

@@ -1646,7 +1650,6 @@ - (void)generateShortUrl:(NSArray *)tags
16461650
linkCache:self.linkCache
16471651
callback:callback];
16481652
[self.requestQueue enqueue:req];
1649-
[self processNextQueueItem];
16501653
});
16511654
}
16521655

@@ -1875,14 +1878,6 @@ - (void)setNetworkCount:(NSInteger)networkCount {
18751878
}
18761879
}
18771880

1878-
- (void)insertRequestAtFront:(BNCServerRequest *)req {
1879-
if (self.networkCount == 0) {
1880-
[self.requestQueue insert:req at:0];
1881-
} else {
1882-
[self.requestQueue insert:req at:1];
1883-
}
1884-
}
1885-
18861881
static inline void BNCPerformBlockOnMainThreadSync(dispatch_block_t block) {
18871882
if (block) {
18881883
if ([NSThread isMainThread]) {
@@ -1902,7 +1897,7 @@ - (void) processRequest:(BNCServerRequest*)req
19021897
error:(NSError*)error {
19031898

19041899
// If the request was successful, or was a bad user request, continue processing.
1905-
if (!error ||
1900+
/* if (!error ||
19061901
error.code == BNCTrackingDisabledError ||
19071902
error.code == BNCBadRequestError ||
19081903
error.code == BNCDuplicateResourceError) {
@@ -1956,7 +1951,7 @@ - (void) processRequest:(BNCServerRequest*)req
19561951
}
19571952
});
19581953
}
1959-
}
1954+
}*/
19601955
}
19611956

19621957
- (BOOL)isReplayableRequest:(BNCServerRequest *)request {
@@ -1980,6 +1975,7 @@ - (BOOL)isReplayableRequest:(BNCServerRequest *)request {
19801975
}
19811976

19821977
- (void)processNextQueueItem {
1978+
/*
19831979
dispatch_semaphore_wait(self.processing_sema, DISPATCH_TIME_FOREVER);
19841980
19851981
[[BranchLogger shared] logVerbose:[NSString stringWithFormat:@"Processing next queue item. Network Count: %ld. Queue depth: %ld", (long)self.networkCount, (long)self.requestQueue.queueDepth] error:nil];
@@ -2027,7 +2023,7 @@ - (void)processNextQueueItem {
20272023
}
20282024
else {
20292025
dispatch_semaphore_signal(self.processing_sema);
2030-
}
2026+
}*/
20312027
}
20322028

20332029
- (void)clearNetworkQueue {
@@ -2166,7 +2162,7 @@ - (void)initializeSessionAndCallCallback:(BOOL)callCallback sceneIdentifier:(NSS
21662162
req.callback = initSessionCallback;
21672163
req.urlString = urlString;
21682164

2169-
[self.requestQueue insert:req at:0];
2165+
[self.requestQueue enqueue:req withPriority:NSOperationQueuePriorityHigh];
21702166

21712167
NSString *message = [NSString stringWithFormat:@"Request %@ callback %@ link %@", req, req.callback, req.urlString];
21722168
[[BranchLogger shared] logDebug:message error:nil];
@@ -2180,7 +2176,7 @@ - (void)initializeSessionAndCallCallback:(BOOL)callCallback sceneIdentifier:(NSS
21802176
req.urlString = urlString;
21812177

21822178
// put it behind the one that's already on queue
2183-
[self.requestQueue insert:req at:1];
2179+
[self.requestQueue enqueue:req withPriority:NSOperationQueuePriorityHigh];
21842180

21852181
[[BranchLogger shared] logDebug:@"Link resolution request" error:nil];
21862182
NSString *message = [NSString stringWithFormat:@"Request %@ callback %@ link %@", req, req.callback, req.urlString];
@@ -2190,8 +2186,6 @@ - (void)initializeSessionAndCallCallback:(BOOL)callCallback sceneIdentifier:(NSS
21902186

21912187
self.initializationStatus = BNCInitStatusInitializing;
21922188
[[BranchLogger shared] logVerbose:[NSString stringWithFormat:@"initializationStatus %ld", self.initializationStatus] error:nil];
2193-
2194-
[self processNextQueueItem];
21952189
});
21962190
}
21972191
}

0 commit comments

Comments
 (0)