3

I am using iOS 16 beta 3 and try to fetch all of the applications daily screen duration times. I am using the code bellow it fetches duration and bundleIdentifier but localizedDisplayName always returns nil. Does anyone facing with the same issue? Is it a beta problem? Or am I doing something wrong?

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: (ActivityReport) -> TotalActivityView

func makeConfiguration(representing data: DeviceActivityResults<DeviceActivityData>) async -> ActivityReport {
    // Reformat the data into a configuration that can be used to create
    // the report's view.
    var list: [AppDeviceActivity] = []
    let totalActivityDuration = await data.flatMap { $0.activitySegments }.reduce(0, {
        $0 + $1.totalActivityDuration
    })
    for await d in data {
        for await a in d.activitySegments{
            for await c in a.categories {
                for await ap in c.applications {
                    let appName = (ap.application.localizedDisplayName ?? "nil")
                    let bundle = (ap.application.bundleIdentifier ?? "nil")
                    let duration = (ap.totalActivityDuration)
                    let app = AppDeviceActivity(id: bundle, displayName: appName, duration: duration)
                    list.append(app)
                }
            }
        }
    }
    
    return ActivityReport(totalDuration: totalActivityDuration, apps: list)
}}

0 Answers0