Post

Replies

Boosts

Views

Activity

Reducing Memory Usage in DeviceActivityMonitor: Help Needed
Hi everyone, I am a beginner in Swift and I am currently using DeviceActivityMonitor to develop an app for parents to control their children's app usage time. During the development process, I found that the DeviceActivityMonitor has a 6MB memory limit in the background, and my app exceeds this limit after running for a long time. I would like to know how to reduce the memory usage of DeviceActivityMonitor in the background, or where I can check the memory usage of DeviceActivityMonitor and see which variables are consuming memory. Additionally, I want to know if a new instance of the DeviceActivityMonitor class is created every time it is called? Thank you for your help!
1
2
642
Aug ’24
FamilyActivityPicker will have a problem closing the parent element fullScreenCover in the 18.4 official version
.fullScreenCover(isPresented: $isShow) { Button(action : { isPresented.toggle() }){ Text("Choose") } .familyActivityPicker( isPresented: $isPresented, selection: $selection) .onChange(of: selection){ value in } } In the official version of iOS 18, when I click the Done button of familyActivityPicker, the fullScreenCover pop-up box will disappear.
2
2
178
Apr ’25
Summary of issues encountered with the Screen Time interface
I have developed three apps using the Screen Time API. The following are common problems I encountered in the three apps: DeviceActivityMonitorExtension is automatically killed after running for a few days (frequently) The same DeviceActivityEvent in DeviceActivityMonitorExtension is triggered twice during eventDidReachThreshold (especially obvious in iOS18.5) Screen Time authorization is automatically canceled for no reason (occasionally) I hope to get help
5
2
193
Jun ’25
Live Activity (Dynamic Island) suddenly stopped working without code changes
Hi everyone, I am encountering an issue where my Live Activity (Dynamic Island) suddenly became invalid and failed to launch. It was working perfectly before, and I haven't modified any code since then. My Environment: Xcode: 26.1.1 Device iOS: 26.1 Testing: I also tested on iOS 18, but the Live Activity fails to start there as well. Here is my code: Live Activity Manager (Start/Update/End): func startLiveActivity() { // Initial static data let attributes = SimpleIslandAttributes(name: "Test Order") // Initial dynamic data let initialContentState = SimpleIslandState(message: "Preparing...") // Adapting for iOS 16.2+ new API (Content) let activityContent = ActivityContent(state: initialContentState, staleDate: nil) do { let activity = try Activity.request( attributes: attributes, content: activityContent, pushType: nil // Set to nil as remote push updates are not needed ) print("Live Activity Started ID: \(activity.id)") } catch { print("Failed to start: \(error.localizedDescription)") } } // 2. Update Live Activity func updateLiveActivity() { Task { let updatedState = SimpleIslandState(message: "Delivering 🚀") let updatedContent = ActivityContent(state: updatedState, staleDate: nil) // Iterate through all active Activities and update them for activity in Activity<SimpleIslandAttributes>.activities { await activity.update(updatedContent) print("Update") } } } // 3. End Live Activity func endLiveActivity() { Task { let finalState = SimpleIslandState(message: "Delivered ✅") let finalContent = ActivityContent(state: finalState, staleDate: nil) for activity in Activity<SimpleIslandAttributes>.activities { // dismissalPolicy: .default (immediate), .after(...) (delayed), .immediate (no animation) await activity.end(finalContent, dismissalPolicy: .default) print("End") } } } The Models (Shared between App and Widget Extension): // 1. Define State (Dynamic data, changes over time, e.g., remaining delivery time) public struct SimpleIslandState: Codable, Hashable { var message: String } // 2. Define Attributes (Static data, constant after start, e.g., Order ID) public struct SimpleIslandAttributes: ActivityAttributes { public typealias ContentState = SimpleIslandState var name: String // e.g., "My Order" } The Widget Code: // // SimpleIslandWidget.swift // ReadyGo // // Created by Tang Yu on 2025/11/19. // import WidgetKit import SwiftUI import ActivityKit struct SimpleIslandWidget: Widget { var body: some WidgetConfiguration { ActivityConfiguration(for: SimpleIslandAttributes.self) { context in // UI shown on the Lock Screen VStack { Text("Lock Screen Notification: \(context.state.message)") } .activityBackgroundTint(Color.cyan) .activitySystemActionForegroundColor(Color.black) } dynamicIsland: { context in // Inside Widget Extension DynamicIsland { // Expanded Region DynamicIslandExpandedRegion(.center) { Text("Test") // Pure text only } } compactLeading: { Text("L") // Pure text only } compactTrailing: { Text("R") // Pure text only } minimal: { Text("M") // Pure text only } } } } Additional Info: This is the minimal code setup I created for testing, but even this basic version is failing. I have set NSSupportsLiveActivities (Supports Live Activities) to YES (true) in the Info.plist for both the Main App and the Widget Extension. Has anyone experienced this? Any help would be appreciated.
3
0
115
3w
Color picker not working
HStack{ FormLable(text: NSLocalizedString("Color", comment: "")) Spacer() Image(systemName: "circle.fill") .font(.system(size: AppFontSize.baseSize.size() * 1.2, weight: .medium)) .foregroundColor(color) .overlay(ColorPicker("Color", selection: $color).labelsHidden().opacity(0.015)) } This is how I use the color picker. I used the same code in two different apps, and the color picker appeared in one app but not in the other. By the way, I upgraded Xcode to the latest version.
2
0
371
Feb ’25
ManagedSettingsStore&socialStore.shield
when i watch the video (https://developer.apple.com/videos/play/wwdc2022/110336/) i find the code let socialStore = ManagedSettingsStore(named: .social) let socialCategory = database.socialCategoryToken socialStore.shield.applicationCategories = .specific([socialCategory]) i try to find ManagedSettingsStore shield and specific([socialCategory]) i Documentation , but i failed. who can tell me wher i can find about ManagedSettingsStore shield or specific([socialCategory]) ? thanks a lot.
0
0
518
Mar ’24
Issue with Missing Application Token Data in DeviceActivityEvent
I am developing an application for managing screen time, and I encountered an issue when retrieving DeviceActivityEvent bound to a specific DeviceActivityName using the events method of DeviceActivityCenter. I noticed that the application token data bound to DeviceActivityEvent is missing. Could you help me understand why this might be happening?
1
0
482
Jul ’24
Bug in DeviceActivity
I am developing an app using DeviceActivity. let schedule = DeviceActivitySchedule( intervalStart: DateComponents(hour : 0, minute : 0, second: 1), intervalEnd: DateComponents(hour : 23, minute : 59, second: 59), repeats: true ) I found that on the second day, intervalDidStart(for: DeviceActivityName) gets called multiple times. I also tried let schedule = DeviceActivitySchedule( intervalStart: DateComponents(hour : 0, minute : 0, second: 1), intervalEnd: DateComponents(hour : 23, minute : 59, second: 59), repeats: false ) and started monitoring for the next day in the intervalDidEnd(for: DeviceActivityName) method. but , intervalDidStart(for: DeviceActivityName) still gets called multiple times. How should I resolve this issue?
0
0
448
Oct ’24
Issues with Multiple Activations and Interruption of intervalDidStart in DeviceActivity When Using ScreenTime API
I am a Swift developer using the ScreenTime API to develop an app that helps users manage app usage time on their phones. While working with DeviceActivity, I've noticed that it sometimes gets activated multiple times in succession, and occasionally, the code within intervalDidStart stops executing midway. What could be the cause of this?
0
0
310
Nov ’24