如何在iOS设备上获得屏幕时间?

发布于 2025-01-22 05:23:54 字数 132 浏览 2 评论 0原文

我们目前正在构建一个iOS应用程序,该应用程序在其iOS设备上跟踪用户的屏幕时间。我了解Apple非常限制,并且当前的屏幕时间API是通过父母设置访问的。有什么办法可以在用户的​​屏幕时间获得基本信息?即使是像一天中的总屏幕时间这样的信息也可以做到。

We are currently working on building an iOS app that tracks the screen-time of the user on their iOS device. I understand that apple is very restrictive and the current Screen-Time API is any accessible through Parental Settings. Is there any way we can get basic info on the screen time of the user? Even info like total screen time of the day will do.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

中二柚 2025-01-29 05:23:54

我相信,苹果的屏幕时间API并未提供报告作为其功能之一。
在另一个问题中答案:链接

另请参见有关此信息的WWDC视频:链接

I believe that Screen Time API from Apple does not offer a report as one of their capabilities.
Answer in other question: Link.

Also see WWDC video about this: Link

半透明的墙 2025-01-29 05:23:54

是的,可以使用屏幕时间API获取屏幕时间数据,该屏幕时间数据包括三个框架:

  1. 使用这三个框架,父母控制
  2. 设备活动
  3. 托管设置

,您可以检索屏幕时间信息。

要将其集成到Xcode iOS项目中,请转到文件 - >新 - >目标 - >设备活动报告扩展。这将在您的项目中添加设备活动报告扩展目标,自动创建三个文件:

  1. ScreentimerePort.swift
  2. totalActivityReport.swift
  3. totalActivityView.Swift

以显示用户的整体屏幕时间,将以下代码添加到任何视图文件中。这将促使用户许可并在批准后显示其屏幕时间。

struct ExampleView: View {
    @State private var context: DeviceActivityReport.Context = .init(rawValue: "Total Activity")
    @State private var filter = DeviceActivityFilter(
    segment: .daily(
        during: Calendar.current.dateInterval(
           of: .day, for: .now
        )!
    ),
    users: .all,
    devices: .init([.iPhone, .iPad])
)
var body: some View {
    DeviceActivityReport(context, filter: filter)
   }
}

此代码将调用TotalActivityView.swift文件。

欢呼!屏幕时间将显示。

Yes, it is possible to get screen time data using the Screen Time API, which comprises three frameworks:

  1. Parental Controls
  2. Device Activity
  3. Managed Settings

With these three frameworks, you can retrieve screen time information.

To integrate this in an Xcode iOS project, go to File -> New -> Target -> Device Activity Report Extension. This will add a Device Activity Report Extension target to your project, automatically creating three files:

  1. ScreenTimeReport.swift
  2. TotalActivityReport.swift
  3. TotalActivityView.swift

To display the overall screen time of the user, add the following code to any view file. This will prompt the user for permission and, upon approval, display their screen time.

struct ExampleView: View {
    @State private var context: DeviceActivityReport.Context = .init(rawValue: "Total Activity")
    @State private var filter = DeviceActivityFilter(
    segment: .daily(
        during: Calendar.current.dateInterval(
           of: .day, for: .now
        )!
    ),
    users: .all,
    devices: .init([.iPhone, .iPad])
)
var body: some View {
    DeviceActivityReport(context, filter: filter)
   }
}

This code will call the TotalActivityView.swift file.

Hurray! the screen time will be displayed.

挽袖吟 2025-01-29 05:23:54

没有对冲,这是不可能的。我们可以证明它仅在扩展名中

共享屏幕时间从设备活动扩展到您的父应用程序。我尝试过多种方法来实现UserDefault,AppGroup,Notification Center,但我无法将其输入我的应用程序。反对违规。是的,我检查了其他显示其应用中屏幕时间的应用程序,但是
我相信这是用户从应用程序中计算出的屏幕时间。

No hedgy it's not possible. We can show it's in only extension

Share screen time from Device activity extension to your parent app is not possible. I have tried multiple ways to achieve like Userdefault, Appgroup, Notification Center but i am not able to get that into my App. It's against violation. Yes i check other apps which shows screen time in their app but
i believe it's user estimate screen time which they calculate from app.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文