3

How can I pull the NSUserDefaults shared preferences from the command line? This would be for a development build. I'd like to use a shell script of some sort and call it to retrieve this info. Is this possible? If so, how?

UPDATE: I also need to get it from the unrooted device not simulator unfortunately. Its because I want to grab the APNS token and store it somewhere. I am storing the APNS token in a NSUserDefaults currently. To be clear, I have a iOS app, and I want to get the APNS token that I'm storing in NSUserDefaults using a command line script on Mac. The reason I need it from the device is I can't do push notification from simulator so I wont get APNS token unless real device registers.

update: i saw this SO article Browse the files created on a device by the IOS application I'm developing, on workstation? but i want to automate this. Anyway to pull down the container from shell using xcode command ?

Community
  • 1
  • 1
j2emanue
  • 60,549
  • 65
  • 286
  • 456
  • Unless your device is jail broken, I doubt this is possible. – mah Jan 06 '16 at 15:51
  • If you log the token to console, you could possibly retrieve it using libimobiledevice: http://krypted.com/mac-os-x/use-libimobiledevice-to-view-ios-logs/ – chedabob Jan 06 '16 at 16:18

2 Answers2

1

If you're using the simulator you can find them in

~/Library/Developer/CoreSimulator/Devices/<dev-uuid>/data/Containers/Data/Application/<app-uuid>/Library/Preferences/<app-bundle>.plist

dev-uuid is the UUID of the simulator (you can find a list of them with xcrun simctl list)

app-uuid is the UUID for this installation of the app

app-bundle is your app bundle (i.e. com.test.testApp)

chedabob
  • 5,835
  • 2
  • 24
  • 44
0

First of all, you do not need to solve this problem. Just write some code to print data to console.

If you do need to do so, here is the solution for standard user defaults (group user defaults is stored in another path, which I can not handle now).

  1. Make sure your app is not installed via App Store.
  2. Install iExplorer (on Mac OS or iFunbox on Windows) and plug in your device.
  3. Open iExplorer (or iFunbox) and browser to this app. Export the whole sandbox directory to you PC.
  4. The user defaults is stored in Library/Preferences/<app-bundle>.plist. Open it with Xcode.
John Wong
  • 342
  • 2
  • 10
  • i need it automated. Whats happening is with my automation test, i need to get the APNS token so we can do automated tests with it. Are you suggesting we print it to the console and read it from there ? iFunbox would not be automated but rather manual. – j2emanue Jan 06 '16 at 19:28
  • @john-wong you don't need iFunbox if you've got Xcode installed. You can get the app sandbox from the Devices window. – chedabob Jan 06 '16 at 21:45