基於xcrun的工程構建

weixin_34236869發表於2018-04-17

1.使用NSTask呼叫shell

- (NSString *)cmd:(NSString *)cmd
{
    // 初始化並設定shell路徑
    NSTask *task = [[NSTask alloc] init];
    [task setLaunchPath: @"/bin/bash"];
    // -c 用來執行string-commands(命令字串),也就說不管後面的字串裡是什麼都會被當做shellcode來執行
    NSArray *arguments = [NSArray arrayWithObjects: @"-c", cmd, nil];
    [task setArguments: arguments];
    
    // 新建輸出管道作為Task的輸出
    NSPipe *pipe = [NSPipe pipe];
    [task setStandardOutput: pipe];
    
    // 開始task
    NSFileHandle *file = [pipe fileHandleForReading];
    [task launch];
    
    // 獲取執行結果
    NSData *data = [file readDataToEndOfFile];
    return [[NSString alloc] initWithData: data encoding: NSUTF8StringEncoding];
}`

### 2.一些shell命令
真機安裝:

fruitstrap  -b  UCWEB.app/XXX.ipa

模擬器安裝:

xcrun simctl install booted <XXX.app/XXX.ipa>

解除安裝應用(萬能法,殺傷力極大,直接重置裝置):


The solution that I came up with is to use the command

xcrun simctl erase [device ID]
只是解除安裝應用(刪除裝置的安裝資料)

rm -rf  

  ~/Library/Developer/CoreSimulator/Devices/

       <device id>/data/Containers/Data/Application/* 

檢視裝置:

instruemtns -s  devices

更加詳細:

The device ID can be obtained from running

xcrun simctl list

### 3.xcrun simctl openurl booted "alipays://"
這個命令喚起支付寶,是schememanager的底層實現原理。
https://github.com/daryl5/iScheme 作者:凌萬

相關文章