DCDevice.current.generateToken Is it safe to cache tokens for less than 1s ?

We have a crash on DCDevice.current.isSupported

We want to try to make a serial queue to generate tokens but the side effect would be the same token would be used on multiple server API requests that are made within a few ms of each other?

Is this safe or will the Apple server immediately reject the same token being reused?

Can you share how long tokens are safe to use for?

Here is the code we want to try

final actor DeviceTokenController: NSObject {
    
    static var shared: DeviceTokenController = .init()
    
    private var tokenGenerationTask: Task<Data?, Never>?
    
    var ephemeralDeviceToken: Data? {
        get async {
            // Re-using the token for short periods of time
            if let existingTask = tokenGenerationTask {
                return await existingTask.value
            }
            
            let task = Task<Data?, Never> {
                guard DCDevice.current.isSupported else { return nil }
                do {
                    return try await DCDevice.current.generateToken()
                } catch {
                    Log("Failed to generate ephemeral device token", error)
                    return nil
                }
            }
            
            tokenGenerationTask = task
            let result = await task.value
            tokenGenerationTask = nil
            
            return result
        }
    }
}
DCDevice.current.generateToken Is it safe to cache tokens for less than 1s ?
 
 
Q