Unwanted communication extension is unable to persist data written to defaults

I'm currently using 4 extensions within my app and use a group in combination with UserDefaults.init(suiteName:) to share settings between the extensions and the app.

However I've just tried adding an unwanted communications extension and found that data writing to defaults, in the exact same way as the other extensions, isn't saved. At first I noticed data written by the UCE wasn't present when the app tried to read it, so performed an experiment and found that while the extension is running, it can write and read data to user defaults, but the next time the extension runs, all that data has gone.

I've tried using the old and now default UserDefaults.synchronize() but it makes no difference.

Why is the UC extension different from every other extension? Is it possible to write and persist data from within it?

    let groupName = "group.com.mycompany.appName"
    let sharedDefaults = UserDefaults.init(suiteName: groupName)
    var theValue = sharedDefaults!.value(forKey: "some key")
    NSLog("\(theValue)") // prints nothing, despite the extension having previously run
    sharedDefaults!.set("some value", forKey: "some key"))
    sharedDefaults!.synchronize()
    theValue = sharedDefaults!.value(forKey: "some key")
    NSLog("\(theValue)") // prints "some value"

I'm getting the same result.

Xcode Version 13.0 (13A233)

Tested on iOS 15.5 iPhone 11 & iOS 14.6 iPhone 11.

I made a small project using Xcode Version 13.2.1 (3C100) with the same result.

Getting the spurious error found here

Along with this error:

SMSReport[6600:233574] [User Defaults] Failed to create directory /var/mobile/Containers/Shared/AppGroup/123AC467-Example-Removed-RealValue/Library/Preferences because of [1: Operation not permitted].
2022-07-28 16:29:29.044238-0600 SMSReport[6600:233574] [User Defaults] Couldn't write values for keys (
  numberKey
) in CFPrefsPlistSource<0x281f73c80> (Domain: group.com.mycompany.appName, User: kCFPreferencesCurrentUser, ByHost: No, Container: (null), Contents Need Refresh: No): Directory needed

The values were being persisted in the extension but the values were not reflected in the Host App.

I tried writing to FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: "group.com.mycompany.appName") and was getting an "Operation not permitted" too.

I'm beginning to think that persistence is not permitted in the Unwanted Communication Reporting Extension. However I have not tried the KeyChain capability yet.

After further attempts, and making use of the KeyChain capability, I believe Unwanted Communication Reporting Extension is not capable of any local writes.

Apple doesn't say this in the UCR docs. However they do say it in the Message Filtering Extension.

"For privacy reasons, the system handles all communication with your associated server; your Message Filter app extension can’t access the network directly. Your app extension also can’t write data to containers shared with the containing app."

Unwanted communication extension is unable to persist data written to defaults
 
 
Q