Skip to content

Commit 5d52c24

Browse files
authored
Add --wait to ios launch (danielpaulus#205)
adds new --wait switch to keep the command running and display application logs when an app is launched with ios launch [bundleID]
1 parent 497b36a commit 5d52c24

File tree

3 files changed

+29
-13
lines changed

3 files changed

+29
-13
lines changed

ios/dtx_codec/connection.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
package dtx
22

33
import (
4+
"github.com/danielpaulus/go-ios/ios"
45
"io"
6+
"math"
57
"strings"
68
"sync"
79
"time"
8-
"math"
910

10-
ios "github.com/danielpaulus/go-ios/ios"
1111
"github.com/danielpaulus/go-ios/ios/nskeyedarchiver"
1212
log "github.com/sirupsen/logrus"
1313
)
@@ -73,9 +73,13 @@ func (g GlobalDispatcher) Dispatch(msg Message) {
7373
}
7474
//TODO: use the dispatchFunctions map
7575
if "outputReceived:fromProcess:atTime:" == msg.Payload[0] {
76-
msg, err := nskeyedarchiver.Unarchive(msg.Auxiliary.GetArguments()[0].([]byte))
76+
logmsg, err := nskeyedarchiver.Unarchive(msg.Auxiliary.GetArguments()[0].([]byte))
7777
if err == nil {
78-
log.Info(msg[0])
78+
log.WithFields(log.Fields{
79+
"msg": logmsg[0],
80+
"pid": msg.Auxiliary.GetArguments()[1],
81+
"time": msg.Auxiliary.GetArguments()[2],
82+
}).Info("outputReceived:fromProcess:atTime:")
7983
}
8084
return
8185
}

ios/instruments/processcontrol.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package instruments
22

33
import (
44
"fmt"
5-
65
"github.com/danielpaulus/go-ios/ios"
76
dtx "github.com/danielpaulus/go-ios/ios/dtx_codec"
87
log "github.com/sirupsen/logrus"
@@ -16,13 +15,20 @@ type ProcessControl struct {
1615
//LaunchApp launches the app with the given bundleID on the given device.LaunchApp
1716
//Use LaunchAppWithArgs for passing arguments and envVars. It returns the PID of the created app process.
1817
func (p *ProcessControl) LaunchApp(bundleID string) (uint64, error) {
19-
options := map[string]interface{}{}
20-
options["StartSuspendedKey"] = uint64(0)
21-
return p.StartProcess(bundleID, map[string]interface{}{}, []interface{}{}, options)
18+
opts := map[string]interface{}{
19+
"StartSuspendedKey": uint64(0),
20+
}
21+
// Xcode sends all these, no idea if we need them for sth. later.
22+
//"CA_ASSERT_MAIN_THREAD_TRANSACTIONS": "0", "CA_DEBUG_TRANSACTIONS": "0", "LLVM_PROFILE_FILE": "/dev/null", "METAL_DEBUG_ERROR_MODE": "0", "METAL_DEVICE_WRAPPER_TYPE": "1",
23+
//"OS_ACTIVITY_DT_MODE": "YES", "SQLITE_ENABLE_THREAD_ASSERTIONS": "1", "__XPC_LLVM_PROFILE_FILE": "/dev/null"
24+
// NSUnbufferedIO seems to make the app send its logs via instruments using the outputReceived:fromProcess:atTime: selector
25+
// We'll supply per default to get logs
26+
env := map[string]interface{}{"NSUnbufferedIO": "YES"}
27+
return p.StartProcess(bundleID, env, []interface{}{}, opts)
2228
}
2329

24-
func (p *ProcessControl) Close() {
25-
p.conn.Close()
30+
func (p *ProcessControl) Close() error {
31+
return p.conn.Close()
2632
}
2733

2834
func NewProcessControl(device ios.DeviceEntry) (*ProcessControl, error) {

main.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ Usage:
9393
ios install --path=<ipaOrAppFolder> [options]
9494
ios uninstall <bundleID> [options]
9595
ios apps [--system] [--all] [--list] [options]
96-
ios launch <bundleID> [options]
96+
ios launch <bundleID> [--wait] [options]
9797
ios kill (<bundleID> | --pid=<processID> | --process=<processName>) [options]
9898
ios runtest <bundleID> [options]
9999
ios runwda [--bundleid=<bundleid>] [--testrunnerbundleid=<testbundleid>] [--xctestconfig=<xctestconfig>] [--arg=<a>]... [--env=<e>]... [options]
@@ -177,7 +177,7 @@ The commands work as following:
177177
ios install --path=<ipaOrAppFolder> [options] Specify a .app folder or an installable ipa file that will be installed.
178178
ios pcap [options] [--pid=<processID>] [--process=<processName>] Starts a pcap dump of network traffic, use --pid or --process to filter specific processes.
179179
ios apps [--system] [--all] [--list] Retrieves a list of installed applications. --system prints out preinstalled system apps. --all prints all apps, including system, user, and hidden apps. --list only prints bundle ID, bundle name and version number.
180-
ios launch <bundleID> Launch app with the bundleID on the device. Get your bundle ID from the apps command.
180+
ios launch <bundleID> [--wait] Launch app with the bundleID on the device. Get your bundle ID from the apps command. --wait keeps the connection open if you want logs.
181181
ios kill (<bundleID> | --pid=<processID> | --process=<processName>) [options] Kill app with the specified bundleID, process id, or process name on the device.
182182
ios runtest <bundleID> Run a XCUITest.
183183
ios runwda [--bundleid=<bundleid>] [--testrunnerbundleid=<testbundleid>] [--xctestconfig=<xctestconfig>] [--arg=<a>]... [--env=<e>]...[options] runs WebDriverAgents
@@ -515,6 +515,7 @@ The commands work as following:
515515

516516
b, _ = arguments.Bool("launch")
517517
if b {
518+
wait, _ := arguments.Bool("--wait")
518519
bundleID, _ := arguments.String("<bundleID>")
519520
if bundleID == "" {
520521
log.Fatal("please provide a bundleID")
@@ -524,8 +525,13 @@ The commands work as following:
524525

525526
pid, err := pControl.LaunchApp(bundleID)
526527
exitIfError("launch app command failed", err)
527-
528528
log.WithFields(log.Fields{"pid": pid}).Info("Process launched")
529+
if wait {
530+
c := make(chan os.Signal, 1)
531+
signal.Notify(c, syscall.SIGINT, syscall.SIGTERM)
532+
<-c
533+
log.WithFields(log.Fields{"pid": pid}).Info("stop listening to logs")
534+
}
529535
}
530536

531537
b, _ = arguments.Bool("kill")

0 commit comments

Comments
 (0)