项目适配iOS9遇到的一些问题及解决办法(更新两个小问题)

 项目适配iOS9遇到的一些问题及解决办法(更新两个小问题)


Collection/Bookmark/Share for width under 768px

1.网络请求报错。

升级Xcode 7.0发现网络访问失败。

输出错误信息

The resource could not be loaded because the App Transport Security policy requires the use of a secure connection.

原因:iOS9引入了新特性App Transport Security (ATS)

详情:App Transport Security (ATS)

新特性要求App内访问的网络必须使用HTTPS协议。

但是现在公司的项目使用的是HTTP协议,使用私有加密方式保证数据安全。现在也不能马上改成HTTPS协议传输。

最终找到以下解决办法:

在Info.plist中添加NSAppTransportSecurity类型Dictionary

NSAppTransportSecurity下添加NSAllowsArbitraryLoads类型Boolean,值设为YES


2.Scheme白名单问题(无法判断手机是否安装微信等)

-canOpenURL: failed for URL: "weixin://app/wxdaae92a9cfe5d54c/" - error: "This app is not allowed to query for scheme weixin"

搜索后得知

近期苹果公司iOS 9系统策略更新,限制了http协议的访问,此外应用需要在“Info.plist”中将要使用的URL Schemes列为白名单,才可正常检查其他应用是否安装。

受此影响,当你的应用在iOS 9中需要使用微信SDK的相关能力(分享、收藏、支付、登录等)时,需要在“Info.plist”里增加如下代码:


注意:截图来自微信开放平台,里面已经包含第一个问题的解决

完成后需使用Xcode 7编译。

如果你在模拟器上运行可以能还会有以下报错:

-canOpenURL: failed for URL: "weixin://app/wxdaae92a9cfe5d54c/" - error: "(null)"

这是因为模拟器上并没有安装微信,如果运行到真机上就不会有报错了。

请注意:未升级到微信客户端6.2.5及以上版本的用户,在iOS 9下使用到微信相关功能时,仍可能无法成功。

下面整理一些常用的白名单

<key>LSApplicationQueriesSchemes</key>

<array>

    <string>mqqOpensdkSSoLogin</string>

    <string>mqzone</string>

    <string>sinaweibo</string>

    <string>alipayauth</string>

    <string>alipay</string>

    <string>safepay</string>

    <string>mqq</string>

    <string>mqqapi</string>

    <string>mqqopensdkapiV3</string>

    <string>mqqopensdkapiV2</string>

    <string>mqqapiwallet</string>

    <string>mqqwpa</string>

    <string>mqqbrowser</string>

    <string>wtloginmqq2</string>

    <string>weixin</string>

    <string>wechat</string>

</array>

qq登录绑定,qq支付,qq分享

微信支付,微信登录绑定

新浪登录绑定

支付宝支付,支付宝登录绑定


3.Bitcode问题(通俗解释:在线版安卓ART模式)

报错如下

ld: warning: directory not found for option '-F/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS9.0.sdk/Developer/Library/Frameworks'

ld: -bundle and -bitcode_bundle (Xcode setting ENABLE_BITCODE=YES) cannot be used together

clang: error: linker command failed with exit code 1 (use -v to see invocation)


Bitcode报错

原因:Xcode7 及以上版本会默认开启 bitcode 。

bitcode具体是什么就不解释了。

解决方法:

1.更新library使包含Bitcode,否则会出现以上的警告。

2.关闭Bitcode,简单粗暴。

Build Settings”->”Enable Bitcode”改成"NO"。


4.项目运行报错如下

<Error>: CGContextSaveGState: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.

<Error>: CGContextTranslateCTM: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.

<Error>: CGContextRestoreGState: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.

出错原因:设置app的状态栏样式的使用使用了旧的方式,在info.plist里面设置了View controller-based status bar appearance为NO,默认为YES,一般式iOS6的时候使用这种方式,iOS7,8也兼容,但是到了iOS9就报了警告。

[[UIApplication sharedApplication]setStatusBarStyle:UIStatusBarStyleLightContent];

以前我们通过上面代码改变状态了颜色,iOS9以后点进去看api发现如下说明

// Setting the statusBarStyle does nothing if your application is using the default UIViewController-based status bar system.

@property(readwrite, nonatomic) UIStatusBarStyle statusBarStyle NS_DEPRECATED_IOS(2_0, 9_0, "Use -[UIViewController preferredStatusBarStyle]");

- (void)setStatusBarStyle:(UIStatusBarStyle)statusBarStyle animated:(BOOL)animated NS_DEPRECATED_IOS(2_0, 9_0, "Use -[UIViewController preferredStatusBarStyle]");

解决办法:

修改方式将View controller-based status bar appearance设置为YES,然后使用新的方式来实现状态栏的样式。

- (UIStatusBarStyle)preferredStatusBarStyle;

- (UIViewController *)childViewControllerForStatusBarStyle;

- (void)setNeedsStatusBarAppearanceUpdate

2015.09.21更新

5 directory not found for option问题

警告如下:

ld: warning: directory not found for option '-F/Applications/Xcode 7.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator9.0.sdk/Developer/Library/Frameworks'

问题原因:Xcode7将framworks位置改变了。

解决方法:

点击项目,选择 Targets->xxxTests

选择build setting ,找到 Frameworks Search Path 或者 Library Search Paths

删除$(SDKROOT)/Developer/Library/Frameworks,

或者使用$(PLATFORM_DIR)/Developer/Library/Frameworks替换


framworks位置改变


暂时就这些,还有其他问题会继续更新

如果你们还有其他问题请参考:https://github.com/ChenYilong/iOS9AdaptationTips

further readings

推荐拓展阅读


abuse report

举报文章

Reward / Support Author

如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!

¥ 打赏支持 

article meta bottom

Like Button

喜欢

100

share group

分享到微博 分享到微信 更多分享

Modals

×

喜欢的用户

Comments

16条评论 ( 按时间正序· 按时间倒序· 按喜欢排序

添加新评论


蓝夜

3 楼 · 2015.09.19 18:20

iOS9.适配,及时

喜欢(0)

回复


Littledogboy

4 楼 · 2015.09.20 02:30

支持

喜欢(0)

回复


beadecb13cf9

5 楼 · 2015.09.20 07:35

实用性强

喜欢(0)

回复


尘间

6 楼 · 2015.09.20 22:30

都遇到了

喜欢(0)

回复


什么是心

7 楼 · 2015.09.21 08:50

我使用了Masonry, 适配ios9 一直崩溃

喜欢(0)

回复

David_Cap@什么是心 请问怎么解决呢,我也遇到了。

回复

2015.09.21 09:02

勤奋的笨老头: 我项目中没用到Masonry,我也不知道原因,网上搜搜看,或者去Masonry官网看看

回复

2015.09.21 09:25

什么是心@David_Cap iOS9 使用Masonry 崩溃的问题找到了 

一直以为leading就是left 在ios8上正常 在ios9上崩溃语句如下

make.left.equalTo(self.mas_leading).offset(15);

修改后是

make.left.equalTo(self.mas_left).offset(15);


同理 mas_training 也需要改为right

回复

2015.09.21 15:45


添加新回复


纷纷扰扰

8 楼 · 2015.09.21 20:45

很棒

喜欢(1)

回复


一听情话就哽咽

9 楼 · 2015.09.24 11:58

一些第三方库会报错~, 比如JSONKit~ 等~

喜欢(0)

回复

一听情话就哽咽@一听情话就哽咽 我用的是http://github.com/johnezang/JSONKit这个没有报错~,同事用的别的,更新xcode7之后报错~

回复

2015.09.24 11:59


添加新回复


弗丁老爹

10 楼 · 2015.09.25 16:25

项目建了两个taget,新建的那个怎么弄就是没有启动图,已经检查了启动图等的target包含关系,都没问题。xcode7打包就没启动图,xcode6打包就有。

喜欢(0)

回复


llb

11 楼 · 2015.09.28 17:50

@勤奋的笨老头 请问这个问题<Error>: CGContextSaveGState: invalid context 0x0.

是必须修改吗?还是仅仅是一个警告不需要关心?

喜欢(0)

回复


llb

12 楼 · 2015.09.28 17:58

@勤奋的笨老头 这个测试同学在iOS9上偶现一个问题:启动类似“黑屏”。重启不行,卸载重装才好。控制台的log输出<Error>: CGContextSaveGState: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable. 不知道你说这个问题是不是有这个“黑屏”的现象。

喜欢(0)

回复


NeroLee

13 楼 · 2015.10.01 10:32

-canOpenURL: failed for URL: "(白名单)://(xxxxxx)" - error: "(null)"


其他同理将白名单这部分添加进去就好了


喜欢(0)

回复

⌘+Return 发表

被以下专题收入,发现更多相似内容:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值