Sharing data between Targets via App groups but Userdefault Container is null

Dear Apple Support Team,

I am trying to shared data between two different App target. Target A is main iOS app and Target B is Intent Extension. I have create app group and utilise app group to share data between different target but when setting the user default from Target B stile getting container null.

Target B UserDefault object details

sharedDefaults UserDefaults 0x0000600000c05110 baseNSObject@0 NSObject kvo id 0x0 0x0000000000000000 [0] id identifier __CFString * "group.com.xxxx. xxxx" 0x0000600001704900 container __CFString * NULL 0x0000000000000000 _volatileDomainNames id 0x0 0x0000000000000000 [0] id

Code snippet in Target B to setting UserDefault

    guard let sharedDefaults = UserDefaults(suiteName: SharedUserDefaults.suitName)else {
        completion(MuteIntentResponse(code: .failure, userActivity: nil))
        return
    }
    ///["event": AudioCommand.mute.rawValue]
    sharedDefaults.set("test", forKey: SharedUserDefaults.Keys.audioCommand)
    let didSynchronize =  sharedDefaults.synchronize()
    
    print("Intent Extension: Wrote Synchronize successful: \(didSynchronize)")
    
    guard let command = sharedDefaults.string(forKey: SharedUserDefaults.Keys.audioCommand) else {
        completion(MuteIntentResponse(code: .failure, userActivity: nil))
        return
    }
    
    print("userDef \(command)")

While reading UserDefault value in Target A

UserDefault object details baseNSObject@0 NSObject isa Class NSUserDefaults 0x01000001efe1a8a9 kvo id 0x0 0x0000000000000000 identifier __CFString * "group.com.xxxx. xxxx” 0x0000600001782200 container __CFString * NULL 0x0000000000000000 _volatileDomainNames id 0x0 0x0000000000000000 [0] id

Reading UserDefault value Code

if let def = UserDefaults(suiteName: SharedUserDefaults.suitName){ print("commandInfo (def.string(forKey: SharedUserDefaults.Keys.audioCommand))") }

Please let me know what I am doing wrong.

Are the App Groups defined in both the main app and extension?

Yeah, App groups are defined in both target.

Main app bundle identifier: in.***.app Intent extension identifier: in.***.app.MuteIntent App group: group.in.xxxx.shared

I have save value A in Main App target and B in Intent extension target against the same key and re-run the app. Both target have its own value which I saved previously. It means UserDefaults in not shared between targets.

Also tested same behaviour with Message extension where UserDefaults sharing working fine.

xcode: 16.2 iOS simulator: iphone 16 pro 18.1

Is it limitation with Intent extension (Siri)?

Thanks for your support.

I've resolved the issue. The problem was caused by conflicting entitlements. When the App Group capability was added, a new entitlements file was generated. To fix this, I merged the App Group information into the existing entitlements file, and the problem is now resolved.

Sharing data between Targets via App groups but Userdefault Container is null
 
 
Q