I'm trying to use DeviceActivity but without success, I need an example code
I need to show app usage time in my app
Can't you measure it directly ?
- start when app comes to foreground
- stop when it goes to background
- save to userDefaults just befor
There is some sample code for how to use a DeviceActivityReport
within your app's view hierarchy here: https://developer.apple.com/documentation/deviceactivity/deviceactivityreport
As for how to implement an extension that renders the report's UI based on usage data, if you select File > New > Target... > iOS > Device Activity Report Extension in Xcode, it will create a simple extension that you can then modify to fit your app's use case.
If this is not sufficient, please file a request for supplemental sample code using Feedback Assistant.