@@ -923,6 +923,34 @@ extension AppManager
923923 }
924924 }
925925
926+ @discardableResult
927+ func resign( _ installedApp: InstalledApp , presentingViewController: UIViewController ? , completionHandler: @escaping ( Result < InstalledApp , Error > ) -> Void ) -> RefreshGroup
928+ {
929+ let group = RefreshGroup ( )
930+ group. completionHandler = { ( results) in
931+ do
932+ {
933+ guard let result = results. values. first else { throw group. context. error ?? OperationError . unknown ( ) }
934+ let installedApp = try result. get ( )
935+ completionHandler ( . success( installedApp) )
936+ }
937+ catch
938+ {
939+ completionHandler ( . failure( error) )
940+ }
941+ }
942+
943+ Task {
944+ do {
945+ try await self . perform ( [ . resign( installedApp) ] , presentingViewController: presentingViewController, group: group)
946+ } catch {
947+ completionHandler ( . failure( error) )
948+ }
949+ }
950+
951+ return group
952+ }
953+
926954 func backup( _ installedApp: InstalledApp , presentingViewController: UIViewController ? , completionHandler: @escaping ( Result < InstalledApp , Error > ) -> Void )
927955 {
928956 let group = RefreshGroup ( )
@@ -1103,13 +1131,15 @@ private extension AppManager
11031131 case deactivate( InstalledApp )
11041132 case backup( InstalledApp )
11051133 case restore( InstalledApp )
1134+ case resign( InstalledApp )
11061135
11071136 var app : AppProtocol {
11081137 switch self
11091138 {
11101139 case . install( let app) , . update( let app) , . refresh( let app as AppProtocol ) ,
11111140 . activate( let app as AppProtocol ) , . deactivate( let app as AppProtocol ) ,
1112- . backup( let app as AppProtocol ) , . restore( let app as AppProtocol ) :
1141+ . backup( let app as AppProtocol ) , . restore( let app as AppProtocol ) ,
1142+ . resign( let app as AppProtocol ) :
11131143 return app
11141144 }
11151145 }
@@ -1139,6 +1169,7 @@ private extension AppManager
11391169 case . deactivate: return . deactivate
11401170 case . backup: return . backup
11411171 case . restore: return . restore
1172+ case . resign: return . install
11421173 }
11431174 }
11441175 }
@@ -1208,6 +1239,12 @@ private extension AppManager
12081239 }
12091240 progress? . addChild ( updateProgress, withPendingUnitCount: 80 )
12101241
1242+ case . resign( let app) :
1243+ let resignProgress = self . _install ( app, operation: operation, group: group, reviewPermissions: . none) { ( result) in
1244+ self . finish ( operation, result: result, group: group, progress: progress)
1245+ }
1246+ progress? . addChild ( resignProgress, withPendingUnitCount: 80 )
1247+
12111248 case . activate( let app) where UserDefaults . standard. isLegacyDeactivationSupported: fallthrough
12121249 case . refresh( let app) :
12131250 let refreshProgress = self . _refresh ( app, operation: operation, group: group) { ( result) in
@@ -1295,7 +1332,11 @@ private extension AppManager
12951332
12961333 if let installedApp = app as? InstalledApp
12971334 {
1298- if let storeApp = installedApp. storeApp, !FileManager. default. fileExists ( atPath: installedApp. fileURL. path)
1335+ if case . resign = appOperation {
1336+ // For resign, we MUST use the cached app bundle and not download from the store/web
1337+ downloadingApp = installedApp
1338+ }
1339+ else if let storeApp = installedApp. storeApp, !FileManager. default. fileExists ( atPath: installedApp. fileURL. path)
12991340 {
13001341 // Cached app has been deleted, so we need to redownload it.
13011342 downloadingApp = storeApp
@@ -2206,7 +2247,7 @@ private extension AppManager
22062247 switch operation
22072248 {
22082249 case . install, . update: return self . installationProgress [ bundleID]
2209- case . refresh, . activate, . deactivate, . backup, . restore: return self . refreshProgress [ bundleID]
2250+ case . refresh, . activate, . deactivate, . backup, . restore, . resign : return self . refreshProgress [ bundleID]
22102251 }
22112252 }
22122253
@@ -2221,7 +2262,7 @@ private extension AppManager
22212262 switch operation
22222263 {
22232264 case . install, . update: self . installationProgress [ bundleID] = progress
2224- case . refresh, . activate, . deactivate, . backup, . restore: self . refreshProgress [ bundleID] = progress
2265+ case . refresh, . activate, . deactivate, . backup, . restore, . resign : self . refreshProgress [ bundleID] = progress
22252266 }
22262267 }
22272268}
0 commit comments