-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MOB-10951] Add mobile framework info to register token request (#884)
- Loading branch information
1 parent
b57c7f5
commit ab02a03
Showing
13 changed files
with
160 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
swift-sdk/Internal/IterableAPIMobileFrameworkDetector.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import Foundation | ||
|
||
final class IterableAPIMobileFrameworkDetector { | ||
private struct FrameworkClasses { | ||
static let flutter = [ | ||
"FlutterViewController", | ||
"GeneratedPluginRegistrant", | ||
"FlutterEngine", | ||
"FlutterPluginRegistry" | ||
] | ||
|
||
static let reactNative = [ | ||
"RCTBridge", | ||
"RCTRootView", | ||
"RCTBundleURLProvider", | ||
"RCTEventEmitter" | ||
] | ||
} | ||
|
||
private struct BundleIdentifiers { | ||
static let executableKey = "CFBundleExecutable" | ||
static let flutterTargetKey = "FlutterDeploymentTarget" | ||
static let reactNativeProviderKey = "RNBundleURLProvider" | ||
static let flutterExecutableName = "Runner" | ||
} | ||
|
||
private static var cachedFrameworkType: IterableAPIMobileFrameworkType = { | ||
detectFramework() | ||
}() | ||
|
||
static func detectFramework() -> IterableAPIMobileFrameworkType { | ||
let bundle = Bundle.main | ||
|
||
// Helper function to check for framework classes | ||
func hasFrameworkClasses(_ classNames: [String]) -> Bool { | ||
guard !classNames.isEmpty else { return false } | ||
return classNames.contains { className in | ||
guard IterableUtil.isNotNullOrEmpty(string: className) else { return false } | ||
return bundle.classNamed(className) != nil | ||
} | ||
} | ||
|
||
// Safely check frameworks | ||
let hasFlutter = hasFrameworkClasses(FrameworkClasses.flutter) | ||
let hasReactNative = hasFrameworkClasses(FrameworkClasses.reactNative) | ||
|
||
switch (hasFlutter, hasReactNative) { | ||
case (true, true): | ||
ITBError("Both Flutter and React Native frameworks detected. This is unexpected.") | ||
if let mainBundle = Bundle.main.infoDictionary, | ||
let executableName = mainBundle[BundleIdentifiers.executableKey] as? String, | ||
!executableName.isEmpty, | ||
executableName == BundleIdentifiers.flutterExecutableName { | ||
return .flutter | ||
} else { | ||
return .reactNative | ||
} | ||
|
||
case (true, false): | ||
return .flutter | ||
|
||
case (false, true): | ||
return .reactNative | ||
|
||
case (false, false): | ||
if let mainBundle = Bundle.main.infoDictionary { | ||
if let _ = mainBundle[BundleIdentifiers.flutterTargetKey] as? String { | ||
return .flutter | ||
} | ||
if let _ = mainBundle[BundleIdentifiers.reactNativeProviderKey] as? String { | ||
return .reactNative | ||
} | ||
} | ||
return .native | ||
} | ||
} | ||
|
||
public static func frameworkType() -> IterableAPIMobileFrameworkType { | ||
return cachedFrameworkType | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -210,6 +210,7 @@ struct TestUtils { | |
queryItem.name == name | ||
}! | ||
} | ||
|
||
} | ||
|
||
struct KeyPath { | ||
|