Skip to content

Commit

Permalink
Merge pull request #81 from plaidev/ryosuke-persistent-props
Browse files Browse the repository at this point in the history
feat(ios): Persist custom user properties in UserDefaults and bump up to 0.6.1
  • Loading branch information
RyosukeCla authored Feb 20, 2025
2 parents 21ef105 + ae576cc commit a5f695a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Nativebrik.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'Nativebrik'
s.version = '0.6.0'
s.version = '0.6.1'
s.summary = 'Nativebrik SDK'
s.description = <<-DESC
Nativebrik SDK for iOS.
Expand Down
10 changes: 10 additions & 0 deletions ios/Nativebrik/Nativebrik/data/user.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ func nativebrikUserPropType(key: BuiltinUserProperty) -> UserPropertyType {
}
}

private let USER_CUSTOM_PROPERTY_KEY_PREFIX = "NATIVEBRIK_CUSTOM_"
private let USER_SEED_KEY: String = "NATIVEBRIK_USER_SEED"
private let USER_SEED_MAX: Int = 100000000

Expand Down Expand Up @@ -114,6 +115,13 @@ public class NativebrikUser {

let cfBundleVersion = Bundle.main.infoDictionary?["CFBundleVersion"] as? String ?? ""
self.properties[BuiltinUserProperty.cfBundleVersion.rawValue] = cfBundleVersion

self.userDB.dictionaryRepresentation().forEach { key, value in
if key.starts(with: USER_CUSTOM_PROPERTY_KEY_PREFIX) {
let propKey = key.replacingOccurrences(of: USER_CUSTOM_PROPERTY_KEY_PREFIX, with: "")
self.customProperties[propKey] = String(describing: value)
}
}

self.comeBack()
}
Expand All @@ -136,9 +144,11 @@ public class NativebrikUser {
if key == BuiltinUserProperty.userId.rawValue {
// overwrite userId
self.properties[BuiltinUserProperty.userId.rawValue] = value
self.userDB.set(value, forKey: NativebrikUserDefaultsKeys.USER_ID.rawValue)
continue
}
self.customProperties[key] = value
self.userDB.set(value, forKey: USER_CUSTOM_PROPERTY_KEY_PREFIX + key)
}
}

Expand Down
2 changes: 1 addition & 1 deletion ios/Nativebrik/Nativebrik/sdk.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import Combine
// for development
public var nativebrikTrackUrl = "https://track.nativebrik.com/track/v1"
public var nativebrikCdnUrl = "https://cdn.nativebrik.com"
public let nativebrikSdkVersion = "0.6.0"
public let nativebrikSdkVersion = "0.6.1"

public let isNativebrikAvailable: Bool = {
if #available(iOS 15.0, *) {
Expand Down

0 comments on commit a5f695a

Please sign in to comment.