[GH-ISSUE #149] [BUG] NSUserDefaults are not written to App's respective directories #137

Closed
opened 2026-03-03 15:30:55 +03:00 by kerem · 1 comment
Owner

Originally created by @hugeBlack on GitHub (Sep 2, 2024).
Original GitHub issue: https://github.com/LiveContainer/LiveContainer/issues/149

Describe the bug

I found that although apps write almost all their files to their respective folders, their NSUserDefaults are still written to LiveContainer's Library/Preferences, which creates a mess in that folder and is hard for users to move apps to other devices.
I wander if it's possible to redirect NSUserDefaults writes to some folder in Document?

Instructions to reproduce

Install any app that uses NSUserDefaults and check LiveContainer's Library/Preferences

What version of LiveContainer are you using?

2.1.2

Other info

I dumped symbols of NSUserDefaults class and didn't find any way to set a path. I wonder if it's hard coded into that class, or it uses a different environment variable other than HOME?
I also tried to create a symlink but iOS didn't allow any write to Library/Preferences folder it self.

There is a method caller -[NSUserDefaults _initWithSuiteName:container:] but it seems that not all NSUserDefaults are instantiated by this method.

Originally created by @hugeBlack on GitHub (Sep 2, 2024). Original GitHub issue: https://github.com/LiveContainer/LiveContainer/issues/149 ### Describe the bug I found that although apps write almost all their files to their respective folders, their NSUserDefaults are still written to LiveContainer's `Library/Preferences`, which creates a mess in that folder and is hard for users to move apps to other devices. I wander if it's possible to redirect NSUserDefaults writes to some folder in Document? ### Instructions to reproduce Install any app that uses NSUserDefaults and check LiveContainer's `Library/Preferences` ### What version of LiveContainer are you using? 2.1.2 ### Other info I dumped symbols of NSUserDefaults class and didn't find any way to set a path. I wonder if it's hard coded into that class, or it uses a different environment variable other than `HOME`? I also tried to create a symlink but iOS didn't allow any write to `Library/Preferences` folder it self. There is a method caller `-[NSUserDefaults _initWithSuiteName:container:]` but it seems that not all `NSUserDefaults` are instantiated by this method.
kerem 2026-03-03 15:30:55 +03:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@hugeBlack commented on GitHub (Sep 3, 2024):

I found a method -[NSUserDefaults _container] that I can hook to redirect most NSUserDefaults write to other location, but some still write directly to Library/Preferences

<!-- gh-comment-id:2325503351 --> @hugeBlack commented on GitHub (Sep 3, 2024): I found a method `-[NSUserDefaults _container]` that I can hook to redirect most `NSUserDefaults` write to other location, but some still write directly to `Library/Preferences`
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/LiveContainer#137
No description provided.