xcode8的一些變動得一些坑!


一、證書管理

用Xcode8打開工程後,比較明顯的就是下圖了,這個是蘋果的新特性,可以幫助我們自動管理證書。建議大家勾選這個Automatically manage signing(Ps.但是在beat2版本我用的時候,完全不可以,GM版本竟然神奇的又好了。)


 下面我來說說可能會出現的問題:

1.Xcode未設置開發者賬號情況下的截圖



解決辦法是:大家在Xcode的偏好設置中,添加蘋果賬號,即可。

2.設備機器未添加進開發者的Device情況下的截圖


 

解決辦法是:大家在官網將設備添加進開發機後,陪下描述文件重新下個描述文件即可。

3.正常情況:Xcode配置登錄開發者賬號後的圖片,耐心等待即可。


 

等待完成之後的圖


 二、Xib文件的注意事項

使用Xcode8打開xib文件後,會出現下圖的提示。


 

大家選擇Choose Device即可。
之後大家會發現佈局啊,frame亂了,只需要更新一下frame即可。如下圖


  •  注意:如果按上面的步驟操作後,在用Xcode7打開Xib會報一下錯誤,

  •  解決辦法:需要刪除Xib裏面
    <code class="xml" style="margin: 0px; padding: 0px;"><<span class="hljs-title" style="margin: 0px; padding: 0px; color: rgb(163, 21, 21); line-height: 1.5;">capability <span class="hljs-attribute" style="margin: 0px; padding: 0px; line-height: 1.5;">name=<span class="hljs-value" style="margin: 0px; padding: 0px; line-height: 1.5;">"documents saved in the Xcode 8 format" <span class="hljs-attribute" style="margin: 0px; padding: 0px; line-height: 1.5;">minToolsVersion=<span class="hljs-value" style="margin: 0px; padding: 0px; line-height: 1.5;">"8.0"/></span></span></span></span></span></code>
    這句話,以及把< document >中的toolsVersion和< plugIn >中的version改成你正常的xib文件中的值
    ,不過不建議這麼做,在Xcode8出來後,希望大家都快速上手,全員更新。這就跟Xcode5到Xcode6一樣,有變動,但是還是要儘早學習,儘快適應喲!

三、代碼及Api注意

使用Xcode8之後,有些代碼可能就編譯不過去了,具體我就說說我碰到的問題。
1.UIWebView的代理方法:
**注意要刪除NSError前面的 nullable,否則報錯。

<code class="objectivec" style="margin: 0px; padding: 0px;">- (<span class="hljs-keyword" style="color: rgb(0, 0, 255); margin: 0px; padding: 0px; line-height: 1.5;">void)webView:(<span class="hljs-built_in" style="color: rgb(102, 0, 102); margin: 0px; padding: 0px; line-height: 1.5;">UIWebView *)webView didFailLoadWithError:(nullable <span class="hljs-built_in" style="margin: 0px; padding: 0px; line-height: 1.5;">NSError *)error
{
    [<span class="hljs-keyword" style="color: rgb(0, 0, 136); margin: 0px; padding: 0px; line-height: 1.5;">self hideHud];
}</span></span></span></span></code>

四、代碼註釋不能用的解決辦法

這個是因爲蘋果解決xcode ghost,把插件屏蔽了。
解決方法
打開終端,命令運行: sudo /usr/libexec/xpccachectl
然後必須重啓電腦後生效

注意:Xcode8內置了開啓註釋的功能,位置在這裏


 快捷鍵的設置在這裏

 貌似Xcode8取消了三方插件的功能,具體可以查閱下Xcode8 Source Editor

五、權限以及相關設置

注意,添加的時候,末尾不要有空格
我們需要打開info.plist文件添加相應權限的說明,否則程序在iOS10上會出現崩潰。
具體如下圖:


 麥克風權限:Privacy - Microphone Usage Description 是否允許此App使用你的麥克風?

相機權限: Privacy - Camera Usage Description 是否允許此App使用你的相機?
相冊權限: Privacy - Photo Library Usage Description 是否允許此App訪問你的媒體資料庫?通訊錄權限: Privacy - Contacts Usage Description 是否允許此App訪問你的通訊錄?
藍牙權限:Privacy - Bluetooth Peripheral Usage Description 是否許允此App使用藍牙?

語音轉文字權限:Privacy - Speech Recognition Usage Description 是否允許此App使用語音識別?
日曆權限:Privacy - Calendars Usage Description 是否允許此App使用日曆?

定位權限:Privacy - Location When In Use Usage Description 我們需要通過您的地理位置信息獲取您周邊的相關數據
定位權限: Privacy - Location Always Usage Description 我們需要通過您的地理位置信息獲取您周邊的相關數據
定位的需要這麼寫,防止上架被拒。

六、字體變大,原有frame需要適配

經有的朋友提醒,發現程序內原來2個字的寬度是24,現在2個字需要27的寬度來顯示了。。
希望有解決辦法的朋友,評論告我一下耶,謝謝啦

七、推送

如下圖的部分,不要忘記打開。所有的推送平臺,不管是極光還是什麼的,要想收到推送,這個是必須打開的喲✌️


 之後就應該可以收到推送了。另外,極光推送也推出新版本了,大家也可以更新下。

PS.蘋果這次對推送做了很大的變化,希望大家多查閱查閱,處理推送的代理方法也變化了。

<code class="objectivec" style="margin: 0px; padding: 0px;"><span class="hljs-comment" style="color: green; margin: 0px; padding: 0px; line-height: 1.5;">// 推送的代理
[<UNUserNotificationCenterDelegate>]</span></code>

iOS10收到通知不再是在
[application: didReceiveRemoteNotification:]方法去處理, iOS10推出新的代理方法,接收和處理各類通知(本地或者遠程)

<code class="css" style="margin: 0px; padding: 0px;"><span class="hljs-tag" style="color: rgb(0, 0, 255); margin: 0px; padding: 0px; line-height: 1.5;">- (<span class="hljs-tag" style="color: rgb(0, 0, 0); margin: 0px; padding: 0px; line-height: 1.5;">void)<span class="hljs-rule" style="margin: 0px; padding: 0px; line-height: 1.5;"><span class="hljs-attribute" style="color: rgb(163, 21, 21); margin: 0px; padding: 0px; line-height: 1.5;">userNotificationCenter:<span class="hljs-value" style="color: rgb(0, 136, 0); margin: 0px; padding: 0px; line-height: 1.5;">(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler { //應用在前臺收到通知 <span class="hljs-function" style="color: rgb(0, 102, 102); margin: 0px; padding: 0px; line-height: 1.5;">NSLog(@<span class="hljs-string" style="color: rgb(0, 136, 0); margin: 0px; padding: 0px; line-height: 1.5;">"========%@", notification);}<span class="hljs-tag" style="color: rgb(0, 0, 255); margin: 0px; padding: 0px; line-height: 1.5;">- (<span class="hljs-tag" style="color: rgb(0, 0, 0); margin: 0px; padding: 0px; line-height: 1.5;">void)<span class="hljs-rule" style="margin: 0px; padding: 0px; line-height: 1.5;"><span class="hljs-attribute" style="color: rgb(163, 21, 21); margin: 0px; padding: 0px; line-height: 1.5;">userNotificationCenter:<span class="hljs-value" style="color: rgb(0, 136, 0); margin: 0px; padding: 0px; line-height: 1.5;">(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler { //點擊通知進入應用 <span class="hljs-function" style="color: rgb(0, 102, 102); margin: 0px; padding: 0px; line-height: 1.5;">NSLog(@<span class="hljs-string" style="color: rgb(0, 136, 0); margin: 0px; padding: 0px; line-height: 1.5;">"response:%@", response);}</span></span></span></span></span></span></span></span></span></span></span></span></span></span></code>

稍後我會更新文章,對推送做一個詳細的講解。

8.屏蔽雜亂無章的bug

更新Xcode8之後,新建立工程,都會打印一堆莫名其妙看不懂的Log.
如這些

<code class="cpp" style="margin: 0px; padding: 0px;">subsystem: com.apple.UIKit, category: HIDEventFiltered, enable_level: <span class="hljs-number" style="color: rgb(0, 102, 102); margin: 0px; padding: 0px; line-height: 1.5;">0, persist_level: <span class="hljs-number" style="margin: 0px; padding: 0px; line-height: 1.5;">0, default_ttl: <span class="hljs-number" style="margin: 0px; padding: 0px; line-height: 1.5;">0, info_ttl: <span class="hljs-number" style="margin: 0px; padding: 0px; line-height: 1.5;">0, debug_ttl: <span class="hljs-number" style="margin: 0px; padding: 0px; line-height: 1.5;">0, generate_symptoms: <span class="hljs-number" style="margin: 0px; padding: 0px; line-height: 1.5;">0, enable_oversize: <span class="hljs-number" style="margin: 0px; padding: 0px; line-height: 1.5;">1,</span></span></span></span></span></span></span></code>

屏蔽的方法如下:
Xcode8裏邊 Edit Scheme-> Run -> Arguments, 或者用快捷鍵打開:ctrl+shift+<,在Environment Variables裏邊添加
OS_ACTIVITY_MODE = Disable 


如果寫了之後還是打印log,請重新勾選對勾,就可以解決了

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章