[go: up one dir, main page]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can we have a way to view the shared app group sandbox files and user default plist under Resources? #88

Open
paulsumit1993 opened this issue Jul 16, 2024 · 2 comments
Labels
feature 💡 Feature to develop. good first issue 🌟 Good for newcomers

Comments

@paulsumit1993
Copy link

No description provided.

@MaatheusGois MaatheusGois added good first issue 🌟 Good for newcomers feature 💡 Feature to develop. labels Jul 16, 2024
@MaatheusGois
Copy link
Member
MaatheusGois commented Jul 16, 2024

According GPT, have one way :)

if you can, you could try!

In iOS development, directly viewing the contents of the shared app group sandbox and user defaults plist within the app’s Resources is not a standard feature provided by Xcode or iOS. However, you can achieve this through some indirect methods:

1.	Debugging with Xcode:
•	File System: You can use Xcode to explore the app’s file system. Connect your device, run the app, and use the “Devices and Simulators” window in Xcode. Select your device, find your app, and use the “Download Container” button to download the app’s data container. This will include the shared app group sandbox files.
•	User Defaults: You can write code to read the contents of UserDefaults and print them to the console. For example:
if let appGroupDefaults = UserDefaults(suiteName: "group.com.yourcompany.yourapp") {
    print(appGroupDefaults.dictionaryRepresentation())
}
2.	Custom Debug Screens:
•	You can create custom debug screens within your app that read and display the contents of the shared app group sandbox and user defaults. This can be useful for development and testing purposes. For example, you can list files in a table view and display their contents, or print user defaults in a text view.
3.	Third-Party Tools:
•	Tools like iExplorer or iMazing can be used to explore the file system of your iOS device, including the shared app group sandbox.

Here is a basic example of how you might set up a debug view controller to display the contents of the shared app group sandbox files:

import UIKit

class DebugViewController: UITableViewController {
    var files: [String] = []
    let fileManager = FileManager.default
    let appGroupID = "group.com.yourcompany.yourapp"

    override func viewDidLoad() {
        super.viewDidLoad()
        loadFiles()
    }

    func loadFiles() {
        if let containerURL = fileManager.containerURL(forSecurityApplicationGroupIdentifier: appGroupID) {
            do {
                files = try fileManager.contentsOfDirectory(atPath: containerURL.path)
                tableView.reloadData()
            } catch {
                print("Error loading files: \(error)")
            }
        }
    }

    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return files.count
    }

    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath)
        cell.textLabel?.text = files[indexPath.row]
        return cell
    }
}

This is a starting point, and you can expand it to read and display the contents of the files or user defaults in more detail.

@heitara
Copy link
Contributor
heitara commented Jul 31, 2024

@MaatheusGois are we going to add this to the library?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature 💡 Feature to develop. good first issue 🌟 Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants