Skip to content

Commit

Permalink
refactor: folder structure
Browse files Browse the repository at this point in the history
  • Loading branch information
duguyihou committed Oct 28, 2023
1 parent d39c661 commit fb9a588
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 23 deletions.
6 changes: 0 additions & 6 deletions example/ios/File.swift

This file was deleted.

27 changes: 12 additions & 15 deletions utils/DeviceUID.swift → ios/DeviceUID.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,25 @@ import Security
class DeviceUID: NSObject {
private var uidString: String?
private let UIDKey = "deviceUID"
private var appleIFV: String? {
return UIDevice.current.identifierForVendor?.uuidString
}

private var randomUUID: String {
return UUID().uuidString
}

func uid() -> String {
var uid: String {
uidString = DeviceUID.getValueForKeychain(by: UIDKey, in: UIDKey)
?? DeviceUID.getValueForUserDefaults(by: UIDKey)
?? DeviceUID.appleIFV()
?? DeviceUID.randomUUID()
?? appleIFV
?? randomUUID
saveIfNeed()
return uidString!
}

func syncUid() -> String {
uidString = DeviceUID.appleIFV() ?? DeviceUID.randomUUID()
var syncUid: String {
uidString = appleIFV ?? randomUUID
save()
return uidString!
}
Expand Down Expand Up @@ -112,13 +119,3 @@ extension DeviceUID {
return defaults.string(forKey: key)
}
}
// MARK: - UID Generation
extension DeviceUID {
private static func appleIFV() -> String? {
return UIDevice.current.identifierForVendor?.uuidString
}

private static func randomUUID() -> String {
return UUID().uuidString
}
}
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions ios/TurboDevice+system.swift
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,14 @@ extension TurboDevice {
@objc
func getUniqueId(_ resolve: @escaping RCTPromiseResolveBlock,
reject: @escaping RCTPromiseRejectBlock) {
let uniqueId = DeviceUID().uid()
let uniqueId = DeviceUID().uid
resolve(uniqueId)
}

@objc
func syncUniqueId(_ resolve: @escaping RCTPromiseResolveBlock,
reject: @escaping RCTPromiseRejectBlock) {
let uniqueId = DeviceUID().syncUid()
let uniqueId = DeviceUID().syncUid
resolve(uniqueId)
}

Expand Down
File renamed without changes.

0 comments on commit fb9a588

Please sign in to comment.