Skip to content

Commit 2652fd2

Browse files
committed
Fix LiveContainer/LiveContainer#1469, fix backup again
1 parent 2e598fe commit 2652fd2

2 files changed

Lines changed: 32 additions & 9 deletions

File tree

Shared/Extensions/Bundle+AltStore.swift

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@
77
//
88

99
import Foundation
10+
import Security
11+
12+
@_silgen_name("SecTaskCreateFromSelf")
13+
private func secTaskCreateFromSelf(_ allocator: CFAllocator?) -> Unmanaged<CFTypeRef>?
14+
15+
@_silgen_name("SecTaskCopyValueForEntitlement")
16+
private func secTaskCopyValueForEntitlement(_ task: CFTypeRef, _ entitlement: CFString, _ error: UnsafeMutablePointer<Unmanaged<CFError>?>?) -> Unmanaged<CFTypeRef>?
1017

1118
public extension Bundle
1219
{
@@ -63,6 +70,14 @@ public extension Bundle
6370
static let baseAltStoreAppGroupID = "group.com.SideStore.SideStore"
6471
static let isBundledWithLiveContainer = Bundle.main.bundleURL.lastPathComponent == "SideStoreApp.framework" || Bundle.main.bundleURL.lastPathComponent == "LiveWidgetExtension.appex"
6572

73+
private static let entitlementAppGroups: [String] = {
74+
guard let task = secTaskCreateFromSelf(nil)?.takeRetainedValue(),
75+
let value = secTaskCopyValueForEntitlement(task, "com.apple.security.application-groups" as CFString, nil)?.takeRetainedValue(),
76+
let appGroups = value as? [String] else { return [] }
77+
78+
return appGroups
79+
}()
80+
6681
var appGroups: [String] {
6782
return self.infoDictionary?[Bundle.Info.appGroups] as? [String] ?? []
6883
}
@@ -76,10 +91,8 @@ public extension Bundle
7691
}
7792

7893
var altstoreAppGroup: String? {
79-
if Bundle.isBundledWithLiveContainer, let lcBundle = Bundle.lcBundle {
80-
return lcBundle.appGroups.first { $0.contains(Bundle.baseAltStoreAppGroupID) }
81-
}
82-
return self.appGroups.first { $0.contains(Bundle.baseAltStoreAppGroupID) }
94+
let appGroups = Bundle.entitlementAppGroups
95+
return appGroups.first { $0.contains(Bundle.baseAltStoreAppGroupID) } ?? appGroups.first
8396
}
8497

8598
var completeInfoDictionary: [String : Any]? {

SideBackup/SideBackupApp.swift

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,22 @@ class AppDelegate: NSObject, UIApplicationDelegate {
9898
Task { @MainActor in
9999
// Response to the caller/parent app is posted here (url is provided by caller in incoming query params)
100100
debugLog("[SideBackup]: Attempting to open return URL: \(responseURL.absoluteString), scheme: \(responseURL.scheme ?? "nil")")
101-
UIApplication.shared.open(responseURL, options: [:]) { success in
102-
debugLog("[SideBackup]: Sent response to app with success: \(success)")
103-
if !success {
104-
debugLog("[SideBackup]: WARNING - Failed to open SideStore return URL. Scheme '\(responseURL.scheme ?? "nil")' may not be registered or SideStore is not installed.")
105-
}
101+
let success1 = await UIApplication.shared.open(responseURL, options: [:])
102+
debugLog("[SideBackup]: Sent response to app with success: \(success1)")
103+
if success1 {
104+
return
105+
}
106+
debugLog("[SideBackup]: WARNING - Failed to open SideStore return URL. Scheme '\(responseURL.scheme ?? "nil")' may not be registered or SideStore is not installed.")
107+
// fallback to sidestore://
108+
components.scheme = "sidestore"
109+
guard let responseURL2 = components.url else { return }
110+
let success2 = await UIApplication.shared.open(responseURL2, options: [:])
111+
debugLog("[SideBackup]: Sent response to app with success: \(success2)")
112+
if success2 {
113+
return
106114
}
115+
debugLog("[SideBackup]: WARNING - Failed to open SideStore return URL. Scheme '\(responseURL.scheme ?? "nil")' may not be registered or SideStore is not installed.")
116+
107117
}
108118
}
109119
}

0 commit comments

Comments
 (0)