@@ -2,6 +2,8 @@ package installationproxy
22
33import (
44 "bytes"
5+ "fmt"
6+ log "github.com/sirupsen/logrus"
57
68 ios "github.com/danielpaulus/go-ios/ios"
79 "howett.net/plist"
@@ -61,6 +63,56 @@ func (conn *Connection) browseApps(request interface{}) ([]AppInfo, error) {
6163 }
6264 return appinfos , nil
6365}
66+
67+ func (c * Connection ) Uninstall (bundleId string ) error {
68+ options := map [string ]interface {}{}
69+ uninstallCommand := map [string ]interface {}{
70+ "Command" : "Uninstall" ,
71+ "ApplicationIdentifier" : bundleId ,
72+ "ClientOptions" : options ,
73+ }
74+ b , err := c .plistCodec .Encode (uninstallCommand )
75+ if err != nil {
76+ return err
77+ }
78+ err = c .deviceConn .Send (b )
79+ if err != nil {
80+ return err
81+ }
82+ for {
83+ response , err := c .plistCodec .Decode (c .deviceConn .Reader ())
84+ if err != nil {
85+ return err
86+ }
87+ dict , err := ios .ParsePlist (response )
88+ if err != nil {
89+ return err
90+ }
91+ done , err := checkFinished (dict )
92+ if err != nil {
93+ return err
94+ }
95+ if done {
96+ return nil
97+ }
98+ }
99+ }
100+
101+ func checkFinished (dict map [string ]interface {}) (bool , error ) {
102+ if val , ok := dict ["Error" ]; ok {
103+ return true , fmt .Errorf ("received uninstall error: %v" , val )
104+ }
105+ if val , ok := dict ["Status" ]; ok {
106+ if "Complete" == val {
107+ log .Info ("done uninstalling" )
108+ return true , nil
109+ }
110+ log .Infof ("uninstall status: %s" , val )
111+ return false , nil
112+ }
113+ return true , fmt .Errorf ("unknown status update: %+v" , dict )
114+ }
115+
64116func plistFromBytes (plistBytes []byte ) (BrowseResponse , error ) {
65117 var browseResponse BrowseResponse
66118 decoder := plist .NewDecoder (bytes .NewReader (plistBytes ))
0 commit comments