Every September means pain for iOS developers- you need to make sure your old apps/code run on the new iOS system/Apple devices, as well as update the iOS SDK, deprecate your code, API, etc. And ready to comply with whatever requirements Apple asks for.

This bug I encountered is iOS 6.0 only, on which Game Center has portrait view only. When API is being called, it will crash on landscape only games.

Xcode will error out something about autoRotate which isn't the real cause.

People say apple fixed this bug for later version of iOS 6.

The workaround I came up, is to support Portrait view in UIWindow, but disable it in the rootViewController by setting up the landscape mask.

In order to access a UIApplication, we need to do it from UIApplicationDelegate, the delegate class has a UIWindow, and the UIWindow has a rootViewController (after iOS 4.0), and you can add your UIView as subview to rootViewController.

(This is quite normal for any 2D based display system, you will need to have a display container hierarchy anyway.)

Everything works fine, problem seems to solved...

However, google mobile ad sdk interstitial triggered this rotation malfunction. Some interstitials have both landscape view and portrait view, even though the interstitial starts with the current orientation, if you rotate the screen to portrait view, the interstitial will automatically rotate to portait view. Because portrait view is possible in UIWindow.

Now when you close the ad, the game mistakely got rotated, even tho the rootViewController only has landscape views.

For some reason interstitials are added to UIWindow directly, instead of being added to rootViewController like banners are. Part of the reason might be that Google Mob Ad Sdk interstitial class is not derived from UIViewController, it derives directly from NSObjects. So I've tried to add the InterstialViewController directly to rootViewController and presentViewController, now the interstitial is cut off and only shows up 1/3 of the screen. In another trial, the UI input is disabled. After all, both ways ended up with the interstitial being rotatable, which causes the game play to rotate.

Some people suggest use UINavigationController and set those rotation related functions. It wouldn't work because this app is really really really f**king old, it isn't even using Storyboard at all. Tried to change class declaration for rootViewController or interstialViewController, no luck.

What makes it even harder to debug is, if this is a native or modern iOS app, i could do everything in the project, adding flag checks. But this app is using our internal framework, AppDelegate is a static libarary class, otherwise i could add a game center flag check directly and control the supportedOrientation for window accordingly.

Plus, certain functions, for example the accelerometer and rotation function made by the framwork group seems to be working in parallel with the iOS system level function, but they are out of sync, the core functions cannot detect the portrait orientation, it simply ignores it!

So after digging out more stackoverflow posts, people mentioned using setOrientation, or manually change the rotation. This is an unofficial/non-public interface. We cannot depend everything on iOS itself. So my final solution for this is: in willDissmissInterstitial function, manually rotate the window 90 degree secretly.  This works fine, nobody knows until i tell them.  (btw, if you put it in didDismiss function, you will notice a glitch)

iOS Orientation bug的更多相关文章

  1. 讲述Sagit.Framework解决:双向引用导致的IOS内存泄漏(中)- IOS不为人知的Bug

    前言: 话说昨晚还是前晚,写了一篇:讲述Sagit.Framework解决:双向引用导致的IOS内存泄漏(上) 文章写到最后时,多了很多莫名奇妙的问题!!! 为了解决了这些莫名奇妙的问题,我又战斗了2 ...

  2. iOS Orientation获取

    [iOS Orientation获取] 1.[[UIDevice sharedInstance] orientation] 必须调用beginGeneratingDeviceOrientationNo ...

  3. IOS Orientation, 想怎么转就怎么转~~~

    此博文主要针对IOS应用, 是屏幕旋转相关问题的一个总结. 主要内容有: IOS5,6,7不同版的适配. 强制旋转和自动旋转. 博客: http://www.cnblogs.com/jhzhu 邮箱: ...

  4. iOS 证书Bug The identity used to sign the executable is no longer valid 解决方案

    现象:The identity used to sign the executable is no longer valid Please verify that your device’s cloc ...

  5. ios 刷新BUG

    UItextView edited = yes  ; 导致 刷新奇怪: 有些方法不要自己调用: 可能会破坏组件自己的生命周期: 建议模块化开发组件,自己处理自己的事:

  6. ios模拟器bug

    Error: xcode-select: error: tool 'xcodebuild' requires Xcode, but active developer directory '/Libra ...

  7. iOS开发-Bug锦囊

    duplicate symbols for architecture armv7 今天修改了自己项目的部分代码,发现XCode编译的时候报错:duplicate symbols for archite ...

  8. ios问题bug收录——1

     **[2713:59682] *** Assertion failure in -[MBProgressHUD show:], /Users/lu/Desktop/****/Pods/MBProgr ...

  9. VUE: 移动端长按弹出确认删除地址(后面测试发现IOS有BUG,后面有更新随笔,更新后的亲测有效)

    收货地址的删除方式可能有很多种,我目前见过的暂时只有两种(1.在编辑页删除  2.长按某一条收货地址弹出是否删除地址) 在开发的项目上要求第二种删除方法,于是记录一下我写的代码 ~ 1.首先,在移动端 ...

随机推荐

  1. recovery编译问题汇总

    1.修改支持USB大容量存储 (1).首先需要查看手机lun位置 手机链接电脑,打开cmd命令行,依次输入以下命令: adb shell find /sys -name "lun" ...

  2. HTML 之 head

    使用 base 标签使页面中的所有标签在新窗口中打开.<!DOCTYPE html> <html> <head> <meta http-equiv=" ...

  3. 转载:CDH5.X完全卸载步骤

    http://blog.csdn.net/wulantian/article/details/42706777 //CDH5.X完全卸载步骤 # by coco # 2015-01-14   1. 关 ...

  4. JS 4 新特性:混合属性(mixins)

    Ext JS4的新特征1:混合属性(mixins) 组合是Extjs4的新特性,可用于实现多继承的情况.该属性会以同步方式加载类文件,并实例化该类(译者推理其内部使用Ext.create方法).直接上 ...

  5. python时间时分秒与秒数的互相转换

    受到Unix时间戳的启发,我发现时间转成秒数后会非常好处理,在程序当中不再是以字符串的形式处理,不管时间的加减还是获取随机的时间点都变得非常方便, 如果有需要,也很容易转换成需要的时间格式. 一:时间 ...

  6. 解决PyScripter中文乱码问题

    环境: PyScripter 2.6.0.0 python3.4 问题: PyScripter有个小坑,打开文件后中文都成了乱码.在PyScripter中新建的文件中文可以正常显示,但是重新打开后中文 ...

  7. [Python Fabric] [SSH] Mac OS X 10.9 + Vagrant虚拟环境使用Python Fabric进行SSH远程登录的简单实验

    1. ssh客户端生成key $ Generating public/private rsa key pair. Enter file in which to save the key (/Users ...

  8. firefox vimperator插件

    firefox vimperator插件实在是强大,最喜欢的几个功能做个笔记. 如何复制网页上的文字:c进入caret模式,定位cursor到要复制的开始位置--v进入visual模式,用hjkl键选 ...

  9. C#窗体无法接受Keydown事件

    问题一描述:当新建一个窗体时,添加KeyDown事件后,会正常处理,但是当添加有控件时,比如Button,TextBox,不会触发窗体的KeyDown事件,也没有调用KeyDown事件的处理程序. 原 ...

  10. Install and set JAVA home on MAC OS with commandline

    最近需要在MAC上做一些测试,由于测试机没有安装Java,只能自己安装,由于不能通过图形化界面访问测试机,只能通过命令行的形式来安装JAVA. 1. Download the jre/jdk inst ...