Fix a bug with iOS, improve device orientation detection