Category Archives: iPhone Simulator

Adding an image(s) to the iPhone Simulator

I managed to finally get an image to into my iPhone Simulator, running into a problem now, I can’t find the image to delete it or change.

Anyway once you if you know the device that is running (if not you can find out the GUID here:  https://qatesttech.wordpress.com/2015/04/22/determining-which-device-is-running-in-the-iphone-simulator/)

These steps then worked for adding images:

How to bulk upload images on the iOS Simulator. (I’ve only confirmed it on 6.1.)

  1. Backup the device folder:
    1. ~/Library/Application Support/iPhone Simulator/6.1/Media
  2. Copy all your images into the folder:
    1. ~/Library/Application Support/iPhone Simulator/6.1/Media/DCIM/100APPLE
  3. Move or delete the folder:
    1. ~/Library/Application Support/iPhone Simulator/6.1/Media/PhotoData
  4. Restart iOS Simulator
  5. Open the Photos app

The simulator will restore all the images from the 100APPLE folder! – yours will be there too 

Notes:
  1. My Devices aren’t in this location, they are under ~/Library/Developer….
  2. I didn’t do step 1, since launching the Simulator copies missing stuff back
Now I have the problem that even though my image doesn’t appear in the 100APPLE directory, it still shows up when the simulator runs, though if I run the simulator manually, that image isn’t there.
Update 1:
  • This isn’t a solution for me (but might be for some folks:
    • As of iOS 8, you can just drag all your photos onto the simulator window and they’ll save to camera roll automatically. You can do as many at a time as you want.
Update 2:
So I copy the photo to 100APPLE, like mentioned above.  Now the photo seems to be there forever.  Even if I remove everything, the default stuff shows up, but when the simulator is run (invoked using Appium) the photos I previously manually added, reappear inside the phone Simulator.  If I launch the phone Simulator manually the photos aren’t there, so there is an Appium factor that I am unware of/not sure how it works.  Found out the image copy issue, it is all on me, not knowing all the parts of the interconnected system I inherited – education is good 🙂
 Update 3:
A bit clunky, but command line nuking the image files in a folder while the iPhone Simulator is running
find ~/Path to Devices/(GUID of Device)/data/Media/DCIM/100APPLE/ -iname “*.jpg” -delete
Example:
find ~/Library/Developer/CoreSimulator/Devices/6A0CB955-C22B-48A6-A7F5-809806EB57F2/data/Media/DCIM/100APPLE/ -iname “*.jpg” -delete
Advertisements

Determining which “device” is running in the iPhone Simulator

I ran into a problem (again an issue with inheriting someone else’s system and trying to figure out how all the parts work.).  The System uses xCode, and Appium, and Ruby, and RSPEC.  In theory, according to the documention there is a configuration file, which based on the GUID tells me which “device” is running in the simulator.  Per this configuration file, which only has one line of text:

  • {“Simulator ID”: “FEE861DF-59E1-43EA-B17A-A3C289293B0C”}

The Device that is running should have a GUID of FEE861DF-59E1-43EA-B17A-A3C289293B0C.  So if I track that device down in the Developer Directory (see: https://qatesttech.wordpress.com/2015/04/22/resetting-an-iphone-simulator-and-clearing-images/ ),  I will find a device.plist, which has the device description.

According to the device.plist, I should be running an iPhone 6 with iOS 8.2, and this also lets me track down the image directory so I can put in the images I want to process with our App.  However when I ran the test suite, using the “magical” command:  rspec spec/business_card_spec.rb (which is rspec <sub-directory> and name of the test suite that needs to be run), the simulator launched fine, but when it opened the Photo Albums it had different photos and the version at the top of the simulator said “8.3” – so something isn’t quite right.

Fortunately I add a second window open (from trying to add images while the iPhone Simulator was running) and I ran the command:

  • xcrun simctl list

This provided some awesome insight, I got back this list (a bit hard on the eyes):

== Device Types ==
iPhone 4s (com.apple.CoreSimulator.SimDeviceType.iPhone-4s)
iPhone 5 (com.apple.CoreSimulator.SimDeviceType.iPhone-5)
iPhone 5s (com.apple.CoreSimulator.SimDeviceType.iPhone-5s)
iPhone 6 Plus (com.apple.CoreSimulator.SimDeviceType.iPhone-6-Plus)
iPhone 6 (com.apple.CoreSimulator.SimDeviceType.iPhone-6)
iPad 2 (com.apple.CoreSimulator.SimDeviceType.iPad-2)
iPad Retina (com.apple.CoreSimulator.SimDeviceType.iPad-Retina)
iPad Air (com.apple.CoreSimulator.SimDeviceType.iPad-Air)
Resizable iPhone (com.apple.CoreSimulator.SimDeviceType.Resizable-iPhone)
Resizable iPad (com.apple.CoreSimulator.SimDeviceType.Resizable-iPad)
== Runtimes ==
iOS 8.3 (8.3 – 12F69) (com.apple.CoreSimulator.SimRuntime.iOS-8-3)
== Devices ==
— iOS 8.3 —
iPhone 4s (CF459D0C-F679-437D-894B-72FD95436AF1) (Shutdown)
iPhone 5 (C66C2BC3-9A6D-493D-A9D8-915E40363B7C) (Shutdown)
iPhone 5s (80B3FD17-5D99-4DF9-A0C9-372CAC091828) (Shutdown)
iPhone 6 Plus (632E3762-6129-4939-BAFF-B6F1099BD3F4) (Shutdown)
iPhone 6 (6A0CB955-C22B-48A6-A7F5-809806EB57F2) (Booted)
iPad 2 (B0D6162A-B01D-4BE1-929E-18855C29B847) (Shutdown)
iPad Retina (B74C3D84-99B0-43AF-8D75-2D29A1A7764B) (Shutdown)
iPad Air (52F8083B-D47D-4341-8B6C-E8C74384ED91) (Shutdown)
Resizable iPhone (0ADA273B-B83E-4C9B-B8BD-350494F2C7A8) (Shutdown)
Resizable iPad (4FFB59A3-11CA-4C29-A049-C62495A2D934) (Shutdown)
— Unavailable: com.apple.CoreSimulator.SimRuntime.iOS-8-0 —
iPhone 4s (AD216DA2-6EF2-4CC5-9222-71FF8BBB5746) (Shutdown) (unavailable, runtime profile not found)
iPhone 5 (06BF26ED-6892-4BAF-9D94-5D92171A7C1A) (Shutdown) (unavailable, runtime profile not found)
iPhone 5s (142B5205-8506-4EB6-A80A-FEA8A6F022AC) (Shutdown) (unavailable, runtime profile not found)
iPhone 6 Plus (015F9A02-CC77-4F9B-9E42-77FAF7AA6876) (Shutdown) (unavailable, runtime profile not found)
iPhone 6 (6299F3DE-44AE-4D86-84E8-E2A5C883BD4F) (Shutdown) (unavailable, runtime profile not found)
iPad 2 (DF9EEDF3-A0D0-48DA-AFC4-72C96999B9D4) (Shutdown) (unavailable, runtime profile not found)
iPad Retina (A7AAA454-46E3-4D73-AB3A-FE2F1C6E5B66) (Shutdown) (unavailable, runtime profile not found)
iPad Air (40D3CE5A-9059-4D3B-96AB-B736D21D20C6) (Shutdown) (unavailable, runtime profile not found)
Resizable iPhone (8164FE9D-AE3D-45D6-8429-5A06AA870262) (Shutdown) (unavailable, runtime profile not found)
Resizable iPad (8B586B7B-C618-4C8C-A10B-47B3CE0E37EA) (Shutdown) (unavailable, runtime profile not found)
— Unavailable: com.apple.CoreSimulator.SimRuntime.iOS-8-2 —
iPhone 4s (2DA772B3-8ED2-4D2F-BB71-0CABFED9C3EC) (Shutdown) (unavailable, runtime profile not found)
iPhone 5 (C77D8C25-3D04-4E4B-B698-5E02B42B5857) (Shutdown) (unavailable, runtime profile not found)
iPhone 5s (7F057144-D6AC-4E58-BB59-60A677E97F6C) (Shutdown) (unavailable, runtime profile not found)
iPhone 6 Plus (EB5DB275-830C-4898-8F2F-FFBD23A5A3A9) (Shutdown) (unavailable, runtime profile not found)
iPhone 6 (FEE861DF-59E1-43EA-B17A-A3C289293B0C) (Shutdown) (unavailable, runtime profile not found)
iPad 2 (1F6BA798-DD20-42A3-B837-EBFFDE74C9BE) (Shutdown) (unavailable, runtime profile not found)
iPad Retina (D9B2B211-E32A-49ED-A474-D05DE16EFBE4) (Shutdown) (unavailable, runtime profile not found)
iPad Air (61256C66-4326-4646-86E6-161D6096869C) (Shutdown) (unavailable, runtime profile not found)
Resizable iPhone (09C6240A-BA0D-4875-9D6B-9D84A330D6B2) (Shutdown) (unavailable, runtime profile not found)
Resizable iPad (263A9CF2-6CBF-4A7D-9BD5-4B38323C1B5B) (Shutdown) (unavailable, runtime profile not found)

Tough to read, but I noticed the status “Booted” I was running a different iPhone 6 – GUID:  6A0CB955-C22B-48A6-A7F5-809806EB57F2, the device.plist there clearly shots it is configured for iOS 8.3.

Launched xCode and looked at the list of devices, and found the iPhone 6 with the GUID listed above, for some reason that is overriding the configuration file.  Next Task, tracking down why that is happening.

Apparently the information in appium.txt is overriding the configuration file.  In Appium.txt is list the device as “iPhone 6” which is a simulator device that can be found in

  • xCode -> Window -> Devices
    • This is how to get to “devices” in xCode 6.3.1

So I guess I need need to try fixing the images for GUID: 6A0CB955-C22B-48A6-A7F5-809806EB57F2

 

Resetting an iPhone Simulator and Clearing Images

In theory there is this command, though I haven’t tried it yet and it requires the iPhone Simulator to be running

  • xcrun simctl erase device_UUID

Another option, which also requires the iPhone Simulator to be running is:

  • Within the iPhone/iPad simulator, go to the top-menu and select “iOS Simulator” -> “Reset Content and Settings…

However what I really need is control over the images of the device.

One Stack Flow Article mentioned this location

  • /Users/<username>/Library/Application Support/iPhone Simulator/User/Applications
    • There are a bunch of GUID files and directories. They match up to the apps you have installed on your simulator.

I couldn’t find a folder called “iPhone Simulator”, this might be due to how my installation was setup (I followed someone else’s instructions during a knowledge dump). However I did finally find my Simulator files under “Developer”

Devices

  • /Library/Developer/CoreSimulator/Devices
    • Under Devices is a list of Directories that use the GUID as the folder name, you can find these GUID’s in the device list in the iPhone Simulator

Devices

Now that you found the directories you can remove the images if you wish, but going to a sub-directory under data (under your device)

  • /Library/Developer/CoreSimulator/Devices/GUID/data/Media/DCIM/100APPLE

Example:

  • /Library/Developer/CoreSimulator/Devices/06BF26ED-6892-4BAF-9D94-5D92171A7C1A/data/Media/DCIM/100APPLE
    • I’m not sure if the sub-directory is always called “100APPLE” but that is the image directory

 

100APPLE

 

So resetting the iPhone Simulator, puts all the default photos back (like roaches 🙂 , they can’t be nuked by a reset).  So the search continues, and I do dislike postings the same “manually” drag photos or something, that kind of defeats the purpose of automation.

 

Adding an image to the iPhone Simulator via the command line

So from the notes I was given, this is the command to make it work

xcrun simctl addphoto 6A0CB955-C22B-48A6-A7F5-809806EB57F2 /Users/username/Dropbox\ \(Evernote\)/Scannable\ Image\ Library/Moleskine.jpg

Which failed for me.

An error was encountered processing the command (code=146):
Invalid device state

Then I found out that you need the iPhone Simulator running first to make this work, considering I got the notes and overview in a knowledge before someone left the company, I can understand how details like that were lost.

So you need the iPhone simulator running and the command will add an image to the iPhone Simulator (though this caused other failures for)

So Command Usage

  • xcrun (Run or locate development tools and properties Command line)
  • simctl (Command line utility to control the iOS Simulator)

So me in this case I need to add a photo for processing by our app, fortunately there is a command “addphoto”

  • xcrun simctl addphoto (Device ID) /PATH To Image
    • Note 1: Simulator needs to be running for this command to work
    • Note 2: You can drag an image to the command line and OSx will put in the path to the image for you
  • Example: xcrun simctl addphoto 6A0CB955-C22B-48A6-A7F5-809806EB57F2 /Users/username/Dropbox\ \(Evernote\)/Scannable\ Image\ Library/Moleskine.jpg
    • username = your actual username