I'm currently working on the simulator. I'd like to save an UIImage to a jpg file, on my desktop.
It seems that I have a problems with paths or something.
Thank you for your help :)
To run your app in Simulator, choose an iOS simulator—for example, iPhone 6 Plus, iPad Air, or iPhone 6 + Apple Watch - 38mm—from the Xcode scheme pop-up menu, and click Run. Xcode builds your project and then launches the most recent version of your app running in Simulator on your Mac screen, as shown in Figure 1-1.
Simulating Different iOS DevicesOpen the iOS simulator, if it's not already open. From the Hardware menu, select Device, and then select the type of device you want to simulate. The simulator window will change to match the dimensions of the device you selected.
It's neither a Virtual Machine nor an Emulator. It's a simulator, in another words it's a standard mac application which mimic the behaviour of iOS devices. It mimics most of the features of an actual devices, but lacks some major features. So you need to use a real device for testing some of the real world scenarios.
The following should get you started... myImage
is an UIImage object.
NSFileManager *fileManager = [NSFileManager defaultManager];
NSData *myImageData = UIImagePNGRepresentation(myImage);
[fileManager createFileAtPath:@"/Users/Me/Desktop/myimage.png" contents:myImageData attributes:nil];
Edit: Just noticed you wanted a JPG image, you can get the NSData
representation of a JPG using UIImageJPEGRepresentation()
so:
NSData *myImageData = UIImageJPEGRepresentation(myImage, 1.0);
Note: This is useful for quick and dirty testing but I would suggest learning how to write to the documents directory of your app and then using Finder to find the files there. An example path to an application's document directory in the simulator is:
/Users/Me/Library/Application Support/iPhone Simulator/4.3/Applications/1E2C2C81-1ED6-4DC9-CDD0-CA73FB56501F/Documents
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With