Bellow I created Manager to be easier for me to handle app limits, but for some reason It never reached callbacks function, I have permission for screen time, I added the capabilities for it also, I'm sure, I send correctly the appTokens, categoriesTokens ... and the time limit and it also reach ✅ Monitoring started for..., I don't know what to do anymore:
import SwiftUI
import DeviceActivity
import FamilyControls
import ManagedSettings
@MainActor
class AppUsageManager: DeviceActivityMonitor, ObservableObject {
static let shared = AppUsageManager()
private let deviceActivityCenter = DeviceActivityCenter()
private var monitoringSelections: [DeviceActivityName: (selection: FamilyActivitySelection, timeLimit: DateComponents)] = [:]
private var resetTimer: Timer?
private override init() {
super.init()
print("🟢 AppUsageManager initialized.")
}
// MARK: - Public Methods
/// Configures monitoring for a selection with a specific event name and time limit.
func configureMonitoring(
for selection: FamilyActivitySelection,
timeLimitInMinutes: Int,
activityName: String,
eventName: String
) {
let activityName = DeviceActivityName(activityName)
let eventName = DeviceActivityEvent.Name(eventName)
monitoringSelections[activityName] = (selection, DateComponents(minute: timeLimitInMinutes))
setupMonitoring(for: activityName, with: eventName)
}
/// Stops monitoring for a specific event.
func stopMonitoring(for activityName: String) {
let activityName = DeviceActivityName(activityName)
Task {
print("🛑 Stopping monitoring for \(activityName.rawValue).")
deviceActivityCenter.stopMonitoring([activityName])
monitoringSelections.removeValue(forKey: activityName)
}
}
/// Stops all monitoring.
func stopAllMonitoring() {
print("🛑 Stopping monitoring")
deviceActivityCenter.stopMonitoring()
}
// MARK: - Private Methods
/// Sets up monitoring for a specific event.
private func setupMonitoring(
for activityName: DeviceActivityName,
with eventName: DeviceActivityEvent.Name
) {
stopAllMonitoring()
guard let (selection, timeLimit) = monitoringSelections[activityName] else {
print("⚠️ No selection configured for \(activityName.rawValue).")
return
}
print("🛠 Setting up monitoring for \(activityName.rawValue).")
print("📋 Monitoring Details:")
print("- Time Limit: \(timeLimit.minute ?? 0) minutes.")
let warningThreshold = DateComponents(minute: 3)
let timeZone = TimeZone.current
let schedule = DeviceActivitySchedule(
intervalStart: DateComponents(timeZone: timeZone, hour: 0, minute: 0, second: 0),
intervalEnd: DateComponents(timeZone: timeZone, hour: 23, minute: 59, second: 59),
repeats: true,
warningTime: warningThreshold
)
let events: [DeviceActivityEvent.Name: DeviceActivityEvent] = [
eventName: DeviceActivityEvent(
applications: selection.applicationTokens,
categories: selection.categoryTokens,
webDomains: selection.webDomainTokens,
threshold: timeLimit
)
]
do {
try deviceActivityCenter.startMonitoring(
activityName,
during: schedule,
events: events
)
print("✅ Monitoring started for \(activityName.rawValue) with time limit \(timeLimit.minute ?? 0) minutes.")
} catch {
print("❌ Failed to start monitoring \(activityName.rawValue): \(error.localizedDescription)")
}
}
// MARK: - DeviceActivityMonitor Overrides
override func intervalDidStart(for activity: DeviceActivityName) {
print("🟢 Interval for \(activity.rawValue) started.")
}
override func intervalWillStartWarning(for activity: DeviceActivityName) {
print("⚠️ Warning: \(activity.rawValue) is about to start.")
}
/// Handles warnings for approaching the time limit.
override func eventWillReachThresholdWarning(
_ event: DeviceActivityEvent.Name,
activity: DeviceActivityName
) {
super.eventWillReachThresholdWarning(event, activity: activity)
print("⚠️ Warning: \(activity.rawValue) is about to reach its time limit.")
print("⚠️ Event: \(event.rawValue)")
}
/// Handles when the time limit is reached.
override func eventDidReachThreshold(
_ event: DeviceActivityEvent.Name,
activity: DeviceActivityName
) {
super.eventDidReachThreshold(event, activity: activity)
print("🟢 Limit reached.")
Task { @MainActor in
print("🕒 \(activity.rawValue) has reached its time limit.")
print("🕒 Event: \(event.rawValue)")
guard let (selection, _) = monitoringSelections[activity] else {
print("⚠️ No selection configured for \(activity.rawValue).")
return
}
blockApps(for: selection)
}
}
// MARK: - Blocking Logic
/// Blocks the selected apps/categories.
private func blockApps(for selection: FamilyActivitySelection) {
print("🔒 Blocking apps/categories for selection.")
print("- Applications: \(selection.applicationTokens)")
print("- Categories: \(selection.categoryTokens)")
let store = ManagedSettingsStore()
store.shield.applications = selection.applicationTokens
store.shield.applicationCategories = .specific(selection.categoryTokens)
print("🔒 Apps/categories blocked successfully.")
}
}
Post
Replies
Boosts
Views
Activity
Hi, I've created an carousel using an Tabview component and it is divided in pages, each page has 7 items. Now we wan't to load the carousel page by page, but whenever I updated the list which Tabview uses to render, it flickers because it rerenders previous elements.
I've tried to use a scroll view for this but this app is for Vision Pro and I added some 3D transformations (position/rotation) to the cards from the tabview and when I added this in the scrollview they becom unclickable.
Do you have any sugestions what can I do?
Bellow is a sample of the code, I put [items] just to suggest there is a list.
VStack (spacing: 45) {
TabView(selection: $navigationModel.carouselSelectedPage) {
let orderedArtist = [items]
let numberOfPages = Int((Double(orderedArtist.count) / Double(cardsPerPage)).rounded(.up))
if(numberOfPages != 1){
Spacer().tag(-1)
}
ForEach(0..<numberOfPages, id: \.self) { page in
LazyHStack(alignment: .top, spacing: 16){
ForEach(0..<cardsPerPage, id: \.self) { index in
if(page * cardsPerPage + index < orderedArtist.count){
let item = orderedArtist[page * cardsPerPage + index]
GeometryReader{proxy in
Hi, I heve a problem with an visionOS app and I couldn't find a solution. I have 3D carousel with cards and when I use the drag gesture and I drag to the left I want the carousel to rotate clockwise and when I drag to the right I want the carousel to rotate counter clockwise. My problem is when I rotate my body more than 90 degrees to the left or to the right the drag gesture changes it's value and the carousel rotates in the opposite direction? Do you know how can I maintain the right sense taking into account that the user can rotate his body?
I've tried to take the user orientation with device tracking and check if rotation on Y axis is greater than 90 degrees in both direction but It is a very small area bettween 70-110 degrees when it still rotates in the opposite direction. I think that's because the device traker doesn't update at the same rate as drag gesture or it doesn't have the same acurracy.
Hi, since I updated my device to visionOS 2.0 or higher I have some problems with my app. Sometimes when I go with my eyes over buttons or the tabview which is a SwiftUI component that many apps use, the hover effect doesn't trigger anymore, I can tap on the icon from the tabview but doesn't extend when I hover it to se the description of the button. It is weird because it doesn't happen all the time. But in VisionOS 1.0 doesn't happen at all.
My second issue is that I have an navbar as an attachment and this attachment has a draggable modifier that we created. The buttons are not tappable until I drag the navbar a little, this also never happened in VisionOS 1.0 but always happen in Vision 2.0+ because I've tested in the simulator with different versions.
Is it possible these problems to be related to handTracking Service that we use from ARKit? Because sometimes when we close the trackers the app works as intended.
Hi, does anyone know if it is an easy way to determine the distance between floor and ceiling in vision Pro?
Hi, we have in our app an immersive space and we taught the palm menu button is not available in immersive spaces, but when I look in the hand and tap the menu button appear. Is it possible to keep it hidden? Because we a have an hand tracking feature in palm and when we try to press a button to overlap the palm it triggers the menu button and then when the user presses again by mistake, it sends the application to the background.
This is very important for us because we would like to release this hand-tracking feature as soon as possible.
Here is a link with to a video with the problem:
https://drive.google.com/file/d/1cfOcdzF19h_mbmpvkVNCJjXEBJecVeJL/view?usp=sharing
Hi, I would like to put a video in an ImmersiveSpace but, when people tap on maximize button from top left corner, the app crashes. Is it a way to remove that button?
I need it to be in an ImmersiveSpace because I would like to be able to instantiate it wherever I want.
Hi, I have a question, is it possible to create an occlusion material that hide only specific entities. For example I would. like to create a mask that hides the an cube entity which is in front of another sphere entity and would like to be able to see the sphere but not the cube trough occlusion.
Is it possible to put an video on loop and autoplaying for visionOS? We used AVPlayerViewController
Hi, I have a problem in the new version of visionOS (2.0). When I call a magnify gesture for an attachment some times it works fine but some times the gesture doesn't call onEnded and onChanged is called just one time. Is it something known
Hello, I tried to create an subscription for my app but I receive this error every time, what should I do?
Hello, is it possible to change the immersion style at runtime?
Hi, I would like to remove an app from apple vision pro app store but also I would like to keep it for iPad and iPhone. Is it possible? I tried in xcode to select destinations only for iPhone and iPad but this doesn't work.
Hello, I would like to change the aspect (scale, texture, color) of a 3D element (Model Entity) when I hovered it with my eyes. What should I do If I want to create a request for this feature? And how would I know if it will ever be considered or when it will appear?
Hello, I tried to build something with scene reconstruction but I want to add occlusion on the Surfaces how can I do that? I tried to create an entity and than apply an Occlusion Material but I received an ShapeResourece and I should pass an MeshResource to create a mesh for the entity and than apply a material. Any suggestions?