Skip to content

Commit e4422df

Browse files
committed
Fix crash when signing in & more logging & ui improvement
1 parent fd1d053 commit e4422df

File tree

7 files changed

+42
-69
lines changed

7 files changed

+42
-69
lines changed

Entitlement/AnisetteDataHelper.swift

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,8 @@ final class AnisetteDataHelper: WebSocketDelegate
139139
self.printOut("Getting provisioning URLs")
140140
var request = self.buildAppleRequest(url: URL(string: "https://gsa.apple.com/grandslam/GsService2/lookup")!)
141141
request.httpMethod = "GET"
142-
let (data, response) = try await URLSession.shared.asyncRequest(request: request)
143-
if let data = data,
142+
let (data, response) = try await URLSession.shared.data(for: request)
143+
if
144144
let plist = try? PropertyListSerialization.propertyList(from: data, format: nil) as? Dictionary<String, Dictionary<String, Any>>,
145145
let startProvisioningString = plist["urls"]?["midStartProvisioning"] as? String,
146146
let startProvisioningURL = URL(string: startProvisioningString),
@@ -153,7 +153,7 @@ final class AnisetteDataHelper: WebSocketDelegate
153153
self.printOut("Starting a provisioning session")
154154
return try await self.startProvisioningSession()
155155
} else {
156-
self.printOut("Apple didn't give valid URLs! Got response: \(String(data: data ?? Data("nothing".utf8), encoding: .utf8) ?? "not utf8")")
156+
self.printOut("Apple didn't give valid URLs! Got response: \(String(data: data, encoding: .utf8) ?? "not utf8")")
157157
throw "Apple didn't give valid URLs. Please try again later"
158158
}
159159

@@ -319,13 +319,10 @@ final class AnisetteDataHelper: WebSocketDelegate
319319
self.printOut("Trying to get client_info")
320320
let clientInfoURL = self.url!.appendingPathComponent("v3").appendingPathComponent("client_info")
321321

322-
let (data, response) = try await URLSession.shared.asyncRequest(url: clientInfoURL)
322+
let (data, response) = try await URLSession.shared.data(from: clientInfoURL)
323323

324324

325325
do {
326-
guard let data = data else {
327-
throw "Couldn't fetch client info. The server may be down"
328-
}
329326

330327
if let json = try JSONSerialization.jsonObject(with: data, options: []) as? [String: String] {
331328
if let clientInfo = json["client_info"] {
@@ -374,9 +371,7 @@ final class AnisetteDataHelper: WebSocketDelegate
374371
"adi_pb": adiPb
375372
], options: [])
376373
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
377-
let (data, response) = try await URLSession.shared.asyncRequest(request: request)
378-
379-
guard let data else { throw "Couldn't fetch anisette" }
374+
let (data, response) = try await URLSession.shared.data(for: request)
380375

381376
return try await self.extractAnisetteData(data, response as? HTTPURLResponse, v3: true)
382377

Entitlement/AppIDView.swift

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,40 +13,35 @@ struct AppIDEditView : View {
1313
@State private var errorInfo = ""
1414

1515
var body: some View {
16-
NavigationView {
17-
Form {
18-
Section {
19-
Button {
20-
Task { await addIncreasedMemoryLimit() }
21-
} label: {
22-
Text("Add Increased Memory Limit")
23-
}
24-
}
25-
26-
Section {
27-
Text(viewModel.result)
28-
.font(.system(.subheadline, design: .monospaced))
29-
} header: {
30-
Text("Server Response")
16+
Form {
17+
Section {
18+
Button {
19+
Task { await addIncreasedMemoryLimit() }
20+
} label: {
21+
Text("Add Increased Memory Limit")
3122
}
3223
}
33-
.alert("Error", isPresented: $errorShow){
34-
Button("OK".loc, action: {
35-
})
36-
} message: {
37-
Text(errorInfo)
38-
}
39-
.navigationTitle(viewModel.bundleID)
40-
.navigationBarTitleDisplayMode(.inline)
4124

25+
Section {
26+
Text(viewModel.result)
27+
.font(.system(.subheadline, design: .monospaced))
28+
} header: {
29+
Text("Server Response")
30+
}
4231
}
43-
.navigationViewStyle(StackNavigationViewStyle())
32+
.alert("Error", isPresented: $errorShow){
33+
Button("OK".loc, action: {
34+
})
35+
} message: {
36+
Text(errorInfo)
37+
}
38+
.navigationTitle(viewModel.bundleID)
39+
.navigationBarTitleDisplayMode(.inline)
4440
}
4541

4642
func addIncreasedMemoryLimit() async {
4743
do {
4844
try await viewModel.addIncreasedMemory()
49-
print("completed")
5045
} catch {
5146
errorInfo = error.localizedDescription
5247
errorShow = true

Entitlement/AppIDViewModel.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ class AppIDModel : ObservableObject, Hashable {
5656
request.allHTTPHeaderFields = httpHeaders
5757
request.httpBody = "{\"data\":{\"relationships\":{\"bundleIdCapabilities\":{\"data\":[{\"relationships\":{\"capability\":{\"data\":{\"id\":\"INCREASED_MEMORY_LIMIT\",\"type\":\"capabilities\"}}},\"type\":\"bundleIdCapabilities\",\"attributes\":{\"settings\":[],\"enabled\":true}}]}},\"id\":\"\(appID.identifier)\",\"attributes\":{\"hasExclusiveManagedCapabilities\":false,\"teamId\":\"\(team.identifier)\",\"bundleType\":\"bundle\",\"identifier\":\"\(appID.bundleIdentifier)\",\"seedId\":\"\(team.identifier)\",\"name\":\"\(appID.name)\"},\"type\":\"bundleIds\"}}".data(using: .utf8)
5858

59-
let (data, _) = try await URLSession.shared.asyncRequest(request: request)
59+
let (data, _) = try await URLSession.shared.data(for: request)
6060

6161
await MainActor.run {
62-
result = String(data: data!, encoding: .utf8) ?? "Unable to decode response."
62+
result = String(data: data, encoding: .utf8) ?? "Unable to decode response."
6363
}
6464

6565
}
@@ -80,7 +80,7 @@ class AppIDViewModel : ObservableObject {
8080
c.resume(throwing: error)
8181
}
8282
guard let appIDs else {
83-
c.resume(throwing: "AppIDs is nil, please try again or reopen the app.")
83+
c.resume(throwing: "AppIDs is nil. Please try again or reopen the app.")
8484
return
8585
}
8686
c.resume(returning: appIDs)

Entitlement/LoginViewModel.swift

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,13 @@ class LoginViewModel: ObservableObject {
3535
isLoginInProgress = true
3636
}
3737

38-
AnisetteDataHelper.shared.loggingFunc = { text in
38+
func logging(text: String) {
3939
Task { await MainActor.run {
4040
self.logs.append("\(text)\n")
4141
}}
4242
}
43+
44+
AnisetteDataHelper.shared.loggingFunc = logging
4345

4446
defer {
4547
Task{ await MainActor.run {
@@ -64,17 +66,22 @@ class LoginViewModel: ObservableObject {
6466
c.resume(throwing: error)
6567
return
6668
}
67-
68-
c.resume(returning: (account!, session!))
69+
if let account, let session {
70+
c.resume(returning: (account, session))
71+
} else {
72+
c.resume(throwing: "Account or session is nil. Please try again or reopen the app.")
73+
}
6974
}
7075
}
76+
logging(text: "Successfully signed in")
7177

7278
DataManager.shared.model.account = account
7379
DataManager.shared.model.session = session
7480
Keychain.shared.appleIDEmailAddress = self.appleID
7581
Keychain.shared.appleIDPassword = self.password
7682

7783
let team = try await fetchTeam(for: account, session: session)
84+
logging(text: "Successfully fetched team")
7885
DataManager.shared.model.team = team
7986

8087
Task{ await MainActor.run {

Entitlement/SettingsView.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ struct SettingsView: View {
5656
Button("Clean Up Keychain") {
5757
cleanUp()
5858
}
59+
} footer: {
60+
Text("If something went wrong during signing in, please try to clean up the keychain, repoen the app and try again.")
5961
}
6062
}
6163
.alert("Error", isPresented: $errorShow){

Entitlement/Shared.swift

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -80,32 +80,6 @@ extension String: @retroactive LocalizedError {
8080

8181
}
8282

83-
extension URLSession {
84-
public func asyncRequest(url: URL) async throws -> (Data?, URLResponse?) {
85-
return try await asyncRequest(request: URLRequest(url: url))
86-
}
87-
88-
public func asyncRequest(request: URLRequest) async throws -> (Data?, URLResponse?) {
89-
var ansData: Data?
90-
var ansResponse: URLResponse?
91-
var ansError: Error?
92-
await withCheckedContinuation { c in
93-
let task = self.dataTask(with: request) { data, response, error in
94-
ansError = error
95-
ansResponse = response
96-
ansData = data
97-
c.resume()
98-
}
99-
task.resume()
100-
}
101-
if let ansError {
102-
throw ansError
103-
}
104-
return (ansData, ansResponse)
105-
}
106-
}
107-
108-
10983
class SharedModel: ObservableObject {
11084
@Published var isLogin = false
11185
@AppStorage("AnisetteServer") var anisetteServerURL = "https://ani.sidestore.io"

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# Get More Ram
2-
A simple AltSign wrapper that allows you to enable "Increased Memory Limit" to your sideloaded apps without using Xcode
2+
A simple AltSign wrapper app that allows you to enable "Increased Memory Limit" for your sideloaded apps without using Xcode.
33

44
# How to use
55
1. Sideload this app
6-
2. Go to settings, sign in your account
6+
2. Go to settings, sign in your account that you used to sign the app you want to enable "Increased Memory Limit"
77
3. Go to "App IDs" page
88
4. Tap Refresh
99
5. Tap the app you want to enable "Increased Memory Limit"

0 commit comments

Comments
 (0)