ts-glitter 20.6.9 → 20.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -52,11 +52,13 @@ class Ecommerce{
52
52
  // 创建HTML文件并在浏览器中打开
53
53
  if let fileURL = createHTMLFile() {
54
54
  request.glitterAct.openWeb(string: fileURL.absoluteString)
55
+
55
56
  } else {
56
57
  print("Failed to create HTML file.")
57
58
  }
58
59
 
59
60
  }))
61
+
60
62
  GlitterActivity.sharedInterFace.append(JavaScriptInterFace(functionName: "check_out_finish", function: {
61
63
  request in
62
64
  request.glitterAct.dismiss(animated: true)
@@ -143,5 +145,59 @@ class Ecommerce{
143
145
  }
144
146
  }
145
147
  }))
148
+
149
+
150
+ GlitterActivity.sharedInterFace.append(JavaScriptInterFace(functionName: "post_form", function: {
151
+ request in
152
+ checkOutInstance=request
153
+ let htmlContent = """
154
+
155
+ <!DOCTYPE html>
156
+ <html lang="zh-TW">
157
+ <head>
158
+ <meta charset="UTF-8">
159
+ <title>My HTML Page</title>
160
+ </head>
161
+ <body>
162
+ <div id="ddd" style="display: none;">\(request.receiveValue["form"] as! String)</div>
163
+ <script>
164
+ window.webkit.messageHandlers.addJsInterFace.postMessage(
165
+ JSON.stringify({
166
+ functionName: 'is_application',
167
+ callBackId: 0,
168
+ data: {},
169
+ })
170
+ );
171
+ document.querySelector(`#ddd #submit`).click();
172
+ </script>
173
+ </body>
174
+ </html>
175
+ """
176
+ // 函数:创建HTML文件
177
+ func createHTMLFile() -> URL? {
178
+ // 获取用户的文档目录
179
+ let documentsDirectory = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!
180
+ // 创建文件路径
181
+ let fileURL = documentsDirectory.appendingPathComponent("checkout.html")
182
+
183
+ do {
184
+ // 将HTML内容写入磁盘
185
+ try htmlContent.write(to: fileURL, atomically: true, encoding: .utf8)
186
+ return fileURL
187
+ } catch {
188
+ print("Error writing HTML to file: \(error)")
189
+ return nil
190
+ }
191
+ }
192
+ // 创建HTML文件并在浏览器中打开
193
+ if let fileURL = createHTMLFile() {
194
+ request.glitterAct.openWeb(string: fileURL.absoluteString)
195
+ } else {
196
+ print("Failed to create HTML file.")
197
+ }
198
+
199
+ }))
200
+
201
+
146
202
  }
147
203
  }
@@ -13,26 +13,30 @@ import SnapKit
13
13
  import UIKit
14
14
  import Glitter_IOS
15
15
  import FirebaseMessaging
16
+ import WebKit
17
+
18
+
16
19
  class ViewController: UIViewController {
17
20
 
18
21
  public static var vc:ViewController? = nil
19
22
  public static var redirect:String = ""
23
+ public static var agent="iosGlitter Mozilla/5.0 (iPhone; CPU iPhone OS 18_3_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.3 Mobile/15E148 Safari/604.1"
20
24
  public let webView = GlitterActivity.create(glitterConfig: GlitterActivity.GlitterConfig(parameters:"?a=1",projectRout: URL(string: "${domain}/index-app")! )).initWkWebView()
21
-
22
25
  override func viewDidLoad() {
23
26
  webView.webView!.allowsBackForwardNavigationGestures = true;
24
27
  NotificationCenter.default.addObserver(self, selector: #selector(keyBoardWillShow(notification:)), name: UIResponder.keyboardWillShowNotification, object: nil)
25
28
  NotificationCenter.default.addObserver(self, selector: #selector(keyBoardWillHide(notification:)), name: UIResponder.keyboardWillHideNotification, object: nil)
26
29
  ViewController.vc=self
27
- if(ViewController.redirect != ""){
28
- webView.webView!.evaluateJavaScript("""
29
- location.href=new URL("\(ViewController.redirect)",location.href)
30
- """)
31
- }
30
+
32
31
  self.view.backgroundColor = .white
32
+
33
+ webView.webView!.customUserAgent=ViewController.agent
33
34
  super.viewDidLoad()
35
+
34
36
  }
35
37
 
38
+
39
+
36
40
  override func viewWillAppear(_ animated: Bool) {
37
41
  self.view.addSubview(self.webView.view)
38
42
  }
@@ -71,6 +75,8 @@ extension UIViewController {
71
75
  }
72
76
  }
73
77
 
78
+
79
+
74
80
  `;
75
81
  }
76
82
  }
@@ -1 +1 @@
1
- {"version":3,"file":"ios-project.js","sourceRoot":"","sources":["ios-project.ts"],"names":[],"mappings":";;;AAAA,MAAa,UAAU;IAEZ,MAAM,CAAC,iBAAiB,CAAC,MAAa;QACjD,OAAO;;;;;;;;;;;;;;2IAcoI,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAsDhJ,CAAA;IACG,CAAC;CACJ;AAzED,gCAyEC"}
1
+ {"version":3,"file":"ios-project.js","sourceRoot":"","sources":["ios-project.ts"],"names":[],"mappings":";;;AAAA,MAAa,UAAU;IAEZ,MAAM,CAAC,iBAAiB,CAAC,MAAa;QACjD,OAAO;;;;;;;;;;;;;;;;;;2IAkBoI,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAwDhJ,CAAA;IACG,CAAC;CACJ;AA/ED,gCA+EC"}
@@ -11,26 +11,30 @@ import SnapKit
11
11
  import UIKit
12
12
  import Glitter_IOS
13
13
  import FirebaseMessaging
14
+ import WebKit
15
+
16
+
14
17
  class ViewController: UIViewController {
15
18
 
16
19
  public static var vc:ViewController? = nil
17
20
  public static var redirect:String = ""
21
+ public static var agent="iosGlitter Mozilla/5.0 (iPhone; CPU iPhone OS 18_3_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.3 Mobile/15E148 Safari/604.1"
18
22
  public let webView = GlitterActivity.create(glitterConfig: GlitterActivity.GlitterConfig(parameters:"?a=1",projectRout: URL(string: "${domain}/index-app")! )).initWkWebView()
19
-
20
23
  override func viewDidLoad() {
21
24
  webView.webView!.allowsBackForwardNavigationGestures = true;
22
25
  NotificationCenter.default.addObserver(self, selector: #selector(keyBoardWillShow(notification:)), name: UIResponder.keyboardWillShowNotification, object: nil)
23
26
  NotificationCenter.default.addObserver(self, selector: #selector(keyBoardWillHide(notification:)), name: UIResponder.keyboardWillHideNotification, object: nil)
24
27
  ViewController.vc=self
25
- if(ViewController.redirect != ""){
26
- webView.webView!.evaluateJavaScript("""
27
- location.href=new URL("\(ViewController.redirect)",location.href)
28
- """)
29
- }
28
+
30
29
  self.view.backgroundColor = .white
30
+
31
+ webView.webView!.customUserAgent=ViewController.agent
31
32
  super.viewDidLoad()
33
+
32
34
  }
33
35
 
36
+
37
+
34
38
  override func viewWillAppear(_ animated: Bool) {
35
39
  self.view.addSubview(self.webView.view)
36
40
  }
@@ -69,6 +73,8 @@ extension UIViewController {
69
73
  }
70
74
  }
71
75
 
76
+
77
+
72
78
  `
73
79
  }
74
80
  }