Any workaround for expanding a large category in FamilyActivityPicker?

I’m developing a self-management app using Family Controls, but I’ve encountered a FamilyActivityPciker's crash due to an XPC(or UIRemoteView) issue when there are too many tokens(maybe 200+ items) in a category. This makes bad UX, so I’m looking for a workaround.

(I guess that the crash reason is cross process memory limitations, such as App Extension 50MB memory limitation.)

A lot of web domains contribute to increase the number of tokens, However, even after clearing Safari’s browsing history, the tokens displayed in the FamilyActivityPicker remains unchanged.

Is there any workaround that a 3rd party developer can implement to address this issue? prevent FamilyActivityPicker crashes or reduce the number of web domain tokens?

For example, if there’s a way to reset the web domain tokens shown in FamilyActivityPicker from the Settings app, I could offer a help to users.

Does anybody have ideas?

Expanding SNS Category (29 items)

It succeeded.

Expanding Productivity & Finance (214 items)

It failed. The screen froze, then appears blank. When the number of items is around 100, the crash rate is 50%, but when the items are over 200, the crash rate is 100%.

Search Bar Problem

The search bar also has same problem. If the number of search results are small, it works good without any blank, but if there are a lot of search results (200+), the XCP crashes and the screen appears blank.

Code to Reproduce

import SwiftUI
import FamilyControls

struct ContentView: View {
    
    @State private var selection = FamilyActivitySelection()
    @State private var isPickerPresented: Bool = false
    
    var body: some View {
        VStack {
            Button("Open Picker") {
                isPickerPresented = true
            }
        }
        .familyActivityPicker(isPresented: $isPickerPresented, selection: $selection)
    }
}

Steps to Reproduce

  1. Prepare a category that has 200+ items
  2. Try to open the category in the picker
  3. The screen will freeze, then appears blank.

Errors in Console

 [u EDD60B83-5D2A-5446-B2C7-57D47C937916:m (null)] [com.apple.FamilyControls.ActivityPickerExtension(1204)] Connection to plugin interrupted while in use.
 
 AX Lookup problem - errorCode:1100 error:Permission denied portName:'com.apple.iphone.axserver' PID:2164 (
     0   AXRuntime                           0x00000001d46c5f08 _AXGetPortFromCache + 796
     1   AXRuntime                           0x00000001d46ca23c AXUIElementPerformFencedActionWithValue + 700
     2   UIKit                               0x0000000256b75cec C01ACC79-A5BA-3017-91BD-A03759576BBF + 1527020
     3   libdispatch.dylib                   0x000000010546ca30 _dispatch_call_block_and_release + 32
     4   libdispatch.dylib                   0x000000010546e71c _dispatch_client_callout + 20
     5   libdispatch.dylib                   0x00000001054765e8 _dispatch_lane_serial_drain + 828
     6   libdispatch.dylib                   0x0000000105477360 _dispatch_lane_invoke + 408
     7   libdispatch.dylib                   0x00000001054845f0 _dispatch_root_queue_drain_deferred_wlh + 328
     8   libdispatch.dylib                   0x0000000105483c00 _dispatch_workloop_worker_thread + 580
     9   libsystem_pthread.dylib             0x0000000224f77c7c _pthread_wqthread + 288
     10  libsystem_pthread.dylib             0x0000000224f74488 start_wqthread + 8
 )
 
 Error acquiring assertion: <Error Domain=RBSAssertionErrorDomain Code=2 "Specified target process does not exist" UserInfo={NSLocalizedFailureReason=Specified target process does not exist}>
Answered by Engineer in 805569022

This is a known bug, please follow up with your bug report(s).

Hey ! We opened an Apple bug report for this exact issue 2 years ago with id FB11400221, can you open a report yourself to get this fixed by apple ? We have a lot of user reports about it, and we didn't find a workaround. We found a way to detect the crash though, and we show am explanation dialog when it happens.

I have reported the issue to Feedback Report (FB14067691).

Accepted Answer

This is a known bug, please follow up with your bug report(s).

For people who want to show an alert as soon as possible after the FamilyActivityPicker has crashed, I'll share my workaround !

Workaround

struct MyView : View {
  let stateUpdateTimer = Timer.publish(every: 1, on: .main, in: .common).autoconnect()
  @State private var updateFlag: Bool = false

  var body : some View {
    ZStack {
      Text(verbatim: "A") // This should not be empty.
        .foregroundStyle(.clear)
        .accessibilityHidden(true)
        .opacity(updateFlag ? 1 : 0)

      ContentUnavailableView(...)
      FamilyActivityPicker(...)
    }
    .onReceive(stateUpdateTimer) { _ in
        updateFlag.toggle()
    }
  }
}

Description

At first glance, it looks like the FamilyActivityPicker has frozen, but I realized that it simply doesn’t redraw. Therefore, if there is an event that triggers a redraw, it will quickly transition to a transparent after the crash.

The above code forces a view update every second by toggling the opacity of a view that is completely irrelevant to the user.

This let the FamilyActivityPicker transition to a transparent and immediately show an alert in ZStack.

Good Points

This workaround doesn't touch any private API and private class. It relies only on public APIs and minimal code, therefore It will continue to work without issues even if the internal implementation is changed in the future.

This exists since iOS 16, I don't have any hopes of it being fixed...

From what I managed to uncover it is memory issue since the picker runs in special extension and apparently has just handful of memory. I am not sure why Apple yet hasn't "simply" increase the memory limit. The Photos picker works fine without issues.

Any workaround for expanding a large category in FamilyActivityPicker?
 
 
Q