How to check [NSUserDefaults standardUserDefaults] in iOS development device with Xcode 9.3 [duplicate]
Asked Answered
H

1

7

In Xcode 9.3 and iOS simulators, [NSUserDefaults standardUserDefaults] store the values at:

/Users/{User Name}/Library/Developer/CoreSimulator/Devices/{Device GUID}/data/Containers/Data/Application/{application GUID}/Library/Preferences/{bundle identifier}.plist

where I could open the .plist file easily and look into the values.

But, how could I check these values when the app is running in a development device? Is it possible to check these values in a developed device like as simulators?

Hanschen answered 16/5, 2018 at 14:15 Comment(2)
Is there any particular reason to open the PList directly instead of just using NSUserDefaults? If you just need to see what's stored, using dictionaryRepresentation() would give you everything: for (key, value) in UserDefaults.standard.dictionaryRepresentation() { print("\(key) = \(value)") }Conformation
@Krunal Yes, this solved my problem. ThanksHanschen
M
10

You cannot access it directly. Apple does not allow, an access to such kind of data (and/or files) of iOS application (for any external sources) from device.

Only application developer can access it programatically. (There are some software available in market, which can open/access files from IPA using Jail-broken devices.)

Refer this Apple document: iOS Security - File Data Protection. (There is no direct answer to your question but complete details about file and data security, in this doc.)

But if you are a developer of this app then you can find it from AppData Preferences.

Follow these steps to find it:

  1. Open Device and Simulator window (Xcode (Menu) >> Window >> Devices and Simulators).
  2. Select your iOS device from a list of connected devices.
  3. Select an apps from a list of Installed Apps.
  4. Click on application Settings icon
  5. Select Download Container, that will prompt you to save you file.
  6. Save your file (file extension - .xcappdata)

enter image description here

  1. Right click on file and select Show Package Contents

enter image description here

  1. A finder window will show a path to AppData of file.
  2. Go to: AppData >> Library >> Preferences >> <file>.plist
  3. Bingo: This is what you are looking for. UserDefault storage file. Open it and check your data.

enter image description here

Macklin answered 16/5, 2018 at 14:46 Comment(3)
Sorry but this answer is incorrect - at least when it comes to an app your are developing.Labio
Thanks! This worked for me for my real development device. I was able to read the UserDefaults file using Xcode 11.4.1.Genuflection
confirmed, this worked for viewing UserDefaults file downloaded from actual device. Crazy how many steps it requires just to view a snapshot.Deandreadeane

© 2022 - 2024 — McMap. All rights reserved.