Reputation: 2049
Can someone tell me how can I add files to be used as test files for uploading from the simulator?
I dragged a PDF to the simulator and this is all I get. Can't really tap the Add button.
Upvotes: 83
Views: 76242
Reputation: 7089
As with Apple goes, they often do breaking changes with xcode / simulator and I found none of the answer of zipping/dragging/xcrun or even saving from icloud/safari working.
The only way I could get this to work after extensive trial and error is the following way:
xcrun simctl listapps booted
"com.apple.DocumentsApp" = {
ApplicationType = System;
Bundle = "file:///Library/Developer/CoreSimulator/Volumes/iOS_22A3351/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS%2018.0.simruntime/Contents/Resources/RuntimeRoot/Applications/Files.app/";
CFBundleDisplayName = Files;
CFBundleExecutable = Files;
CFBundleIdentifier = "com.apple.DocumentsApp";
CFBundleName = Files;
CFBundleVersion = "335.1";
DataContainer = "file:///Users/samuel/Library/Developer/CoreSimulator/Devices/CE9CF483-08B9-4E5B-8A4B-85FEEA091EDE/data/Containers/Data/Application/FBF8DF15-DBD9-4B31-A241-BEF2705AE584/";
GroupContainers = {
"group.com.apple.DocumentManager" = "file:///Users/samuel/Library/Developer/CoreSimulator/Devices/CE9CF483-08B9-4E5B-8A4B-85FEEA091EDE/data/Containers/Shared/AppGroup/7A4EE496-D41A-410C-87A0-AC316360BF71/";
"group.com.apple.FileProvider.LocalStorage" = "file:///Users/samuel/Library/Developer/CoreSimulator/Devices/CE9CF483-08B9-4E5B-8A4B-85FEEA091EDE/data/Containers/Shared/AppGroup/DC898A75-8F12-4E5B-9348-A2CF95295DF6/";
"group.com.apple.tipsnext" = "file:///Users/samuel/Library/Developer/CoreSimulator/Devices/CE9CF483-08B9-4E5B-8A4B-85FEEA091EDE/data/Containers/Shared/AppGroup/7469808E-746A-44B4-96B4-6E0E8A927E64/";
};
Path = "/Library/Developer/CoreSimulator/Volumes/iOS_22A3351/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 18.0.simruntime/Contents/Resources/RuntimeRoot/Applications/Files.app";
SBAppTags = (
);
};
The key thing here is to find the object named
"com.apple.DocumentsApp"
and then you'll need to look for the key:"group.com.apple.FileProvider.LocalStorage"
under theGroupContainers
object
We'll take the path from there, in case of my answer:
file:///Users/samuel/Library/Developer/CoreSimulator/Devices/CE9CF483-08B9-4E5B-8A4B-85FEEA091EDE/data/Containers/Shared/AppGroup/DC898A75-8F12-4E5B-9348-A2CF95295DF6/
file://
and add the "File Provider Storage"
to the end part of the key and voila you've got the synced path.Now you can either open the location in Finder / whatever fileman you're using or just copy files to it from terminal, i.e.
For example
mv ~/Downloads/example.pdf /Users/samuel/Library/Developer/CoreSimulator/Devices/CE9CF483-08B9-4E5B-8A4B-85FEEA091EDE/data/Containers/Shared/AppGroup/DC898A75-8F12-4E5B-9348-A2CF95295DF6/File\ Provider\ Storage
And you'll find the file in your Simulator finder under Browse (On this iPhone)
Upvotes: 0
Reputation: 49
create a folder, copy your file to the folder and then drag the folder and drop it in files in simulator or home screen, audio file will be copied in simulator.
Upvotes: 1
Reputation: 282
The easiest way is to create a Folder in iOS Simulator Files app with a random string like: "Qhdtbixpx".
Then search for it in Macbook Finder in the Devies folder (Cmd + G : /Users/user/Library/Developer/CoreSimulator/Devices/
) , you'll easily find the folder and be able to add files there.
Upvotes: 2
Reputation: 11
You don't need any hacks for that. Steps:
I use it always, it works perfectly. You can do same for media files(pictures/video). The official info from Apple: https://developer.apple.com/documentation/xcode/sharing-data-with-simulator#Add-files-to-Simulator
Upvotes: -1
Reputation: 688
If you want to file .app you can file follow this step by step.
open Finder -> Go -> Computer -> Untitled -> Users -> (FolderNameYourMacbook)
/Library/Developer/Xcode/DerivedData/YourAppName-xxxxxxxxx/Build/Products
Upvotes: 0
Reputation: 1634
The answer is much simpler, just zip the file in macOS and drag and drop into the simulator, it will automatically be opened in the files app and there you can decompress and use it.
Upvotes: 21
Reputation: 877
Currently, you can click using your right mouse button on the folder / image that you wanna send and select from the list Share -> Simulator
then you'll see a list of options:
Upvotes: 12
Reputation: 2953
If you want to add some files to the "Files" app, first you have to find its directory in your mac, create a directory named for example, "MagicTheGreate", in the "Files" app, and then go to the command line and search the ./Library folder for the name.
find ~/Library/Developer/CoreSimulator/Devices/ -name MagicTheGreate
Now you can copy your files to that directory or the parent one, it will show up on your simulator. The bad news is, the directory changes once in a while and you have to find it again.
Upvotes: 3
Reputation: 195
In my case I wanted to upload the proxy certificate with shell without any confirmation dialog, so I came up with this:
SIM_UDID=$(xcrun simctl list devices | grep Booted | awk -F'[\(\)]' '{print $2}')
find ~/Library/Developer/CoreSimulator/Devices/$SIM_UDID/data/Containers/Shared/AppGroup/ -name "File\ Provider\ Storage" -exec cp path_to_some_file {} \;
First line is simply getting the UDID of a booted simulator and the second one is finding all File Provider Storage
directories inside booted simulator and then copies the file to them.
Copied file should appear inside Files app.
Of course if one wants to specify the simulator or multiple simulators are booted, grep Booted
can be changed to grep <name_of_the_device>
UPDATE
this lines can copy the file directly just to LocalStorage, no other directories in the contrary to the previous solution.
SIM_UDID=$(xcrun simctl list devices | grep Booted | awk -F'[\(\)]' '{print $2}')
FILES_PATH=$(xcrun simctl listapps $SIM_UDID | grep LocalStorage | awk -F'"' '{print $4}' | sed -e "s/^file:\/\///")
cp path_to_some_file $FILES_PATH/File\ Provider\ Storage
This approach makes use of xcrun simctl listapps
command which return the AppGroup id of FileProvider.LocalStorage
Upvotes: 0
Reputation: 141
You can put files in your APP's local /documents folder. To get the directory name in your APP do
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *fileNam = [NSString stringWithFormat:@"myImage.JPG"]; NSString *filePath = [[paths objectAtIndex:0] stringByAppendingPathComponent: fileNam];
you will also need to enable file sharing by putting
UIFileSharingEnabled
in info.plist
You can copy any file you like into the simulator's local documents directory.
Upvotes: 0
Reputation: 579
I found one easy way to do it with a little help from Python3 (I suppose all Macs should have it installed by default.
Here are the steps.
(I need to transfer a self-signed certificate to the simulator)
python3 -m http.server
to launch an HTTP serverUpvotes: 8
Reputation: 6156
Since none of the given solution worked for me on Simulator of iOS 13/Xcode 11, (trying to add a file, dragged from the Finder would just give an error), I found a workaround.
This takes a bit of setting up at first, but you get free access to the actual folder right from the Finder.
When I drag a file to the Simulator (providing no other App handles the file), the Files App would open, but when I save, I get "Invalid argument error".
The solution:
The folder named "On my phone" in the Simulator is called "File Provider Storage". The aim is to find it in the Finder.
The full path:
username/Library/Developer/CoreSimulator/Devices/device_hash_folder/data/Containers/Shared/AppGroup/hash_folder/File Provider Storage/
(Note:
Up until to current version (13.1), the Simulator does not work for picking files. You can see the files, but nothing happens on click.)
Here are the steps:
From here there are two ways
The short:
(In the Finder)
3a. Navigate to: username/Library/Developer/Core Simulator/Devices.
3b. Search for the folder you created. It should be in "File Provider Storage". That is the "On my phone" folder.
If the search does not find for any reason:
3a. Run an App and print (from Xcode) the path to documentDirectory
(using FileManager
).
3b. Open it in Finder and navigate back to "Containers folder".
3c. Navigate to Shared/AppGroup.
3d. You're looking for Shared/AppGroup/some_hashFolder/File Provider Storage/your_folder.
3e. Either look for modified date (folder created) of search for the folder name.
Upvotes: 80
Reputation: 2930
Simple answer:
Side note: I was working on an app that had the file association, but did not save the file. So I deleted my app from the simulator, copied the file into the Files app, then restored my app to the simulator. Mention in case it helps others.
@Palli Kominak gave this answer but left it in a comment under one of the other answers.
Upvotes: 4
Reputation: 1489
updated answer:
since xcode11/sdk13 dragging files over the simulator does not work for whatever reason. you can send media files (jpg, png, mov, etc) via terminal with xcrun simctl addmedia <device> <path>
.
therefore, this command will add an image right into Photos app with no questions asked:
xcrun simctl addmedia booted pic.001.jpg <== booted is the current running simulator.
in my case, i wanted to send root certificates to allow connecting to local servers, which doesnt work with addmedia
. the solution was to force the simulator to navigate to the full macOS local path to the .cer file with safari
xcrun simctl openurl booted 'file:///Users/my.user/Desktop/my.cer'
as it turns out, launching safari and typing file:///Users/my.user/Desktop/my.cer
in the address bar will also work. use this for pdfs and other types.
original answer:
On XCode 9 simulator, if it's an image/video, simply drag it over the simulator. It adds it to the Photos app. Other types of files seem to randomly open the file browser and generally fail. :P
Upvotes: 41
Reputation: 767
Use safari on your simulator
Vist https://en.unesco.org/inclusivepolicylab/sites/default/files/dummy-pdf_2.pdf
for a dummy pdf
Upvotes: 11
Reputation: 1925
Dragging and dropping a file from Filer onto the simulator has an issue with macOS Catalina (I am currently on 10.15.5 and seeing it). Apparently, if the source file is in a "restricted" directory (such as Downloads), it won't transfer.
Put the file in your $HOME directory and then drag it (or use Share button to share to simulator). See thread: https://forums.developer.apple.com/thread/126307
Upvotes: 11
Reputation: 1159
Maybe I am a bit late but after reading all complex answers, here's the simple and quick solution. Since you are using simulator and you want to access some of the files/images via simulator, follow these steps,
Simple, now use it just like it acts on real device.
Upvotes: 3
Reputation: 357
Multiple steps but works
1) Create a new project Document Based app and run it on the same simulator.
2) Now open safari in simulator and google for pdf. Select save to files option from action sheet and then select you newly created app folder.
Upvotes: 11
Reputation: 927
The easiest solution can be found here: https://apple.stackexchange.com/a/299565/140768
Short summary: You need an application which is able to handle/store "documents". As suggested in the linked post just create an empty "Document based" app and run it once.
Upvotes: 23
Reputation: 1158
You can browse to Library/Developer/CoreSimulator/Devices/Your App ID/data
This is basically your phone's storage. You can copy the files to any of the location you like and it will appear in your simulator.
Upvotes: -1
Reputation: 58029
You can upload files to iCloud Drive of the account you are logged in with on the simulator, and access them by navigating to Browse/iCloud Drive inside the Files app or a file upload dialog.
Upvotes: 14