iOS 十、Xcode 8 遇到部分问题解决记录

 

今天把iphone 6 升级到ios10 后,用Xcode 7进行真机调试的时候提示:html

Could not find Developer Disk Imageios

果断准备升级到Xcode 8 。可是想保留Xcode 7,解决方法:sql

一、打开Finder,进入“应用程序”文件夹,新建一个文件夹命名为“Xcode 7”。

二、将原来的Xcode7程序拖进刚才建立的文件夹。

三、安装Xcode8以前,首先要把系统升级到10.11.6

四、接下来安装Xcode8。为方便之后升级,把Xcode8直接安装在“应用程序”文件夹内。或者直接经过AppStore下载安装。

五、至此,安装完成。打开Launchpad,能够见到有两个Xcode,且都能正常打开。

六、打开xcodeproj文件时,系统会默认使用Xcode8


升级之后出现的各类问题记录以下:

一、升级到Xcode8 后,真机调试,原来的描述文件出问题了(一堆问题,可能每一个人的问题不同,我就不列举了,反正就是有关描述文件的问题)

发现:Deprecated (以下)

 

而后:Target -  General - 勾选 Xcode8 新增的Automatically manage signing ,xcode

进行team选择等app

后面:Target -  BuildSeting 就能够以下配置:iphone

经过打包测试,彻底没有问题。ide

2. Xcode8 在 Target -  General下有个Signing ,  Xcode新增的Automatically manage signing会自动管理须要的配置文件和证书。咱们只须要在Xcode的Account中登陆咱们的AppleID帐号便可,配置证书变得如此简单.测试

Provisioning Profile 文件选取,已经从Buiid Settings移动到了General中,Buiid Settings中已经标识了 Deprecated(说白了,能够不用弄了),之前添加设备以后须要从新生成描述文件,而后下载安装,很麻烦,如今省事多了。ui

固然你也能够选择手动管理配置文件,除此以外,若是签名证书有任何问题Xcode都会及时提示你.this

三、一切都配置好了之后,真机调试的时候仍是出现如下问题:

The certificate used to sign "你的项目名称" has either expired or has been revoked. An updated certificate is required to sign and install the application.

检查一下,没有问题啊,可是就是报这个错误。

解决:

原来测试证书的p12文件安装了好几回,上次的已经失效,影响了真机调试。在钥匙窜中找到那些失效的证书删掉便可。只留一个有效的证书。

 

四、升级到Xcode8(ios 10),发如今注册remote notification的,获取device token的时候失败了,错误信息为:

no valid 'aps-environment' entitlement string found for application

原来在Xcode7中,push notifications开关只有一个步骤:将push notifications加入到app id。


 

可是Xcode8中,打开push notifications开关有两个步骤:
多了一步写entitlements文件的步骤


 

因此,用Xcode8打开工程后,应该从新打开一次push notification开关,以后entitlements文件中会多出两行:

<key>aps-environment</key> <string>development</string>

有了这两行以后,才能够正常注册device token。

使用:codesign --display --entitlements :- ./myApp.app

命令,能够看到app文件内的entitlement。

经发现:若是用production证书签名,能够看到:

<key>aps-environment</key> <string>production</string>

说明苹果在签名过程当中,会自动更新aps-environment字段。

五、IDFA可被用户禁用

iOS10中,用户能够在设置-隐私-广告-限制广告追踪中禁止app读取IDFA,这时app读取到的IDFA就是一串0。

官方文档中这样说:

In iOS 10.0 and later, the value of advertisingIdentifier is all zeroes when the user has limited ad tracking.

 

六、Info.plist增长权限字段

使用Xcode8构建的app,在使用相册等系统权限时会崩溃。错误信息为:

This app has crashed because it attempted to access privacy-sensitive data without a usage description. The app's Info.plist must contain an NSPhotoLibraryUsageDescription key with a string value explaining to the user how the app uses this data.

官方文档中解释:

Important: To protect user privacy, an iOS app linked on or after iOS 10.0, and which accesses the user’s photo library, must statically declare the intent to do so. Include the NSPhotoLibraryUsageDescription key in your app’s Info.plist file and provide a purpose string for this key. If your app attempts to access the user’s photo library without a corresponding purpose string, your app exits. 必须在Info.plist文件中增长NSPhotoLibraryUsageDescription键,而且填入合适的描述文本

还有不少其余的权限,如相机等,也须要在Info.plist文件中声明,具体可参考官方文档。

有一个坑就是,若是string的值为空,这行权限的声明就会无效,遇到的时候仍是崩溃:

<key>NSPhotoLibraryUsageDescription</key> <string></string>

七、UITableView、UICollectionView生命周期适配

WWDC介绍了UITableViewUICollectionView的生命周期在iOS10中发生了改变。

在iOS9及以前,一个UICollectionViewCell被重用的过程是这样的:

  • 一个cell即将出现的屏幕上
  • prepareForReuse
  • cellForItemAtIndexPath
  • willDisplayCell
  • ……
  • 一个cell彻底离开屏幕
  • didEndDisplayCell
  • 进入reuse queue

但在iOS10中,一个UICollectionViewCell被重用的过程变成了这样:

  • 一个cell还没出如今屏幕上
  • prepareForReuse
  • cellForItemAtIndexPath
  • 一个cell即将出现的屏幕上
  • ……
  • 一个cell彻底离开屏幕
  • didEndDisplayCell
  • 一段时间后再进入reuse queue

因此,iOS10后,cellForItemAtIndexPath被调用时,并不表示这个cell即将要出如今了屏幕上。仍是得老老实实使用willDisplayCelldidEndDisplayCell方法。

参考文章:http://www.jianshu.com/p/90680a4f5143
相关文章
相关标签/搜索