@@ -9,6 +9,19 @@ import Foundation
9
9
import UIKit
10
10
import Telegraph
11
11
import Zip
12
+ import SwiftUI
13
+ import SafariServices
14
+
15
+ struct SafariWebView : UIViewControllerRepresentable {
16
+ let url : URL
17
+
18
+ func makeUIViewController( context: Context ) -> SFSafariViewController {
19
+ return SFSafariViewController ( url: url)
20
+ }
21
+
22
+ func updateUIViewController( _ uiViewController: SFSafariViewController , context: Context ) {
23
+ }
24
+ }
12
25
13
26
func downgradeAppToVersion( appId: String , versionId: String , ipaTool: IPATool ) {
14
27
let path = ipaTool. downloadIPAForVersion ( appId: appId, appVerId: versionId)
@@ -35,6 +48,9 @@ func downgradeAppToVersion(appId: String, versionId: String, ipaTool: IPATool) {
35
48
let appVersion = infoPlist [ " CFBundleShortVersionString " ] as! String
36
49
print ( " appBundleId: \( appBundleId) " )
37
50
print ( " appVersion: \( appVersion) " )
51
+
52
+ let finalURL = " https://api.palera.in/genPlist?bundleid= \( appBundleId) &name= \( appBundleId) &version= \( appVersion) &fetchurl=http://127.0.0.1:9090/signed.ipa "
53
+ let installURL = " itms-services://?action=download-manifest&url= " + finalURL. addingPercentEncoding ( withAllowedCharacters: . alphanumerics) !
38
54
39
55
DispatchQueue . global ( qos: . background) . async {
40
56
let server = Server ( )
@@ -44,15 +60,31 @@ func downgradeAppToVersion(appId: String, versionId: String, ipaTool: IPATool) {
44
60
let signedIPAData = try Data ( contentsOf: destinationUrl)
45
61
return HTTPResponse ( body: signedIPAData)
46
62
} )
63
+
64
+ server. route ( . GET, " install " , { _ in
65
+ print ( " Serving install page " )
66
+ let installPage = """
67
+ <script type= " text/javascript " >
68
+ window.location = " \( installURL) "
69
+ </script>
70
+ """
71
+ return HTTPResponse ( . ok, headers: [ " Content-Type " : " text/html " ] , content: installPage)
72
+ } )
47
73
48
74
try ! server. start ( port: 9090 )
49
75
print ( " Server has started listening " )
50
76
51
77
DispatchQueue . main. async {
52
78
print ( " Requesting app install " )
53
- let finalURL = " https://api.palera.in/genPlist?bundleid= \( appBundleId) &name= \( appBundleId) &version= \( appVersion) &fetchurl=http://127.0.0.1:9090/signed.ipa "
54
- let finalURLfr = " itms-services://?action=download-manifest&url= " + finalURL. addingPercentEncoding ( withAllowedCharacters: . alphanumerics) !
55
- UIApplication . shared. open ( URL ( string: finalURLfr) !)
79
+ let majoriOSVersion = Int ( UIDevice . current. systemVersion. components ( separatedBy: " . " ) . first!) !
80
+ if majoriOSVersion >= 18 {
81
+ // iOS 18+ ( idk why this is needed but it seems to fix it for some people )
82
+ let safariView = SafariWebView ( url: URL ( string: " http://127.0.0.1:9090/install " ) !)
83
+ UIApplication . shared. windows. first? . rootViewController? . present ( UIHostingController ( rootView: safariView) , animated: true , completion: nil )
84
+ } else {
85
+ // iOS 17-
86
+ UIApplication . shared. open ( URL ( string: installURL) !)
87
+ }
56
88
}
57
89
58
90
while server. isRunning {
0 commit comments