Post

Replies

Boosts

Views

Activity

DeviceActivitySchedule when device is powered off
For my app, I use the DeviceActivity API to define a daily, repeating DeviceActivitySchedule that begins at 12:00AM and ends at 11:59 PM every day. I notice that when the device is powered off before 11:59 PM and powered back on the next day, neither the intervalDidEnd nor intervalDidStart callback functions are called. It appears that the interval extends into the next day and only ends once 11:59 PM comes around again. What is the expected behavior of the system to call the intervalDidStart and intervalDidEnd callback functions when the device is powered off during the scheduled start or end time?
3
2
1.8k
Dec ’22
DeviceActivity App Extension Lifecycle
I've asked several questions about DeviceActivity performance issues where the answers have cited limitations to the lifecycle of the DeviceActivity App Extensions. For example: Question about DeviceActivityReport lag and performance issues responded letting me know that my extension may be exceeding its memory limit of 100MB and subsequently getting terminated by the system. Question about async tasks in DeviceActivityMonitor responded letting me know that the monitor extensions lifecycle ends and is terminated by the system once all synchronous functions return, so it has no async support. I couldn't find either of these facts documented anywhere, and the DeviceActivity docs mention very little about how the extensions actually work. In general, it seems like these app extensions are basically a black box. Is there any additional comprehensive documentation about the true lifecycle of the app extensions, their limitations, and how apps should handle error cases (like the system terminating the app extension process)? If not, I would be very grateful if you could provide any information you have in the response to this question. Thanks in advance!
1
2
969
Mar ’23
DeviceActivityMonitor is overcounting screen time for users on iOS 17.6.1
Our app uses a 24-hour DeviceActivityMonitor repeating schedule to send users notifications for every hour of screen time they spend on their phone per day. Notifications are sent from eventDidReachThreshold callbacks at 1, 2, 3, etc, hour thresholds to keep them aware of their screen time. We have recently received an influx of emails from our users that after updating to iOS 17.6.1 their DeviceActivityMonitor notifications are saying their screen time was much higher than what is shown in DeviceActivityReport and their device's Screen Time settings. These users have disabled "Share Across Devices" - but I suspect the DeviceActivityMonitor is still getting screen time from their other devices even though that setting is turned off. Has anybody else noticed this, understands what is causing this, or could recommend a fix that we can tell our users to do?
10
8
1.8k
Oct ’25
DeviceActivityReport Lag
There have been several posts (i.e. here, here) about the lagginess of the DeviceActivityReport extension. Often it takes a few seconds for the view to load, or sometimes doesn't show up at all. I've confirmed this is not a case of excessive memory usage in the extension (exceeding 100MB), because I've profiled the extension and it consistently maxes out at 10MB. I've placed a loading screen behind the DeviceActivityReport inside a ZStack in the host app in order to see if the lag is because it takes some time for the extension to spin up - but the loading screen does not appear, indicating that the extension is running right away, but receiving the view from the extension in the host app is where the lag happens. It's been extremely difficult to debug because the lag only occurs a fraction of the time, and DeviceActivityReport is pretty much a black box. There's no documentation about how the host app and extension actually communicate. I've also combed through the logs using the Console app on Mac with no indication of any issues, (but I do see the message "Connection to view service was invalidated" coming from the extension even when there is no lag). I'm pretty convinced that the problem lies in the host app, because when I strip everything away from the host app, DeviceActivityReport never lags. I suspect that there are processes running (network requests, async tasks, or state updates) that block the report view from being received in the host app. Could you please help me understand why this could be happening, with as many details as you could provide? Any details on how the host and extension communicate, what processes could block the view from appearing, or anything else. Seems like this is a common issue but plenty of apps also don't experience it. Any guidance you can provide would be extremely helpful, as I've been trying to fix this bug every since I've been working with this API with no luck. Thanks in advance!
4
7
1.9k
Apr ’24
ShieldConfigurationExtension not working
I created a ShieldConfigurationExtension in Xcode 14.3 with File > New > Target > ShieldConfigurationExtension. This created the extension with all the necessary Info.plist values (correct NSExtensionPrincipalClass, etc.), with the extension included in embedded content in the host app target. No matter what I try, the extension is not getting invoked when I shield applications from my host app. The custom UI does not show as the shield, and looking at the debugger, an extension process is never invoked. I am shielding categories like this: let managedSettings = ManagedSettingsStore() ... managedSettings.shield.applicationCategories = .all() And my extension code overrides all the ShieldConfigurationDataSource functions. class ShieldConfigurationExtension: ShieldConfigurationDataSource { override func configuration(shielding application: Application) -> ShieldConfiguration { return ShieldConfiguration( backgroundBlurStyle: UIBlurEffect.Style.systemThickMaterial, backgroundColor: UIColor.white, icon: UIImage(systemName: "stopwatch"), title: ShieldConfiguration.Label(text: "You are in a Present Session", color: .yellow) ) } override func configuration(shielding application: Application, in category: ActivityCategory) -> ShieldConfiguration { return ShieldConfiguration( backgroundBlurStyle: UIBlurEffect.Style.systemThickMaterial, backgroundColor: UIColor.white, icon: UIImage(systemName: "stopwatch"), title: ShieldConfiguration.Label(text: "You are in a Present Session", color: .yellow) ) } override func configuration(shielding webDomain: WebDomain) -> ShieldConfiguration { return ShieldConfiguration( backgroundBlurStyle: UIBlurEffect.Style.systemThickMaterial, backgroundColor: UIColor.white, icon: UIImage(systemName: "stopwatch"), title: ShieldConfiguration.Label(text: "You are in a Present Session", color: .yellow) ) } override func configuration(shielding webDomain: WebDomain, in category: ActivityCategory) -> ShieldConfiguration { return ShieldConfiguration( backgroundBlurStyle: UIBlurEffect.Style.systemThickMaterial, backgroundColor: UIColor.white, icon: UIImage(systemName: "stopwatch"), title: ShieldConfiguration.Label(text: "You are in a Present Session", color: .yellow) ) } } What am I missing?
5
2
2.6k
Jun ’25
DeviceActivity monitoring limits
Within the DeviceActivity API, the documentation for DeviceActivityCenter.startMonitoring says: "Attempting to monitor too many activities or activities that are too tightly scheduled can cause this method to throw an error." Is there a documented limit of the amount of activities that are able to be monitored simultaneously? I understand that monitoring "too many activities" will throw an excessiveActivities error, but I can not find documentation that specifically identifies the conditions that this error can be thrown.
1
1
1.3k
Jul ’22
Terminate and re-launch DeviceActivityReport Extension
The DeviceActivityReport is often laggy or sometimes doesn't show up at all. Quitting and re-opening the app usually fixes this problem. I'm wondering, is there a way to programmatically terminate and then re-launch the DeviceActivityReport App Extension from the host app? This way, that could act as a "refresh" when the DeviceActivityReport fails to show up.
0
1
910
May ’23
DeviceActivityMonitor event thresholds triggered together - what is the best way to log crashes / system terminations in the DeviceActivityMonitor extension?
I've been using DeviceActivityMonitor for 2 years, and recently noticed the following issue, starting in iOS 17.5 (another user also reported here). For a sizable percentage of my users, device activity event thresholds get triggered together. My app sends notifications for every hour of screen time during the DeviceActivitySchedule using event thresholds. Often users will get, for example, the 1, 2, and 3 hour screen time notifications all at the same time. I have a hypothesis for why this is happening: the system sometimes terminates the app extension for various reasons, one being if the 6MB memory limit is reached. It seems as though the retry policy is to retry the failed threshold at the next event threshold. And if the following threshold also fails, they can pile up until the next one succeeds. I think this is a new retry policy since iOS 17, and I believe this because: There used to be a bug where the same threshold was triggered multiple times in a row, indicating that the failed threshold was retried immediately. This bug is no longer around and it's been replaced by the one I am reporting. According to my logs, thresholds that get triggered together are also called earlier when they are supposed to be called - but the callback function does not complete. So this indicates that the threshold isn't just called late, but that it is called once and then retried again later. If anyone could answer the following questions I'd be super grateful: Is there ANY way to log when the system terminates the app extension and for what reason? And not just on my own device, but for all our users in production (because it's hard to reproduce this issue, as it only happens for some portion of our users). Maybe some kind of crash report or failure callback that will allow my to ping my server? Could anyone at Apple could confirm my hypothesis about the new retry policy causing this issue?
1
5
749
Nov ’24
iOS 16: Code signature is no longer supported
I am developing an app for iOS 16 using the Xcode 14.0 beta. I've created certificates and provisioning files both through Xcode and manually following instructions at https://developer.apple.com/documentation/xcode/running-your-app-in-the-simulator-or-on-a-device, but every time when trying to install the app on my iPhone 13 Pro Max running iOS 16.0 beta, I get the error The code signature version is no longer supported. Googling around, I haven't found anything funky about code signing with iOS 16 beta, but that might be because it is so new. Is there any reason that my code signature would be invalid given my developer setup? It's attached to my Apple ID and I am a member of the Apple Developer Program. Here's the details to my error if you want to dig in: Details Unable to install "Screentox" Domain: com.apple.dt.MobileDeviceErrorDomain Code: -402620375 User Info: { DVTErrorCreationDateKey = "2022-08-02 13:43:50 +0000"; IDERunOperationFailingWorker = IDEInstalliPhoneLauncher; } -- The code signature version is no longer supported. Domain: com.apple.dt.MobileDeviceErrorDomain Code: -402620375 User Info: { DVTRadarComponentKey = 487925; MobileDeviceErrorCode = "(0xE8008029)"; "com.apple.dtdevicekit.stacktrace" = ( 0 DTDeviceKitBase 0x0000000122538c30 DTDKCreateNSErrorFromAMDErrorCode + 235 1 DTDeviceKitBase 0x00000001225752ff __90-[DTDKMobileDeviceToken installApplicationBundleAtPath:withOptions:andError:withCallback:]_block_invoke + 155 2 DVTFoundation 0x000000010b7453b5 DVTInvokeWithStrongOwnership + 71 3 DTDeviceKitBase 0x0000000122575027 -[DTDKMobileDeviceToken installApplicationBundleAtPath:withOptions:andError:withCallback:] + 1409 4 IDEiOSSupportCore 0x0000000121f6c66c __118-[DVTiOSDevice(DVTiPhoneApplicationInstallation) processAppInstallSet:appUninstallSet:installOptions:completionBlock:]_block_invoke.301 + 3520 5 DVTFoundation 0x000000010b87a629 __DVT_CALLING_CLIENT_BLOCK__ + 7 6 DVTFoundation 0x000000010b87b13d __DVTDispatchAsync_block_invoke + 196 7 libdispatch.dylib 0x00007ff81d8990cc _dispatch_call_block_and_release + 12 8 libdispatch.dylib 0x00007ff81d89a317 _dispatch_client_callout + 8 9 libdispatch.dylib 0x00007ff81d8a0317 _dispatch_lane_serial_drain + 672 10 libdispatch.dylib 0x00007ff81d8a0dfd _dispatch_lane_invoke + 366 11 libdispatch.dylib 0x00007ff81d8aaeee _dispatch_workloop_worker_thread + 753 12 libsystem_pthread.dylib 0x00007ff81da4dfd0 _pthread_wqthread + 326 13 libsystem_pthread.dylib 0x00007ff81da4cf57 start_wqthread + 15 ); } -- Analytics Event: com.apple.dt.IDERunOperationWorkerFinished : { "device_model" = "iPhone14,3"; "device_osBuild" = "16.0 (20A5328h)"; "device_platform" = "com.apple.platform.iphoneos"; "launchSession_schemeCommand" = Run; "launchSession_state" = 1; "launchSession_targetArch" = arm64; "operation_duration_ms" = 4934; "operation_errorCode" = "-402620375"; "operation_errorDomain" = "com.apple.dt.MobileDeviceErrorDomain"; "operation_errorWorker" = IDEInstalliPhoneLauncher; "operation_name" = IDEiPhoneRunOperationWorkerGroup; "param_consoleMode" = 0; "param_debugger_attachToExtensions" = 0; "param_debugger_attachToXPC" = 1; "param_debugger_type" = 5; "param_destination_isProxy" = 0; "param_destination_platform" = "com.apple.platform.iphoneos"; "param_diag_MainThreadChecker_stopOnIssue" = 0; "param_diag_MallocStackLogging_enableDuringAttach" = 0; "param_diag_MallocStackLogging_enableForXPC" = 1; "param_diag_allowLocationSimulation" = 1; "param_diag_gpu_frameCapture_enable" = 0; "param_diag_gpu_shaderValidation_enable" = 0; "param_diag_gpu_validation_enable" = 0; "param_diag_memoryGraphOnResourceException" = 0; "param_diag_queueDebugging_enable" = 1; "param_diag_runtimeProfile_generate" = 0; "param_diag_sanitizer_asan_enable" = 0; "param_diag_sanitizer_tsan_enable" = 0; "param_diag_sanitizer_tsan_stopOnIssue" = 0; "param_diag_sanitizer_ubsan_stopOnIssue" = 0; "param_diag_showNonLocalizedStrings" = 0; "param_diag_viewDebugging_enabled" = 1; "param_diag_viewDebugging_insertDylibOnLaunch" = 1; "param_install_style" = 0; "param_launcher_UID" = 2; "param_launcher_allowDeviceSensorReplayData" = 0; "param_launcher_kind" = 0; "param_launcher_style" = 0; "param_launcher_substyle" = 0; "param_runnable_appExtensionHostRunMode" = 0; "param_runnable_productType" = "com.apple.product-type.application"; "param_runnable_type" = 2; "param_testing_launchedForTesting" = 0; "param_testing_suppressSimulatorApp" = 0; "param_testing_usingCLI" = 0; "sdk_canonicalName" = "iphoneos16.0"; "sdk_osVersion" = "16.0"; "sdk_variant" = iphoneos; } -- System Information macOS Version 12.4 (Build 21F79) Xcode 14.0 (21304.3) (Build 14A5270f) Timestamp: 2022-08-02T09:43:50-04:00
4
4
2.3k
Nov ’22
Please help make DeviceActivityReport reliably show up
Our app uses DeviceActivityReport to display the user’s screen time. The performance of DeviceActivityReport is often very poor. These issue occur commonly: Screen time is reported as 0 minutes DeviceActivityReport View appears completely blank The host app loses connection with the DeviceActivityReport altogether I have implemented several workarounds which only slightly improve the performance, to varying degrees depending on the device iOS: Inside the DeviceActivityReport code - retry fetching screen time data until it returns a non-zero result Implement a “refresh” button which reloads the DeviceActivityReport view from the host app However, due to the sandboxed nature of DeviceActivityReport, there is no way for the host application to tell if the DeviceActivityReport extension is experiencing these performance issues. It results in a really bad user experience. I am building the app with Xcode 14 due to another issue where DeviceActivityReport fails to load for all iOS 16 devices when built with Xcode 15 (this is a know issue, here’s a link to a discussion on the developer forums: https://developer.apple.com/forums/thread/735915). However, when testing on iOS 17 devices with Xcode 15 builds, the above issues still occur. I have received no crash reports from DeviceActivityReport. These issues are known bugs and have been discussed on the developer forums, but I haven't yet seen a solution. Other screen time apps exist that use the DeviceActivityReport seemingly flawlessly, so I know that there is a way to improve the performance of DeviceActivityReport in my app. Please help! I have been dealing with this poor performance for a long time now with almost no improvement!
3
3
1.8k
Apr ’24
UserDefaults and @AppStorage causing DeviceActivityMonitor to crash on iOS 17
I use App Groups to share UserDefaults data between my host app and DeviceActivityMonitor extension. On iOS 17, it appears that reading @AppStorage variables are causing my DeviceActivityMonitor extension callback functions to crash. Weirdly, writing values is okay. I see this in the extension logs: Couldn't read values in CFPrefsPlistSource<0x10fe251d0> (Domain: GROUP_NAME, User: kCFPreferencesAnyUser, ByHost: Yes, Container: (null), Contents Need Refresh: Yes): Using kCFPreferencesAnyUser with a container is only allowed for System Containers, detaching from cfprefsd However, through searching this log message on the internet and the fact that it also appears in my host app logs without crashing, this seems to be a warning - possibly indicating an issue but also a possible red herring. But the fact remains that when I don't read UserDefaults values or variables decorated with @AppStorage in the DeviceActivityMonitor extension, everything works fine. Are UserDefaults, and specifically @AppStorage decorators supported in the DeviceActivityMonitor extension?
2
2
1.4k
Dec ’23
DeviceActivityReport lag and performance issues
I've been experiencing some serious performance issues with DeviceActivityReport. Their severity tends to vary across devices - for some of my users it's really bad and for some it's mostly fine - but every device seems to experience these issues at some point. 1. DeviceActivityReport is completely blank. Often on launch, the DeviceActivityReport is completely blank and the only way to make it show up is to click back and forth between tabs, or quit the app and re-open it. Sometimes, it will show up after one or two seconds, but that is still a bad user experience. When looking at logs during this issue, I can see that makeConfiguration still runs successfully and returns a value, so I suspect the issue is with the rendering of the View in the App Extension. 2. Gestures are slow to register, or can't register at all. For example, if I place my DeviceActivityReport inside a ScrollView, I cannot scroll if I perform the gesture on the report view. If I try to scroll on the part of the screen that's not inside the report view, the screen scrolls but it will lag. This makes me think that if I perform a gesture on the report view, only the view inside the App Extension will register the gesture, but not the parent view in my host app. Is that the expected behavior? My primary concern is number (1), it's by far the biggest pain point for my users and makes my app almost useless to them if they can't view their screen time :(. These issue have been reported before by other developers on the forum (https://developer.apple.com/forums/thread/723444, https://developer.apple.com/forums/thread/723491, https://developer.apple.com/forums/thread/720549). Instead of recommending that I submit a bug to Feedback Assistant (which I will do), I am kindly asking for some recommendations to work around the known performance issues of DeviceActivityReport. Several apps out there that use the DeviceActivity API that do not appear to have these performance issues, like Opal and Jomo, so they must be doing something right! One thing I've noticed is that the further up in the View hierarchy the DeviceActivityReport is, the better its performance, but I'm not sure why - maybe it is because the earlier the extension is connected to, the better. My app also has several tabs, makes network requests with asynchronous tasks on launch, uses the DeviceActivityMonitorExtension, and uses CoreData as a local data store. Maybe these things affect performance? Thank you in advance for any performance recommendations that you could provide!
3
3
1.9k
Mar ’23
Setting values in UserDefaults in DeviceActivityMonitor extension
I understand that the DeviceActivityMonitor extension is designed to be very lightweight, and the system terminates the extension as soon as its callback functions return. However, I want to save values to UserDefaults inside the extension's callback functions. This creates concurrency issues for my app because the documentation for UserDefaults states that "When you set a default value, it’s changed synchronously within your process, and asynchronously to persistent storage and other processes." In order to guarantee that these values are persisted before the extension terminates my app, I want to call UserDefaults.synchronize(), but its documentations states that it's "unnecessary and shouldn't be used." Furthermore, it's listed under "Legacy" but not marked deprecated. Is synchronize() the recommended way to solve my concurrency problem? Or could there be a better way to wait for storage synchronization before returning from a synchronous function?
5
1
2k
Jun ’23
Detecting Termination and Re-establishing Connection with DeviceActivityReport App Extension
Hello, I have an iOS app using the DeviceActivityReport app extension. Occasionally, the extension gets terminated (likely due to reaching memory limit**), which in turn disrupts the connection with the main app. How can the main app detect when the DeviceActivityReport extension has been terminated due to memory constraints, and what's the best way to re-establish the connection afterward? Thanks in advance for your insights and suggestions! ** I'm also unsure why the extension should be reaching its memory limit. When profiling the extension in XCode, it never reaches above 15MB, and I know the limit is 100MB. It's not doing anything out of the ordinary - and I've seen very similar complaints about DeviceActivityReport terminating on these forums. Any thoughts on how to prevent termination in the first place would also be super helpful!
3
1
1.4k
Sep ’23