Failed to get orientaion from appiumDriver.getOrientation() on iOS 9

Hi All,

I’m trying to execute a piece of code in java for appium,
it fails to get proper orientation in switch:

public static void rotate() {
    switch (appium_driver.getOrientation()) {
        case PORTRAIT:
            appium_driver.rotate(ScreenOrientation.LANDSCAPE);
            break;
        case LANDSCAPE:
            appium_driver.rotate(ScreenOrientation.PORTRAIT);
            break;
        default:
            logInfo("Unknown orientation: "+appium_driver.getOrientation());
    }
}

I’m using appium server 1.4.16 and java-client 3.3.0
On iOS 8, real device iPhone 5s I get correct orientation values (LANDSCAPE or PORTRAIT)

However on iOS 9.1, iPhone 6 plus I get following error from console:

org.openqa.selenium.WebDriverException: Unexpected orientation returned: unknown
Build info: version: ‘2.48.2’, revision: ‘41bccdd10cf2c0560f637404c2d96164b67d9d67’, time: ‘2015-10-09 13:08:06’
System info: host: ‘Backup-MacBook-Pro.local’, ip: ‘10.48.1.236’, os.name: ‘Mac OS X’, os.arch: ‘x86_64’, os.version: ‘10.11.1’, java.version: ‘1.7.0_80’
Driver info: driver.version: AppiumDriver

And in my server logs there is following:

2016-02-04 15:21:17:664 - info: [debug] Responding to client with success: {“status”:0,“value”:[{“ELEMENT”:“4”}],“sessionId”:“ac882f29-91f5-4e4b-8726-967105a67a00”}
2016-02-04 15:21:17:665 - info: <-- POST /wd/hub/session/ac882f29-91f5-4e4b-8726-967105a67a00/elements 200 4390.614 ms - 89 {“status”:0,“value”:[{“ELEMENT”:“4”}],“sessionId”:“ac882f29-91f5-4e4b-8726-967105a67a00”}
2016-02-04 15:21:17:676 - info: --> GET /wd/hub/session/ac882f29-91f5-4e4b-8726-967105a67a00/orientation {}
2016-02-04 15:21:17:677 - info: [debug] Pushing command to appium work queue: “au.getScreenOrientation()”
2016-02-04 15:21:17:677 - info: [debug] Sending command to instruments: au.getScreenOrientation()
2016-02-04 15:21:18:574 - info: [debug] [INST] 2016-02-04 15:21:30 +0000 Debug: Got new command 19 from instruments: au.getScreenOrientation()
2016-02-04 15:21:18:587 - info: [debug] [INST] 2016-02-04 15:21:30 +0000 Debug: evaluating au.getScreenOrientation()
2016-02-04 15:21:18:599 - info: [debug] [INST] 2016-02-04 15:21:30 +0000 Debug: evaluation finished
2016-02-04 15:21:18:610 - info: [debug] [INST] 2016-02-04 15:21:30 +0000 Debug: responding with:
2016-02-04 15:21:18:626 - info: [debug] [INST] 2016-02-04 15:21:30 +0000 Debug: Running system command #20: /usr/local/Cellar/node/5.1.0/bin/node /usr/local/lib/node_modules/appium/node_modules/appium-uiauto/bin/command-proxy-client.js /tmp/instruments_sock 2,{“status”:0,“value”:“UNKNOWN”}…
2016-02-04 15:21:18:762 - info: [debug] Socket data received (32 bytes)
2016-02-04 15:21:18:765 - info: [debug] Socket data being routed.
2016-02-04 15:21:18:766 - info: [debug] Got result from instruments: {“status”:0,“value”:“UNKNOWN”}
2016-02-04 15:21:18:767 - info: [debug] Setting internal orientation to UNKNOWN
2016-02-04 15:21:18:767 - info: [debug] Responding to client with success: {“status”:0,“value”:“UNKNOWN”,“sessionId”:“ac882f29-91f5-4e4b-8726-967105a67a00”}
2016-02-04 15:21:18:768 - info: <-- GET /wd/hub/session/ac882f29-91f5-4e4b-8726-967105a67a00/orientation 200 1092.680 ms - 81 {“status”:0,“value”:“UNKNOWN”,“sessionId”:“ac882f29-91f5-4e4b-8726-967105a67a00”}
2016-02-04 15:21:18:787 - info: --> GET /wd/hub/session/ac882f29-91f5-4e4b-8726-967105a67a00/screenshot {}
2016-02-04 15:21:18:789 - info: [debug] Pushing command to appium work queue: “au.getScreenOrientation()”
2016-02-04 15:21:18:790 - info: [debug] Sending command to instruments: au.getScreenOrientation()
2016-02-04 15:21:19:539 - info: [debug] [INST] 2016-02-04 15:21:31 +0000 Debug: Got new command 20 from instruments: au.getScreenOrientation()
2016-02-04 15:21:19:552 - info: [debug] [INST] 2016-02-04 15:21:31 +0000 Debug: evaluating au.getScreenOrientation()
2016-02-04 15:21:19:563 - info: [debug] [INST] 2016-02-04 15:21:31 +0000 Debug: evaluation finished
2016-02-04 15:21:19:574 - info: [debug] [INST] 2016-02-04 15:21:31 +0000 Debug: responding with:
2016-02-04 15:21:19:590 - info: [debug] [INST] 2016-02-04 15:21:32 +0000 Debug: Running system command #21: /usr/local/Cellar/node/5.1.0/bin/node /usr/local/lib/node_modules/appium/node_modules/appium-uiauto/bin/command-proxy-client.js /tmp/instruments_sock 2,{“status”:0,“value”:“UNKNOWN”}…
2016-02-04 15:21:19:706 - info: [debug] Socket data received (32 bytes)
2016-02-04 15:21:19:707 - info: [debug] Socket data being routed.
2016-02-04 15:21:19:708 - info: [debug] Got result from instruments: {“status”:0,“value”:“UNKNOWN”}
2016-02-04 15:21:19:708 - info: [debug] Setting internal orientation to UNKNOWN
2016-02-04 15:21:19:708 - info: [debug] Pushing command to appium work queue: “au.capture(‘screenshot1a46ac4f-a39e-4891-92ec-ff8ca2aef24d’)”
2016-02-04 15:21:19:709 - info: [debug] Sending command to instruments: au.capture(‘screenshot1a46ac4f-a39e-4891-92ec-ff8ca2aef24d’)
2016-02-04 15:21:20:640 - info: [debug] [INST] 2016-02-04 15:21:33 +0000 Debug: Got new command 21 from instruments: au.capture(‘screenshot1a46ac4f-a39e-4891-92ec-ff8ca2aef24d’)
2016-02-04 15:21:20:652 - info: [debug] [INST] 2016-02-04 15:21:33 +0000 Debug: evaluating au.capture(‘screenshot1a46ac4f-a39e-4891-92ec-ff8ca2aef24d’)
2016-02-04 15:21:20:666 - info: [debug] [INST] 2016-02-04 15:21:33 +0000 Debug: target.captureRectOnScreenWithName("{origin:{x:0.00,y:0.00}, size:{height:736.00,width:414.00}}", UIScreen, “screenshot1a46ac4f-a39e-4891-92ec-ff8ca2aef24d”)
2016-02-04 15:21:21:106 - info: [debug] Socket data received (25 bytes)
2016-02-04 15:21:21:108 - info: [debug] Socket data being routed.
2016-02-04 15:21:21:108 - info: [debug] Got result from instruments: {“status”:0,“value”:""}
2016-02-04 15:21:21:109 - info: [debug] Waiting 10000 ms for screenshot to ge generated.
2016-02-04 15:21:31:113 - info: [debug] Pushing command to appium work queue: “au.getScreenOrientation()”
2016-02-04 15:21:31:114 - info: [debug] Sending command to instruments: au.getScreenOrientation()
2016-02-04 15:21:31:655 - info: [debug] [INST] 2016-02-04 15:21:33 +0000 Screenshot captured.
2016-02-04 15:21:31:670 - info: [debug] [INST] 2016-02-04 15:21:33 +0000 Debug: evaluation finished
2016-02-04 15:21:31:681 - info: [debug] [INST] 2016-02-04 15:21:33 +0000 Debug: responding with:
2016-02-04 15:21:31:693 - info: [debug] [INST] 2016-02-04 15:21:33 +0000 Debug: Running system command #22: /usr/local/Cellar/node/5.1.0/bin/node /usr/local/lib/node_modules/appium/node_modules/appium-uiauto/bin/command-proxy-client.js /tmp/instruments_sock 2,{“status”:0,“value”:""}…
2016-02-04 15:21:31:943 - info: [debug] [INST] 2016-02-04 15:21:44 +0000 Debug: Got new command 22 from instruments: au.getScreenOrientation()
2016-02-04 15:21:31:957 - info: [debug] [INST] 2016-02-04 15:21:44 +0000 Debug: evaluating au.getScreenOrientation()
2016-02-04 15:21:31:971 - info: [debug] [INST] 2016-02-04 15:21:44 +0000 Debug: evaluation finished
2016-02-04 15:21:31:985 - info: [debug] [INST] 2016-02-04 15:21:44 +0000 Debug: responding with:
2016-02-04 15:21:32:117 - info: [debug] Socket data received (32 bytes)
2016-02-04 15:21:32:118 - info: [debug] Socket data being routed.
2016-02-04 15:21:32:118 - info: [debug] Got result from instruments: {“status”:0,“value”:“UNKNOWN”}
2016-02-04 15:21:32:119 - info: [debug] Setting internal orientation to UNKNOWN
2016-02-04 15:21:32:119 - info: [debug] Pushing command to appium work queue: “au.capture(‘screenshot1a46ac4f-a39e-4891-92ec-ff8ca2aef24d’)”
2016-02-04 15:21:32:119 - info: [debug] Sending command to instruments: au.capture(‘screenshot1a46ac4f-a39e-4891-92ec-ff8ca2aef24d’)
2016-02-04 15:21:32:138 - info: [debug] [INST] 2016-02-04 15:21:44 +0000 Debug: Running system command #23: /usr/local/Cellar/node/5.1.0/bin/node /usr/local/lib/node_modules/appium/node_modules/appium-uiauto/bin/command-proxy-client.js /tmp/instruments_sock 2,{“status”:0,“value”:“UNKNOWN”}…
2016-02-04 15:21:33:045 - info: [debug] [INST] 2016-02-04 15:21:45 +0000 Debug: Got new command 23 from instruments: au.capture(‘screenshot1a46ac4f-a39e-4891-92ec-ff8ca2aef24d’)
2016-02-04 15:21:33:060 - info: [debug] [INST] 2016-02-04 15:21:45 +0000 Debug: evaluating au.capture(‘screenshot1a46ac4f-a39e-4891-92ec-ff8ca2aef24d’)
2016-02-04 15:21:33:071 - info: [debug] [INST] 2016-02-04 15:21:45 +0000 Debug: target.captureRectOnScreenWithName("{origin:{x:0.00,y:0.00}, size:{height:736.00,width:414.00}}", UIScreen, “screenshot1a46ac4f-a39e-4891-92ec-ff8ca2aef24d”)
2016-02-04 15:21:33:511 - info: [debug] Socket data received (25 bytes)
2016-02-04 15:21:33:511 - info: [debug] Socket data being routed.
2016-02-04 15:21:33:512 - info: [debug] Got result from instruments: {“status”:0,“value”:""}
2016-02-04 15:21:33:513 - info: [debug] Waiting 10000 ms for screenshot to ge generated.
2016-02-04 15:21:33:826 - info: [debug] Responding to client with success: {“status”:0,“value”:“iVBORw0KGgoAAAANSUhEUgAABNoAAAigCAYAAADpkk+ZAAAAAXNSR0IArs4c6QAAQABJREFUeAHsnQW8FFX7x5+lUwRExcYOFEUQURADTMTuwg7U107szr/d9dodr4oNIhaIimArgl0YSOf+z2+us8zMzta9u/fucr/P57PszpkzZ858Zy47+5snEvPnz08aBgEIQAACEIAABCAAAQhAAAIQgAAEIAABCNSIQIMabc3GEIAABCAAAQhAAAIQgAAEIAABCEAAAhCAgEcAoY0LAQIQgAAEIAABCEAAAhCAAAQgAAEIQAACRSCA0FYEiAwBAQhAAAIQgAAEIAABCEAAAhCAAAQgAAGENq4BCEAAAhCAAAQgAAEIQAACEIAABCAAAQgUgQBCWxEgMgQEIAABCEAAAhCAAAQgAAEIQAACEIAABBDauAYgAAEIQAACEIAABCAAAQhAAAIQgAAEIFAEAghtRYDIEBCAAAQgAAEIQAACEIAABCAAAQhAAAIQQGjjGoAABCAAAQhAAAIQgAAEIAABCEAAAhCAQBEIILQVASJDQAACEIAABCAAAQhAAAIQgAAEIAABCEAAoY1rAAIQgAAEIAABCEAAAhCAAAQgAAEIQAACRSCA0FYEiAwBAQhAAAIQgAAEIAABCEAAAhCAAAQgAAGENq4BCEAAAhCAAAQgAAEIQAACEIAABCAAAQgUgQBCWxEgMgQEIAABCEAAAhCAAAQgAAEIQAACEIAABBDauAYgAAEIQAACEIAABCAAAQhAAAIQgAAEIFAEAghtRYDIEBCAAAQgAAEIQAACEIAABCAAAQhAAAKVR2DEiBFFnXSjoo7GYBAoIoG///7b3nrrLXvnnXfsyy+/tK+//tp+++03mz59uk2ePNnatGljLVq0sA4dOtgqq6xiq666qvXo0cN69+5tiy66aBFnwlAQgAAEIAABCEAAAhCAAAQgAIHaIfDcc8/ZNddcY++9955NnTq1dnZah3tp1aqV…”,“sessionId”:“ac882f29-91f5-4e4b-8726-967105a67a00”}
2016-02-04 15:21:33:902 - info: <-- GET /wd/hub/session/ac882f29-91f5-4e4b-8726-967105a67a00/screenshot 200 15117.113 ms - 2392898 {“status”:0,“value”:“iVBORw0KGgoAAAANSUhEUgAABNoAAAigCAYAAADpkk+ZAAAAAXNSR0IArs4c6QAAQABJREFUeAHsnQW8FFX7x5+lUwRExcYOFEUQURADTMTuwg7U107szr/d9dodr4oNIhaIimArgl0YSOf+z2+us8zMzta9u/fucr/P57PszpkzZ858Zy47+5snEvPnz08aBgEIQAACEIAABCAAAQhAAAIQgAAEIAABCNSIQIMabc3GEIAABCAAAQhAAAIQgAAEIAABCEAAAhCAgEcAoY0LAQIQgAAEIAABCEAAAhCAAAQgAAEIQAACRSCA0FYEiAwBAQhAAAIQgAAEIAABCEAAAhCAAAQgAAGENq4BCEAAAhCAAAQgAAEIQAACEIAABCAAAQgUgQBCWxEgMgQEIAABCEAAAhCAAAQgAAEIQAACEIAABBDauAYgAAEIQAACEIAABCAAAQhAAAIQgAAEIFAEAghtRYDIEBCAAAQgAAEIQAACEIAABCAAAQhAAAIQQGjjGoAABCAAAQhAAAIQgAAEIAABCEAAAhCAQBEIILQVASJDQAACEIAABCAAAQhAAAIQgAAEIAABCEAAoY1rAAIQgAAEIAABCEAAAhCAAAQgAAEIQAACRSCA0FYEiAwBAQhAAAIQgAAEIAABCEAAAhCAAAQgAAGENq4BCEAAAhCAAAQgAAEIQAACEIAABCAAAQgUgQBCWxEgMgQEIAABCEAAAhCAAAQgAAEIQAACEIAABBDauAYgAAEIQAACEIAABCAAAQhAAAIQgAAEIFAEAghtRYDIEBCAAAQgAAEIQAACEIAABCAAAQhAAAKVR2DEiBFFnXSjoo7GYBAoIoG///7b3nrrLXvnnXfsyy+/tK+//tp+++03mz59uk2ePNnatGljLVq0sA4dOtgqq6xiq666qvXo0cN69+5tiy66aBFnwlAQgAAEIAABCEAAAhCAAAQgAIHaIfDcc8/ZNddcY++9955NnTq1dnZah3tp1aqV…”,“sessionId”:“ac882f29-91f5-4e4b-8726-967105a67a00”}
2016-02-04 15:21:36:156 - info: --> DELETE /wd/hub/session/ac882f29-91f5-4e4b-8726-967105a67a00 {}
2016-02-04 15:21:36:160 - info: Shutting down appium session
2016-02-04 15:21:36:162 - info: [debug] Stopping ios
2016-02-04 15:21:36:164 - info: [debug] Destroying instruments client socket.
2016-02-04 15:21:36:164 - info: [debug] Closing socket server.
2016-02-04 15:21:36:166 - info: [debug] Instruments socket server was closed
2016-02-04 15:21:36:167 - info: [debug] Sending sigterm to instruments
2016-02-04 15:21:36:184 - info: [debug] [INST] 2016-02-04 15:21:36 +0000 Stopped: Script was stopped by the user
2016-02-04 15:21:36:197 - info: [debug] [INST] 2016-02-04 15:21:45 +0000 Screenshot captured.
2016-02-04 15:21:36:197 - info: [debug] [INST] 2016-02-04 15:21:45 +0000 Debug: evaluation finished
2016-02-04 15:21:45 +0000 Debug: responding with:
2016-02-04 15:21:45 +0000 Debug: Running system command #24: /usr/local/Cellar/node/5.1.0/bin/node /usr/local/lib/node_modules/appium/node_modules/appium-uiauto/bin/command-proxy-client.js /tmp/instruments_sock 2,{“status”:0,“value”:""}…
2016-02-04 15:21:36:289 - info: [debug] [INST STDERR] 2016-02-04 16:21:36.289 instruments[52108:363047] Attempting to change event horizon while disengage
2016-02-04 15:21:37:266 - info: [debug] [INST] Instruments Trace Complete (Duration : 50.985645s; Output : /tmp/appium-instruments/instrumentscli0.trace)
2016-02-04 15:21:37:289 - info: [debug] [INSTSERVER] Instruments exited with code 0
2016-02-04 15:21:37:290 - info: [debug] Cleaning up after instruments exit
2016-02-04 15:21:37:291 - info: [debug] Stopping iOS log capture
2016-02-04 15:21:37:292 - info: [debug] Running ios sim reset flow
2016-02-04 15:21:37:293 - info: [debug] Killing the simulator process
2016-02-04 15:21:37:295 - info: [debug] Killing any other simulator daemons
2016-02-04 15:21:37:307 - info: [debug] Killall Simulator
2016-02-04 15:21:37:352 - info: [debug] fullReset requested. Will try to uninstall the app.
2016-02-04 15:21:38:993 - info: [debug] Removed com.reference.stepstone
2016-02-04 15:21:38:994 - info: [debug] Cleaning up appium session
2016-02-04 15:21:38:996 - info: [debug] Responding to client with success: {“status”:0,“value”:null,“sessionId”:“ac882f29-91f5-4e4b-8726-967105a67a00”}
2016-02-04 15:21:39:001 - info: <-- DELETE /wd/hub/session/ac882f29-91f5-4e4b-8726-967105a67a00 200 2844.763 ms - 76 {“status”:0,“value”:null,“sessionId”:“ac882f29-91f5-4e4b-8726-967105a67a00”}

Any clue how to get proper orientation from this?
I’m stuck in this, please help.
Thanks!

Looks like there is a bug filed for this:

You may want to add logs/comments there.