一,說明:
二,問題及解決方法:
今天幫朋友解決iWatch的問題,他把項目直接扔給我,我們都知道如果項目中帶一些需要開發認證的框架(比如Healthkit框架內)是不能直接運行的.昨天經過一個多小時的研究(PS:樓主比較笨),終於搞定這個問題.現在把自己爬坑的經過寫下來,希望能幫助到大家.
朋友的項目就不便放出來啦,特意從github上找了個大牛寫的Demo: https://github.com/shu223/watchOS-2-Sampler
大家是不是和我一樣,項目一下載下來,就會迫不及待滿懷期待的運行一下.結果...
錯誤1: Fail to code sign "***" No valid signing identities (i.e. certificate and private key pair) matching the team ID "****" were found.
然後我們就想都不想來fix issue.本人還是蠻信任蘋果的,一些問題我們fix 下就會解決.然後我們就會滿懷期待的再fix下.然後..
然後我們在fix...
錯誤2: Unable to find a team with the given Team ID '****' to which you belong. Please contact Apple Developer Prpgram Support.
現在問題出來了,是我們的開發者賬號不匹配,所以我們要去項目中去配置一下.
選中我們的開發者賬號在運行,又報錯了..
現在的問題是找不到和"9Z86...."team ID匹配的正式.我們在fix下..
又報錯了,而且只能點Done了,而且問題也沒辦法解決,別人的開發者賬號,我們聯繫蘋果也沒有用,是不是很崩潰..其實只是我們應用中使用了Healthkit框架,而該框架是需要開發者賬號認證的.
點一下fix issue..又報錯了..
錯誤3: An App ID with identifier "*****" is not avaliable. Please enter a different string.
再fix..還是和上面報的錯一樣.然後你就會發現其實這並沒什麼卵用. 錯誤的原因就是這個identifer已經被別人佔用了,你不可以再使了(如果男票和女票也可用這樣就好了,被我佔用了其他人就想都別想了,當然前提是你得有).既然這個被佔用了那我們就換個唄,天涯何處無芳草..
現在我們在bundle ID 後面加了個標誌,回到capabilities再fix一下.好了
我們再滿懷憧憬的運行下...
錯誤4: No code signing identities found: No valid signing identitis (i.e certificate and private key pair) matching the team ID "***" were found. CodeSign error: code signing
is required for product type 'WatchKit App' in SDK 'Watch OS 2.0'
又報錯了..錯誤原因顧名思義,我們值改了extension.watch app也要改
再運行哈..又報錯..
錯誤5: error: Enbedded binary's identifier is not prefixed with the parent app's bundle identifier.
錯誤的原因就是我們嵌入的bundle ID 和父APP的前綴不一樣.蘋果之所以能關聯手機和watch的APP是有條件的.其bundle ID 必須遵循固定的格式. 也就是兩者的前綴必須一樣.好吧,現在我們再改一下父APP的bundle ID .
好啦.我們在運行下..又報錯了,沒完沒了
錯誤6: error: WatchKit App doesn't contain any WatchKit Extensions whose WKAppBundleIdentifier matches "*****". Verify that the value if WKAppBundleIdentifier in your WatchKit Extension's Info.plist matches the value of CFBundleIndetifier in your WatchKit App's Info.plist.
好吧,按照蘋果的提示做就ok了..一定要APP和extension的配置保持一致.
再運行一次..
錯誤7: error: warning: Is a directory
這次想罵人了,報了個莫名其妙的錯誤...
其實每次看到這個錯誤我就會clear一下工程,然後真正的錯誤就會顯出原形.本人比較喜歡改了工程配置啥的就喜歡clean下.雖然有時間沒必要(但有時候是很有用的).而且自認爲是個好習慣...現在讓我們看看真正的錯誤是啥.
錯誤8: error: Embedded binary's bundle identifier is not prefixed with the parent app's bundle identifier.
提示顯示,內嵌的bundle ID 和父APP的不匹配.因爲我們該了watch APP和extension,卻沒有改主APP的bundle ID.下面我們修改一下主APP的bundle ID
在運行一下....然後你會驚奇的發現 ----------------- 終於能運行了.