日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

给iOS 模拟器“安装”app文件

發(fā)布時(shí)間:2024/1/17 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 给iOS 模拟器“安装”app文件 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

?

?

前言

?

剛剛接觸iOS的時(shí)候,我就一直很好奇,模擬器上面能不能直接安裝app呢?如果可以,我們就直接在模擬器上面聊QQ和微信了。直到昨天和朋友們聊到了這個(gè)話(huà)題,沒(méi)有想到還真的可以給模擬器“安裝”app!

?

一.應(yīng)用場(chǎng)景

?

先來(lái)談?wù)勈鞘裁辞闆r下,會(huì)有在模擬器上安裝app的需求。

?

在一個(gè)大公司里,對(duì)源碼的管理有嚴(yán)格的制度,非開(kāi)發(fā)人員是沒(méi)有權(quán)限接觸到源碼的。對(duì)蘋(píng)果的開(kāi)發(fā)證書(shū)管理也非常嚴(yán)格,甚至連開(kāi)發(fā)人員也沒(méi)有發(fā)布證書(shū),證書(shū)只在持續(xù)集成環(huán)境或者Appstore產(chǎn)線(xiàn)里面,或者只在最后打包上架的人手上。

?

那么現(xiàn)在就有這樣的需求,開(kāi)發(fā)人員搭建好UI以后,要把開(kāi)發(fā)完成的Alapha版給到UI設(shè)計(jì)師那邊去評(píng)審,看看是否完全達(dá)到要求,達(dá)不到要求就需要打回來(lái)重做。

?

一般做法就是直接拿手機(jī)去安裝一遍了。直接真機(jī)看效果。不過(guò)要是設(shè)計(jì)師和開(kāi)發(fā)不在同一個(gè)地方的公司,一個(gè)在北京一個(gè)在上海,這種就沒(méi)法安裝了。源碼又無(wú)法導(dǎo)出給設(shè)計(jì)師,讓他運(yùn)行一下Xcode跑一下模擬器。打release的ipa通過(guò)掃碼安裝,如果公司大了,UDID全部都用完了,也沒(méi)法安裝。這個(gè)時(shí)候就比較麻煩了。(一般也沒(méi)人遇到這么蛋疼的事情吧)

?

那么現(xiàn)在就有給模擬器安裝app的需求了,那開(kāi)發(fā)人員如何能把開(kāi)發(fā)版的app給打包出來(lái)給其他模擬器安裝呢?

?

二.解決辦法

?

解決思路,想要?jiǎng)e人的模擬器運(yùn)行起我們開(kāi)發(fā)的app,最簡(jiǎn)單的辦法就是把我們DerivedData的數(shù)據(jù)直接拷貝到別人模擬器上面,就可以了。當(dāng)然還要考慮到設(shè)計(jì)師也許并不會(huì)一些命令行命令,我們的操作越傻瓜越好。

?

1.拷貝本地的DerivedData里面的debug包

?

Mac的拷貝命令有cp和ditto,建議用ditto進(jìn)行拷貝工作。

?

Usage: ditto [??] src [ ... src ] dst

?

???? are any of:

????-h???????????????????????? print full usage

????-v???????????????????????? print a line of status for each source copied

????-V???????????????????????? print a line of status for every file copied

????-X???????????????????????? do not descend into directories with a different device ID

?

????-c???????????????????????? create an archive at dst (by default CPIO format)

????-x???????????????????????? src(s) are archives

????-z???????????????????????? gzip compress CPIO archive

????-j???????????????????????? bzip2 compress CPIO archive

????-k???????????????????????? archives are PKZip

????--keepParent?????????????? parent directory name src is embedded in dst_archive

????--arch archVal???????????? fat files will be thinned to archVal

?????????????????????????????? multiple -arch options can be specified

?????????????????????????????? archVal should be one of "ppc", "i386", etc

????--bom bomFile??????????????only objects present in bomFile are copied

????--norsrc?????????????????? don't preserve resource data

????--noextattr????????????????don't preserve extended attributes

????--noqtn????????????????????don't preserve quarantine information

????--noacl????????????????????don't preserve ACLs

????--sequesterRsrc????????????copy resources via polite directory (PKZip only)

????--nocache??????????????????don't use filesystem cache for reads/writes

????--hfsCompression?????????? compress files at destination if appropriate

????--nopreserveHFSCompression don't preserve HFS+ compression when copying files

????--zlibCompressionLevel num use compression level 'num' when creating a PKZip archive

????--password???????????????? request password for reading from encrypted PKZip archive

?

Ditto比cp命令更好的地方在于:

?

  • 它在復(fù)制過(guò)程中不僅能保留源文件或者文件夾的屬性與權(quán)限,還能保留源文件的資源分支結(jié)構(gòu)和文件夾的源結(jié)構(gòu)。

  • 此命令能確保文件或者文件夾被如實(shí)復(fù)制。

  • 如果目標(biāo)文件或者文件夾不存在,ditto將直接復(fù)制過(guò)去或創(chuàng)建新的文件和文件夾,相反,對(duì)于已經(jīng)存在的文件,命令將與目標(biāo)文件(夾)合并。

  • ditto還能提供完整符號(hào)鏈接。

  • ?

    那么我們就拷貝出本地的debug包

    ?

    ditto -ck --sequesterRsrc --keepParent `ls -1 -d -t ~/Library/Developer/Xcode/DerivedData/*/Build/Products/*-iphonesimulator/*.app | head -n 1` /Users/YDZ/Desktop/app.zip

    ?

    有幾點(diǎn)需要說(shuō)明的:

    ?

  • 上面命令最后一個(gè)路徑(/Users/YDZ/Desktop/app.zip),這個(gè)是自定義的,我這里舉的例子是直接放在桌面。除了這里改一下路徑,前面的都不需要改,包括 * 也都不用改。

  • 再來(lái)說(shuō)一下命令里面的 * 的問(wèn)題。當(dāng)我們打開(kāi)自己本地的~/Library/Developer/Xcode/DerivedData/ ,這個(gè)路徑下,會(huì)發(fā)現(xiàn)里面裝的都是在我們本地模擬器上運(yùn)行過(guò)的app程序。前面是app的Bundle Identifier,橫線(xiàn)后面是一堆字符串。上面的ditto里面帶 * 的那個(gè)路徑是為了動(dòng)態(tài)匹配一個(gè)地址的,* 在這里也是一個(gè)通配符。后面的head說(shuō)明了匹配的規(guī)則。head其實(shí)是找出最近一次我們運(yùn)行模擬器的app的路徑。

  • ?

    為了保證我們打包是正確的,建議先運(yùn)行一下我們要打包的app,一般我們Scheme里面的Run都是debug product(如果這里有更改,那就改成對(duì)應(yīng)debug的Scheme),確保是我們要給設(shè)計(jì)師審核的app,之后再運(yùn)行這個(gè)ditto命令。

    ?

    2.把debug包拷貝到另一個(gè)模擬器中

    ?

    我們運(yùn)行完上面的ditto命令會(huì)產(chǎn)生一個(gè)zip文件,解壓出來(lái),會(huì)得到一個(gè)app文件,這個(gè)就是debug包了。debug包就是我們要給設(shè)計(jì)師的app包了。

    ?

    如何能讓設(shè)計(jì)師傻瓜式的安裝這個(gè)app呢?

    ?

    這里介紹一個(gè)命令行工具,ios-sim命令行工具。

    ?

    ios-sim 是一個(gè)可以在命令控制iOS模擬器的工具。利用這個(gè)命令,我們可以啟動(dòng)一個(gè)模擬器,安裝app,啟動(dòng)app,查詢(xún)iOS SDK。它可以使我們像自動(dòng)化測(cè)試一樣不用打開(kāi)Xcode。

    ?

    不過(guò) ios-sim 只支持Xcode 6 以后的版本。

    ?

    安裝ios-sim

    ?

    $ npm install ios-sim -g

    ?

    說(shuō)明文檔:

    ?

    ????Usage: ios-sim??[--args ...]

    ?

    ????Commands:

    ??????showsdks????????????????????????List the available iOS SDK versions

    ??????showdevicetypes???????????????? List the available device types

    ??????launch????????Launch the application at the specified path on the iOS Simulator

    ??????start?????????????????????????? Launch iOS Simulator without an app

    ??????install?????? Install the application at the specified path on the iOS Simulator without launching the app

    ?

    ????Options:

    ??????--version?????????????????????? Print the version of ios-sim

    ??????--help??????????????????????????Show this help text

    ??????--exit??????????????????????????Exit after startup

    ??????--log????????????The path where log of the app running in the Simulator will be redirected to

    ??????--devicetypeid???? The id of the device type that should be simulated (Xcode6+). Use 'showdevicetypes' to list devices.

    ??????????????????????????????????????e.g "com.apple.CoreSimulator.SimDeviceType.Resizable-iPhone6, 8.0"

    ?

    ????Removed in version 4.x:

    ??????--stdout??????The path where stdout of the simulator will be redirected to (defaults to stdout of ios-sim)

    ??????--stderr??????The path where stderr of the simulator will be redirected to (defaults to stderr of ios-sim)

    ??????--sdk?????????????? The iOS SDK version to run the application on (defaults to the latest)

    ??????--family???????? The device type that should be simulated (defaults to `iphone')

    ??????--retina????????????????????????Start a retina device

    ??????--tall??????????????????????????In combination with --retina flag, start the tall version of the retina device (e.g. iPhone 5 (4-inch))

    ??????--64bit???????????????????????? In combination with --retina flag and the --tall flag, start the 64bit version of the tall retina device (e.g. iPhone 5S (4-inch 64bit))

    ?

    ????Unimplemented in this version:

    ??????--verbose?????????????????????? Set the output level to verbose

    ??????--timeout??????????????The timeout time to wait for a response from the Simulator. Default value: 30 seconds

    ??????--args???????????????????? All following arguments will be passed on to the application

    ??????--env????A plist file containing environment key-value pairs that should be set

    ??????--setenv NAME=VALUE???????????? Set an environment variable

    ?

    用法不難

    ?

    ios-sim launch /Users/YDZ/Desktop/app.app --devicetypeid iPhone-6s

    ?

    其中,/Users/YDZ/Desktop/app.app這個(gè)是設(shè)計(jì)師收到app之后的路徑。–devicetypeid參數(shù)后面是給定一個(gè)模擬器的版本。

    ?

    只需要把上面的命令發(fā)給設(shè)計(jì)師,無(wú)腦粘貼到命令行,裝好app的模擬器就會(huì)自動(dòng)啟動(dòng),打開(kāi)app了。

    ?

    三.額外的嘗試

    ?

    好奇的同學(xué)肯定不會(huì)滿(mǎn)足只給模擬器安裝debug包吧,既然可以不用代碼就可以給模擬器安裝app,那我們能安裝release包么?我好奇的嘗試了一下。

    ?

    先從Appstore上面下載最新的微信,把ipa后綴改成zip,解壓,把Payload文件夾里面的“WeChat”取出來(lái),然后運(yùn)行ios-sim命令。

    ?

    結(jié)果微信確實(shí)是安裝到了模擬器了。不過(guò)一點(diǎn)擊app,看見(jiàn)了月亮界面就退出了。控制臺(tái)打印了一堆信息。

    ?

    此處信息過(guò)長(zhǎng),可到原文查看

    ?

    仔細(xì)看了一下log,根本原因還是因?yàn)?/p>

    ?

    com.apple.CoreSimulator.SimDevice.D6BD3967-9BC4-4A8D-9AD0-23176B22B12A.launchd_sim[19096] (UIKitApplication:com.tencent.xin[0xdf6d][19774]): Program specified by service does not contain one of the requested architectures:

    ?

    Unable to get pid for 'UIKitApplication:com.tencent.xin[0xdf6d]': No such process (err 3)

    ?

    因?yàn)閞elease包里面architectures打包的時(shí)候不包含模擬器的architectures。debug包里面就有。所以release就沒(méi)法安裝到模擬器了。

    ?

    由于筆者逆向方面的東西沒(méi)有研究,所以也無(wú)法繼續(xù)下去了。不知道逆向技術(shù)能不能把release包破殼之后能不能轉(zhuǎn)成debug包呢?如果能轉(zhuǎn)成debug包,通過(guò)ios-sim命令應(yīng)該也是可以直接安裝到模擬器的。

    ?

    至此,ios-sim給模擬器安裝app就嘗試到此了。因?yàn)橹荒芙o模擬器安裝debug包,所以在題目上額外給安裝加了雙引號(hào),并不是所有的app文件都可以安裝到模擬器。

    ?

    請(qǐng)大家多多指教。

    總結(jié)

    以上是生活随笔為你收集整理的给iOS 模拟器“安装”app文件的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

    如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。