Comments (15)
There's no way to do it through the private API that's used. However, I was able to do it by editing ~/Library/Preferences/com.apple.iphonesimulator.plist and changing the value of key ‘SimulateDevice’ to ‘iPhone (Retina)’. This can be easily done programmatically, the only issue probably is that the simulator app would have to quit before it can be changed.
from ios-sim.
That's fine with me. Thanks for the tip!
from ios-sim.
If you come up with some working code, please do share :)
from ios-sim.
Ah, my case is a bit unique in that I executing iphonesim (the predecessor to this project) via the command line from a Java-based game creation toolset. Basically a previewer function, and what I wanted to do was let our users run a game in the simulator in standard, retina or ipad mode without having to go through the menu in the simulator (which resets the orientation, etc.)
What you posted up works, though I ran into some issues trying to programmatically, or even manually do this. I attempted to edit the plist file directly in a text editor (rather than the fancy interface), and any change would invalidate the file and make it unopenable. Maybe an encoding mismatch?
What I ended up doing was a terrible hack - getting the file into a state where it was in retina mode, saving that out and then copying it back to the location in when necessary. This works perfectly, so far at least.
The rest of the "magic" is just a bunch of AppleScript I also execute from the Java app that does this after the simulator is up.
- Pop up the Console app to show console output. This was before you added in the options to redirect output. But I still kinda like showing console because it's easy to see the stacktraces and so forth when things go wrong.
- Tell the console to clear itself
- Bring focus to the iPhone simulator
- Rotate the simulator for landscape games (after a small delay - doing it immediately wasn't working for me). Peeking at the same config file, it appears that I could eliminate this step through the config file too.
In short, I don't have any code that can be directly contributed back, but I do have the Java & AppleScript I'm using for this process if you'd like to see it. I'm pretty sure that the AppleScript part could be improved upon.
from ios-sim.
How did you try to do it programmatically? Reading it with +[NSMutableDictionary dictionaryWithContentsOfFile:]
, changing the key-value, and writing it back out with -[NSMutableDictionary writeToFile:atomically:]
should work in my experience.
Yes, please do share your AppleScripts, I might be able to use the rotating script in a project I'm working on :)
from ios-sim.
I'm working through Java, not Objective-C on this part. I tried two methods - a simple read in the file to a String and replacing the key if present, inserting it if not. (I noticed on printing it out even before touching it, it already was coming up slightly funny). The second method was reading it into an XML parser, which failed to even parse.
Rotating can be done in one of 2 ways. With AppleScript, you can do something like this:
tell application "System Events"
click menu item "Rotate Left" of menu "Hardware" of menu bar of process "iPhone Simulator"
end tell
As long as Apple doesn't change the menus around, this works just fine.
I can also tell that the file has an "Orientation" key with integer values for the different rotation states. That might work better than AppleScript because it already loads it up in pre-rotated form and is immune to breaking if Apple decides to change the menus around.
from ios-sim.
Interestingly, my conjecture about setting the orientation key failed. The simulator seems to always start in portrait mode, at least for me, even though the value of the orientation key changes from 1 to 3 when I rotate it. I wonder if something else is going on under the hood.
from ios-sim.
Oh, those Objective-C APIs were meant for if you were gonna add code to ios-sim :) I’ll have a look at that.
Regarding the orientation, do you simply launch the simulator app after changing the pref value? Or do you launch your app? Not sure if there's some app setting that chooses a preferred orientation, but there might be?
from ios-sim.
This is what I do with the simulator.
- I launch it via this project.
- I rotate it either manually or via AppleScript.
- I close out of the Simulator.
- I inspect the plist to confirm that the orientation value changed (to 3)
- I relaunch the app again via this project and it sticks to portrait
Doing steps 1 and 5 by invoking the actual iOS Simulator (searching via Spotlight) yields the same result - no initial rotation.
That's an interesting point about whether I could specify a preferred orientation for the app. I'll poke around and see if there is.
from ios-sim.
Setting the UIInterfaceOrientation key in the Application-Info.plist file seems to do the trick.
from ios-sim.
Ok, so the conclusion is that you can control it from the app by specifying UIInterfaceOrientation in the app's plist, but not externally? Well, besides using AppleScript.
from ios-sim.
Yep.
from ios-sim.
Thanks!
On Fri, Aug 19, 2011 at 10:01 AM, jon914
[email protected]
wrote:
Yep.
Reply to this email directly or view it on GitHub:
https://github.com/Fingertips/ios-sim/issues/10#issuecomment-1849037
from ios-sim.
Any news here? If i change the value in the plist and then start ios-sim launch App.app it resets it to "iphone".
from ios-sim.
Fixed by #34
from ios-sim.
Related Issues (20)
- No devices in cordova project HOT 10
- convert module to oclif
- complete coverage for command `install` HOT 1
- complete coverage for command `launch`
- complete coverage for command `start` HOT 1
- List empty of devices simulator with Xcode 10.2 HOT 60
- Log more information about simulator being launched
- List empty of devices simulator with Xcode 11 HOT 3
- Error: Cannot read property 'toLowerCase' of undefined
- --devicetypeid was not specified, using first available device: null. HOT 4
- Add support to non binary Info.plist files
- How to run ios-sim all command through python script
- TypeError: Cannot read property 'devicetypes' of undefined HOT 8
- Unable to install the application in simulator HOT 5
- Unhandled Error: launch.js line 51. this.log undefined. HOT 4
- Custom simulators not appearing in showdevicetypes
- BUG: `npm list` errors on this module on global mode
- Bump simctl to 2.0.1 for security updates
- remove appveyor and travis ci, use Github Actions HOT 2
- node.js 16 test failures HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ios-sim.