DeviceActivityReport - filtering applications for makeConfiguration

I am trying to filter my DeviceActivityReport to only show activity for the specific app tokens I pass in. Right now, it shows activity for all apps. Is there something else I need to do in makeConfiguration so that it only filters the application tokens that I'm filtering by?

filter = DeviceActivityFilter(segment: .hourly(during: dateInterval), applications: task.selection.applicationTokens)

struct TotalActivityReport: DeviceActivityReportScene {
    // Define which context your scene will represent.
    let context: DeviceActivityReport.Context = .totalActivity
    
    // Define the custom configuration and the resulting view for this report.
    let content: (String) -> TotalActivityView
    
    func makeConfiguration(representing data: DeviceActivityResults<DeviceActivityData>) async -> String {
        // Reformat the data into a configuration that can be used to create
        // the report's view.
        let formatter = DateComponentsFormatter()
        formatter.allowedUnits = [.minute, .second]
        formatter.unitsStyle = .abbreviated
        formatter.zeroFormattingBehavior = .dropAll
        
        let totalActivityDuration = await data.flatMap { $0.activitySegments }.reduce(0, {
            $0 + $1.totalActivityDuration
        })
        return formatter.string(from: totalActivityDuration) ?? "No activity data"
    }
}

Hi there! Try this instead:

let discouragedDuration =  await data.flatMap { $0.activitySegments }.flatMap { $0.categories }.flatMap { $0.applications }.reduce(0, {$0 + $1.totalActivityDuration})

Not sure why this approach actually takes the filter into account, but my guess is that the filter doesn't apply as high up as the activitySegments level. Hope this works for you; it did for me.

DeviceActivityReport - filtering applications for makeConfiguration
 
 
Q