Skip to content

Commit

Permalink
[MOB-10951] Add mobile framework info
Browse files Browse the repository at this point in the history
  • Loading branch information
sumeruchat committed Jan 13, 2025
1 parent 16b8864 commit def5e7c
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 2 deletions.
3 changes: 3 additions & 0 deletions swift-sdk/Core/Constants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,9 @@ enum JsonKey {

static let contentType = "Content-Type"

static let mobileFramework = "mobileFramework"

static let frameworkType = "frameworkType"

// embedded
static let embeddedSessionId = "session"
Expand Down
27 changes: 26 additions & 1 deletion swift-sdk/Internal/InternalIterableAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -188,13 +188,16 @@ final class InternalIterableAPI: NSObject, PushTrackerProtocol, AuthProvider {
}

hexToken = token.hexString()

let mobileFrameworkType = MobileFrameworkType.detect()
let registerTokenInfo = RegisterTokenInfo(hexToken: token.hexString(),
appName: appName,
pushServicePlatform: config.pushPlatform,
apnsType: dependencyContainer.apnsTypeChecker.apnsType,
deviceId: deviceId,
deviceAttributes: deviceAttributes,
sdkVersion: localStorage.sdkVersion)
sdkVersion: localStorage.sdkVersion,
mobileFrameworkInfo: MobileFrameworkInfo(frameworkType: frameworkType, iterableSdkVersion: localStorage.sdkVersion))
requestHandler.register(registerTokenInfo: registerTokenInfo,
notificationStateProvider: notificationStateProvider,
onSuccess: { (_ data: [AnyHashable: Any]?) in
Expand Down Expand Up @@ -775,3 +778,25 @@ final class InternalIterableAPI: NSObject, PushTrackerProtocol, AuthProvider {
requestHandler.stop()
}
}

extension MobileFrameworkType {

static func detect() -> MobileFrameworkType {
let bundle = Bundle.main

// Check for Flutter
if bundle.classNamed("FlutterViewController") != nil ||
bundle.classNamed("GeneratedPluginRegistrant") != nil {
return .flutter
}

// Check for React Native
if bundle.classNamed("RCTBridge") != nil ||
bundle.classNamed("RCTRootView") != nil {
return .reactNative
}

// If no framework detected, assume native
return .native
}
}
10 changes: 9 additions & 1 deletion swift-sdk/Internal/api-client/Request/RequestCreator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,22 @@ struct RequestCreator {
notificationsEnabled: notificationsEnabled,
deviceAttributes: registerTokenInfo.deviceAttributes)

let deviceDictionary: [String: Any] = [
var deviceDictionary: [String: Any] = [
JsonKey.token: registerTokenInfo.hexToken,
JsonKey.platform: RequestCreator.pushServicePlatformToString(registerTokenInfo.pushServicePlatform,
apnsType: registerTokenInfo.apnsType),
JsonKey.applicationName: registerTokenInfo.appName,
JsonKey.dataFields: dataFields,
]

// Add mobile framework info if available
if let frameworkInfo = registerTokenInfo.mobileFrameworkInfo {
deviceDictionary[JsonKey.mobileFramework] = [
JsonKey.frameworkType: frameworkInfo.frameworkType,
JsonKey.iterableSdkVersion: frameworkInfo.iterableSdkVersion
]
}

var body = [AnyHashable: Any]()

body[JsonKey.device] = deviceDictionary
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@

import Foundation

enum MobileFrameworkType: String {
case flutter = "Flutter"
case reactNative = "ReactNative"
case native = "Native"
}

struct MobileFrameworkInfo {
let frameworkType: MobileFrameworkType
let iterableSdkVersion: String?
}

struct RegisterTokenInfo {
let hexToken: String
let appName: String
Expand All @@ -12,6 +23,7 @@ struct RegisterTokenInfo {
let deviceId: String
let deviceAttributes: [String: String]
let sdkVersion: String?
let mobileFrameworkInfo: MobileFrameworkInfo?
}

struct UpdateSubscriptionsInfo {
Expand Down

0 comments on commit def5e7c

Please sign in to comment.