Adding images or videos to iPhone Simulator - ios
I am trying to use UIImagePickerController with UIImagePickerControllerSourceTypePhotoLibrary, but it says, "No photos". Where does the simulator get the images from? Where should I copy the images so that they are displayed in the simulator?
Explain step by step of Airsource Ltd's answer for adding image to simulator:
Drag it to simulator, then Safari opens
(or browse to the Image in the internet using Safari)
Hold your click on the image
When the pop-up appears, choose Save Image and enjoy ;)
Update: for iOS Simulator 4.2, do these steps twice to get it work. Thanks kevboh!
Update: This also works for iOS Simulator 6.1
The simplest way to get images, videos, etc onto the simulator is to drag and drop them from your computer onto the simulator. This will cause the Simulator to open the Photos app and start populating the library.
If you want a scriptable method, read on.
Note - while this is valid, and works, I think Koen's solution below is now a better one, since it does not require rebooting the simulator.
Identify your simulator by going to xCode->Devices, selecting your simulator, and checking the Identifier value. Or you can ensure the simulator is running and run the following to get the device ID xcrun simctl list | grep Booted
Go to
~/Library/Developer/CoreSimulator/Devices/[Simulator Identifier]/data/Media/DCIM/100APPLE
and add IMG_nnnn.THM and IMG_nnnn.JPG. You will then need to reset your simulator (Hardware->Reboot) to allow it to notice the new changes. It doesn't matter if they are not JPEGs - they can both be PNGs, but it appears that both of them must be present for it to work. You may need to create DCIM if it doesn't already exist, and in that case you should start nnnn from 0001. The JPG files are the fullsize version, while the THM files are the thumbnail, and are 75x75 pixels in size. I wrote a script to do this, but there's a better documented one over here(-link no longer work).
You can also add photos from safari in the simulator, by Tapping and Holding on the image. If you drag an image (or any other file, like a PDF) to the simulator, it will immediately open Safari and display the image, so this is quite an easy way of getting images to it.
3 Simple Steps
Drag & Drop image onto simulator
- this will open a browser with your image
Click & hold image
- this will open options
save image
- this will copy image onto simulator
Watch YouTube Video ( add images to iphone simulator)
With iOS 8.0, we added the ability to just drag and drop images into the iOS Simulator. You can drag a bunch of images into the window, and they should be imported into the photo reel for that simulated device. You can also do this with the simctl command line tool. 'xcrun simctl addphoto '
Since Xcode 6 you can use the command line tool xcrun simctl.
Usage is very simple; to add a photo to the currently running simulator you use the booted placeholder.
xcrun simctl addmedia booted ./MyFile.jpg
To add it to any other simulator, you use its device id, which can be found by running xcrun simctl list.
xcrun simctl addmedia E201E636-CE6C-11E5-AB30-625662870761 ./MyFile.jpg
Its simple. Just follow these steps :
Drag and drop image onto Simulator
Now image opens into Safari browser (file://.../ImageName). Tap-and-hold on the Image.
This displays actionSheet with Save, Cancel option (Also copy in case of iOS 7 simulator).
Save the image. The image gets added into Library.
I just stumbled upon how to bulk upload images on the iOS Simulator. (I've only confirmed it on 6.1.)
Backup the folder:
~/Library/Application Support/iPhone Simulator/6.1/Media
Copy all your images into the folder:
~/Library/Application Support/iPhone Simulator/6.1/Media/DCIM/100APPLE
Move or delete the folder:
~/Library/Application Support/iPhone Simulator/6.1/Media/PhotoData
Restart iOS Simulator
Open the Photos app
The simulator will restore all the images from the 100APPLE folder!
For iOS 7 I did the following:
copy photos to these two folders:
~/Library/Application Support/iPhone Simulator/6.1/Media/DCIM/100APPLE
~/Library/Application Support/iPhone Simulator/7.0/Media/DCIM/100APPLE
delete these 4 files only (to avoid duplicates on relaunch):
~/Library/Application Support/iPhone Simulator/6.1/Media/PhotoData/Photos.sqlite-shm
~/Library/Application Support/iPhone Simulator/6.1/Media/PhotoData/Photos.sqlite-wal
~/Library/Application Support/iPhone Simulator/7.0/Media/PhotoData/Photos.sqlite-shm
~/Library/Application Support/iPhone Simulator/7.0/Media/PhotoData/Photos.sqlite-wal
Just drag images to the iPhone simulator.
This is MUCH easier with the new iOS Simulator that comes with Xcode 6+ (iOS Simulator 8.1 and above.) Now all you have to do is drag one or more photos onto the iOS Simulator window, and instead of opening Safari, the Photos app opens, and instantly adds all dragged-in photos to the device.
Method 1 (Easiest Way): If you have your image on Mac
You can drag an image from the Finder on your Mac to Simulator, and it is saved to the Saved Photos album.
Method 2: If its on any URL
To save an image from a webpage to the Photos app
Place the pointer on the image you want to save, and hold down the mouse button or trackpad.
When the menu appears, click Save Image to save the image to the Photos app in an iOS simulator.
The image is saved to the Saved Photos album in the Photos app.
Incase someone looking for Apple Documentation regarding Copying and Pasting in Simulator.
If you can not drag and drop your files because you experience the error:
One or more media items failed to import: : The operation couldn’t be completed. (PHPhotosErrorDomain error -1.)
Move your files into the Documents folder and then drag them into the simulator. This will trigger the simulator to ask for permissions to access your files. Having them inside the Downloads folder, will not.
None of the answers had the exact solution that I needed.
The steps I've found for myself working on iOS 5.0 and above simulator are as follows:
Close the simulator if it is running xcode project.
Run simulator from the dock by clicking on it.
Drag & drop the image into simulator.
Tap and hold the image (opened in safari) and select the save option.
You are done.
For iOS 5.1 this is further changed to new path
~/Library/Application Support/iPhone Simulator/5.1/Media/DCIM/100APPLE
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.
None of the answers above worked for me on iOS 15.
I simply opened Files app and dragged and dropped the image there. It automatically imported the image to the Photos app and I was able to use everywhere through my simulator.
Cheers!
If you need to import more than just one or two photos then take a look at this article that I wrote. It describes an easy way to perform a bulk import of photos and works for iOS 4.x.
For iOS 8, If there is no need to retain photo capture date and location, just drop photo files to the simulator.
To retain photo meta data, do the following:
Copy photo files to: /Users/{USER}/Library/Developer/CoreSimulator/Devices/{UDID}/data/Media/DCIM/100Apple
Remove (or rename) folder: /Users/{USER}/Library/Developer/CoreSimulator/Devices/{UDID}/data/Media/photoData
Relaunch Simulator
Note: You need to replace {USER} with your user name and {UDID} with the UDID of the simulator. To find UDID for your simulator, from Terminal, run 'xcrun simctl list'.
quit the simulator.
Run simulator from the dock by clicking on it.
Drag & drop the image into simulator which you want to add.
it will open image in safari .
tap and hold the image and click the save option.
then open gallery and you will see the image which u had saved recently.
Adding an image to the Iphone Simulation running IOS 8.0 is even easier.
Drag your image to the simulator
IOS opens the Photo app and your image is now part of your collection.
No need to deal with Safari anymore
In OS X Catalina with Xcode 11 you have to do this differently.
First you MUST start the simulator. If you want to copy, say a photo to MULTIPLE simulated devices. Start all of them up. Then Right Click on a SINGLE (Multiple images will fail. ONLY does a single file.).
Share -> Simulator
A 'share sheet will pop-up. You must choose an active simulator in the combo box and hit send.
It will send one to many but NOT many to many of selected photos.
I hope this helps folks. Drag and drop was supported in the last versions of Xcode and OS X but not with OS X Catalina and Xcode 11.
While this IS in the directions it currently IS NOT working.
What DID work for me was to first import my images into iPhoto on OS X and then DRAG/DROP them from my OS X iPhoto and drop into the simulator. It would appear the drag/drop for photos into the simulator is CURRENTLY only working from OS X iPhoto. :-(
For iOS 4.2 I had to go and create the 100APPLE folder and restart the simulator, then it worked.
try this app I've made. download the code and run it in simulator https://github.com/cristianbica/CBSimulatorSeed
For iOS 8.0,the answer is out of date.I found the media resource in the following path:
~/Library/Developer/CoreSimulator/Devices/[DeviceID]/data/Media/DCIM/100APPLE
Using your pc just Send the image via your email
Open the IOS-Simulator then open the email and download the image
just click and hold the mouse on the image, and from the options that will be displayed
Then, it will be automatically saved to your iOS-Simulator's photo gallery
Just Drag and Drop image into iphone simulator. browser will open to show your image.
press on image until you not receive options to save Image. then Save image.
thats it :). you will see your image in to Photo app in your simulator....
I wrote a bash script to do this.
Check the link[1]
#!/bin/bash
# Imports pictures into all iOS simulators.
path_to_pic="src/ios/pictures/"
mkdir -p /Users/$(whoami)/Library/Application\ Support/iPhone\ Simulator/{5.0,5.1,6.0,6.1}/Media/DCIM/100APPLE/
find ~/Library/Application\ Support/iPhone\ Simulator/ -type d -name '100APPLE' -exec cp /Users/$(whoami)/$path_to_pic/* {} \;
[1] : https://gist.github.com/firesofmay/5194901
Just to tell you : KONG's solution also works on iOS 7 beta.
His solution was:
Drag the image to simulator, then Safari opens (or browse to the Image in the internet using Safari)
Hold your click on the image
When the pop-up appears, choose Save Image and enjoy ;)
I just needed some random images for testing, so this is how I did it.
I have the simplest solution in the world. Just open Safari in the simulator, go to Google images (or your own web or Dropbox URL), view an image, hold down the mouse button for 2 seconds, and you'll see "Save Image" - it will save right into the Photos library. Rinse and repeat.
an even easier way, is :
open safari on simulator > tap www.google.com
search for random photos "nature"
open each image, press on it and save it.
Related
iOS Simulator - Dragging images from Finder Not Adding to Photos in Xcode 10
Just installed macOS Mojave and Xcode 10. I'm trying to drag images from Finder onto the Simulator to add them to Photos, which was working the day before on High Sierra and Xcode 9. Does anyone know if Apple has changed / blocked this or if there is another solution to get local images into Photos?
As of Version 10.1 (SimulatorApp-877 CoreSimulator-581.2), I found what works for now. For some reason keeping the Finder window in the background and keeping the simulator window in the foreground while dragging and dropping the photo into Photos app works. Selecting multiple photos does not work since trying to do that brings the Finder into foreground. Make sure your Finder stays in the background and, no, selecting multiple images does not seem to work no matter what I have tried. I hope this helps!
Just hold the image to Photos icon and drop it, this will help you. -Drag a photo Result:-
For some reason, you have to hold the image you're dragging over the Simulator window for a few seconds (specifically, until the window gets into focus and the little plus symbol next to the cursor disappears). This might be a bug in Xcode 10.
The drag&drop feature works well in XCode 12. If it isn't working for you, just try to quit and reopen the simulator.
The launch screen image not showing up on my ios app on the device
I have an ios app but am trying to add a launch image to the start. I am testing on an old ios 6 phone (which I think is the retina 4.7). I added the launch image in assets catalog like I then have it mentioned like so: When I run the app on my iPhone 6 device it has no load screen. What am I missing? I used to have a LaunchScreen.storyboard but I have all these images of the right size made and want to use those.
I've had this issue before and I believe it's a bug with Xcode. It will still be trying to use the LaunchScreen.storyboard file. Try the following: Clean your project. Delete the app from the device/simulator. Restart Xcode/Simulator and re-run. See https://stackoverflow.com/a/33698093/5032154 for more info.
iOS Sharing Extension app icon not changed to new
I have changed the appicon in xcode project. But My sharing extension keeps showing old one. When I delete appicon files then it shows nothing but when I add again it shows me old one. By the way it shows correct in the simulator but not in device
Try to delete app, reboot device and install again. It's work for me. As I understand, iOS save app icon and launch screen to cache after first app running and load it from cache until rebooting.
Can not add images to iOS Simulator
I can not add any images to ios simulator. I tried saving from google images and tried dragging the images to photos app in the simulator but no image appear in my photos app. There are only 5 sample images. My iOS simulator is 8.1 and same problem in all simulators(iphone 6, 5s,4s)
Go to ~/Library/Application Support/iPhone Simulator/User/Media/DCIM/100APPLE/ …and add Dog.THM and Cat.JPG. ~/Library/Application Support/iPhone Simulator/6.1/Media/DCIM/100APPLE ~/Library/Application Support/iPhone Simulator/7.0/Media/DCIM/100APPLE This might help you.
Easies way is to drag the image from your computer and drop it on your simulator. There's no need to drop it to the photos app. It'll automatically add the image to the photos app.
Copy paste text into iOS simulator
This must be documented somewhere, but I can't find it. In my app using the iPad simulator there is a textfield into which I want the user to paste text. In the real world the user will copy the text from Safari address into the textfield. But I am trying to do that in the ios ipad simulator, but with only partial results. After I reRUN the app, I can immediately paste text into the textfield with the Mac's Edit|Paste Text menu or with Shift-Command-V, (but not with just Edit|Paste, but that's Ok). The need for the Shift is annoying but I can live with it. But then if I try to copy another URL on the Mac and then again, Edit|Paste Text or even use the Paste bubble on the simulator, I don't get the new text, but the original text. Is that common? Is that a feature of the simulator that it is not connected live to the clipboard on the host computer?
I found that even with Edit > Automatically sync pasteboard ticked, the feature didn't work. However, simply unticking and then reticking this option fixed the feature! Hope it works for someone.
Be careful to avoid conflating the mac's clipboard with the simulator's clipboard. They are not the same. The simulator is simulating an iOS device, with it's own iOS clipboard which apps running on that device (simulator) use via the iOS pup-up select-all/copy/paste UI items. Completely separate from that: your mac has it's own clipboard and content. The Simulator program running on your mac provides the Edit > Paste Text menu item. The program implements that menu item by accessing your mac clipboard and types the text into the simulator as if the user used the keyboard. The iOS clipboard is neither accessed nor affected by the Simulator application's Edit menu functions. Update: As of Xcode 6, you need to choose the Edit > Paste menu item in the iOS Simulator (this transfers the data between the Mac clipboard and the iOS Clipboard), then tap in the field in the simulator and tap the "Paste" bubble. In your question you don't specify which "Safari" you're copying the URL from. It could be the mac safari application or the simulator's safari app. Doing a copy from the mac safari program goes to the mac clipboard, doing a copy from the safari app goes to the iOS clipboard inside the simulator. I think your issues are coming from confusing the two, thinking there's one clipboard everything is sharing.
Copy text on the mac, then click the text field in the simulator and press Shift Command V
Please click "Automatically sync pasteboard" option in Simulator edit option.
Xcode 10.0+: Turning the Automatic Pasteboard Sync off and then back on again solved the issue. You might have to do that multiple times. Sometimes it takes a while to trigger it for some reason. (Edit -> Automatic Pasteboard Sync)
What worked for me is this. 1) copy text from Mac 2) In simulator do edit->paste or Command V (I think this copies the text from mac clipboard to iOS Simulator clipboard). 3) Highlight the textfield in simulator and then do command + Shift + V.
I updated to os x 10.13.6 and xcode 10.1 and there is an added menu in edit click get pasteboard then you will be able to paste via the paste tooltip in simulator
Similar thing happened to me and I found a strange workaround, it may help anyone else that may come across the same issue. Try the following steps: Disable and then re-enable the Automatically Sync Pasteboard option, it's found under the Edit menu on the Simulator Copy the text you want from your Mac Paste the text again on your Mac on a text editor like Atom or even your browsers Address Bar Select all the text Cmd+A and then cut/copy Cmd+X/Cmd+C You should now be able to paste the text on the simulator
After trying a lot and nothing work on M1 Macs and simulator above 14 I have taken the different route to solve problem. Apple script to type the text in simulator. tell application "System Events" set texttosay to "Sample Text" display dialog "Text to type:" default answer "white: " set texttosay to the text returned of the result repeat delay 2 repeat 1 times keystroke texttosay delay 1 keystroke return end repeat exit repeat end repeat end tell Steps: Run above script in apple scripts and paste the text in dialogue box you want to type in simulator. click the input-box to populate the value. Hope that helps in your problem. Thanks
Nothing from the above solutions worked for me. I am using M1 Apple. The thing that worked was this thread https://github.com/flutter/flutter/issues/74970 In short, if you are using iOS 14.0 to build the app, you will have the above issues. In order to solve it, what I did was installing iOS 13.7 in xCode by going to Preferences -> Components -> iOS 13.7 -> then rebuild the app in the xCode.
Just Disable and then re-enable the Automatically Sync Pasteboard option from Edit menu, fixed my problem.
In a new emulator, I got no "paste" option and sync did not work for the simulator. It appears that in the simulator you MUST copy something to the internal clipboard before the sync actually works.
Untick and tick again "Automatically Snyc Pasteboard". Then quit the simulator and re-open it. This is what fixed it for me.
Sometimes it's very difficult to type long URLs in iOS simulator. There should be some way to copy URL from Max OS to iOS text field. Here's how you can do it: Copy some text from Mac Open the simulator and click on a text field where you want to paste the text Now in Simulator menu click on Edit -> Paste Text and that's it. Your text from the Mac OS copy buffer should now be there in iOS simulator's text field.
Three steps:(The key point is make sure that the "Paste" help menu is keeping visible when you use " ⌘ + V".) make sure you select the point you want to past in the simulator, and the editMenu with "Paste" is show. use keyboard on mac," ⌘ + V", to paste the text into simulator clipboard. click the "Paste" on editMenu that show above, to paste the text into simulator textField.
sometimes you just need to select Hardware -> reset content and settings in simulator menu. then all works automatically as easy and transparent as working in MacOS with other applications
Facing the same issue on Apple M2 and Simulator 13.4.1, I was digging into my OS logs and it seems that there are some issues in the Simulator - I guess - since I can read that it is not able to retrieve the content of the pasteboard, stored in a file. I can still open myself the file and confirm the content of the pasteboard is OK. After request access to the corresponding file while pasting (either using "Paste" menu or classic cmd+V), I can read something like : Upload preparation for claim XXXX completed with error: Error Domain=NSCocoaErrorDomain Code=256 "Impossible d’ouvrir le fichier « bbbb »." UserInfo={ NSURL=file:///Users/username/Library/Developer/CoreSimulator/Devices/XXXX/data/Library/Caches/com.apple.Pasteboard/ZZZZZ/, NSFilePath=/Users/username/Library/Developer/CoreSimulator/Devices/XXXX/data/Library/Caches/com.apple.Pasteboard/ZZZZZ/data/Library/Caches/com.apple.Pasteboard/aaaaa/bbbb, NSUnderlyingError=0x6000005105d0 {Error Domain=NSOSStatusErrorDomain Code=-10817 "(null)"}} So I guess, Apple has just some adjustments still on-going on the Simulator. Thus, neither disabling/enabling Auto-sync nor forcing sync of the pasteboard worked in my case.
This is a solution that might work if you are working with React Native. I ran into this issue now with my M1 Pro Macbook. It started when I updated Xcode to 14.0 before that everything worked fine. What seems to be the issue is that I'm running terminal in Rosetta. When starting the simulator via npx react-native run-ios this starts the simulator in Rosetta as well (I'm assuming here cannot prove it). Solution: Make sure Xcode is running natively and running the project from Xcode instead of Terminal, the Copy-paste functionality should work again.
If you are using Better Touch Tool(BTT), you can create CMD+V action for iOS Simulator and run an apple script that will do the past clipboard tell application "System Events" delay 0.1 keystroke (get the clipboard as text) end tell I hope it will help somebody. P.S don't forget to bump the answer if it's helped 👍
This works for me. On Safari version 8.0.3 and IOs simulator version 8.1 Copy text from Safari - highlight text then cmd-v or Edit>Copy. In Ios Simulator click Edit>Paste. On TextField or TextView right click then select Paste.
This is what I found. Copy text from mac. In simulator open safari and highlight the address bar by clicking it. Press Cmd + V Click once on address bar. Paste drop down shall appear. Tap on paste. Shift + Cmd + V works great too.
⌘ + V : When iOS simulator is in front,copy the contents of the OS X clipboard over to iOS, but doesn't paste it. Again, this works for both text and images. So you need to do as follows: 1.copy text anywhere in your macOS except iOS simulator. 2.in iOS simulator, click ⌘ + V, copy text from macOS clipboard to iOS simulator's clipborad. 3.in iOS simulator, TextField or TextView click -> Edit ->Paste.
None of these solutions worked for me. I'm using Simulator 11.4. And after trying each of these, I realized all I needed to do was copy something on my Mac using Command + C, and then in the simulator text field, simply hold down the mouse click for an extra second or two, and the paste menu popped up automatically, and worked great.