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. 如何在脚本中获取进程ID(PID)

    我想要知道运行中脚本子shell的进程id.我该如何在shell脚本中得到PID. 当我在执行shell脚本时,它会启动一个叫子shell的进程.作为主shell的子进程,子shell将shell脚本 ...

  2. Fake chat script for website download

    Are you searching for free fake webchat script then you are at the right place go get download your ...

  3. C# 发送HttpWebRequest获得网络图片的大小、尺寸

    可以通过HttpWebRequest的方式发送一个网络图片的请求,再通过HttpWebResponse接收返回的数据,分析数据流得到图片的大小以及尺寸,代码如下: /// <summary> ...

  4. 点击document隐藏某个div

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  5. Win7 64位ORACLE取数字乱码的解决

    参见网址http://www.2cto.com/database/201304/201767.html 首先是PLSQL DEVELOPER 直接报错 NLS_LANG 错误 第一步是在命令行下测试 ...

  6. Git典型使用场景

    1. 在本地创建版本库(把本地的一个目录内的文件纳入版本库管理,方便查看变动历史,恢复版本等.不限于代码,可以是笔记等所有需要追踪历史的文件.) git init -- 把当前目录初始化为版本库 2. ...

  7. c++ 中的sort用法

    别人写的,我拿来做做笔记 sort函数的用法 做ACM题的时候,排序是一种经常要用到的操作.如果每次都自己写个冒泡之类的O(n^2)排序,不但程序容易超时,而且浪费宝贵的比赛时间,还很有可能写错.ST ...

  8. VS2010里, using System.Data.OracleClient; 不可用

    当我试图去引用System.Data.OracleClient 这个命名空间时,VS 显示不存在 但是在对象浏览器里却可以找到这个命名空间及里边的对象 另外好像也没有区分清楚 using 和Refer ...

  9. linux-rpm

    1.         RPM本地安装 RPM包管理员(简称RPM,全称为The RPM Package Manager)是在Linux下广泛使用的软件包管理器.RPM此名词可能是指.rpm的文件格式的 ...

  10. 一款公用的CSS+DIV弹窗

    为了方便以后自己使用! <html> <head> <style> .winmainshow { background: #fff; padding: 10px 5 ...