iOS 10、Xcode 8 遇到部分問題解決記錄(包括控制台日志不輸出)


 

今天把iphone 6 升級到ios10 后,用Xcode 7進行真機調試的時候提示:

Could not find Developer Disk Image

果斷准備升級到Xcode 8 。但是想保留Xcode 7,解決方法:

1、打開Finder,進入“應用程序”文件夾,新建一個文件夾命名為“Xcode 7”。

2、將原來的Xcode7程序拖進剛才創建的文件夾。

3、安裝Xcode8之前,首先要把系統升級到10.11.6

4、接下來安裝Xcode8。為方便以后升級,把Xcode8直接安裝在“應用程序”文件夾內。或者直接通過AppStore下載安裝。

5、至此,安裝完成。打開Launchpad,可以見到有兩個Xcode,且都能正常打開。

6、打開xcodeproj文件時,系統會默認使用Xcode8


升級以后出現的各種問題記錄如下:

1、升級到Xcode8 后,真機調試,原來的描述文件出問題了(一堆問題,可能每個人的問題不一樣,我就不列舉了,反正就是有關描述文件的問題)

發現:Deprecated (如下)

 

然后:Target -  General - 勾選 Xcode8 新增的Automatically manage signing ,

進行team選擇等

后面:Target -  BuildSeting 就可以如下配置:

通過打包測試,完全沒有問題。

2. Xcode8 在 Target -  General下有個Signing ,  Xcode新增的Automatically manage signing會自動管理需要的配置文件和證書。我們只需要在Xcode的Account中登錄我們的AppleID賬號即可,配置證書變得如此簡單.

Provisioning Profile 文件選取,已經從Buiid Settings移動到了General中,Buiid Settings中已經標識了 Deprecated(說白了,可以不用弄了),以前添加設備之后需要重新生成描述文件,然后下載安裝,很麻煩,現在省事多了。

當然你也可以選擇手動管理配置文件,除此之外,如果簽名證書有任何問題Xcode都會及時提示你.

3、一切都配置好了以后,真機調試的時候還是出現以下問題:

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

檢查一下,沒有問題啊,但是就是報這個錯誤。

解決:

原來測試證書的p12文件安裝了好幾次,上次的已經失效,影響了真機調試。在鑰匙竄中找到那些失效的證書刪掉即可。只留一個有效的證書。

 

4、升級到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字段。

5、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.

 

6、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>

7、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方法。

8、控制台日志不打印問題設置

 Edit Scheme -> Run -> Arguments, 在Environment Variables里邊添加 OS_ACTIVITY_MODE =disable 添加完后並選中,控制台打印日志不輸出。同時取消后,日志打印輸出。

參考文章:http://www.jianshu.com/p/90680a4f5143


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM