Giter VIP home page Giter VIP logo

Comments (15)

alloy avatar alloy commented on August 25, 2024

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.

jon914 avatar jon914 commented on August 25, 2024

That's fine with me. Thanks for the tip!

from ios-sim.

alloy avatar alloy commented on August 25, 2024

If you come up with some working code, please do share :)

from ios-sim.

jon914 avatar jon914 commented on August 25, 2024

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.

  1. 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.
  2. Tell the console to clear itself
  3. Bring focus to the iPhone simulator
  4. 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.

alloy avatar alloy commented on August 25, 2024

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.

jon914 avatar jon914 commented on August 25, 2024

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.

jon914 avatar jon914 commented on August 25, 2024

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.

alloy avatar alloy commented on August 25, 2024

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.

jon914 avatar jon914 commented on August 25, 2024

This is what I do with the simulator.

  1. I launch it via this project.
  2. I rotate it either manually or via AppleScript.
  3. I close out of the Simulator.
  4. I inspect the plist to confirm that the orientation value changed (to 3)
  5. 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.

jon914 avatar jon914 commented on August 25, 2024

Setting the UIInterfaceOrientation key in the Application-Info.plist file seems to do the trick.

from ios-sim.

alloy avatar alloy commented on August 25, 2024

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.

jon914 avatar jon914 commented on August 25, 2024

Yep.

from ios-sim.

alloy avatar alloy commented on August 25, 2024

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.

x2on avatar x2on commented on August 25, 2024

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.

shazron avatar shazron commented on August 25, 2024

Fixed by #34

from ios-sim.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.