Post

Replies

Boosts

Views

Activity

DeviceActivityMonitor - Callbacks not trigger
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.") } }
1
1
136
1w
Carousel Flicker
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
1
0
176
3w
Maintain rotation sense while dragging
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.
1
0
254
Nov ’24
Hover Effect & Tap Problem
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.
0
0
240
Nov ’24
Palm Menu Button Issue
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
1
0
398
Sep ’24