Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use html file in ios webview #1625

Merged
merged 4 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions demos/ios-webview/procaptcha.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
6093CEA72CA96BB9006699D1 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6093CEA62CA96BB9006699D1 /* ContentView.swift */; };
6093CEA92CA96BBD006699D1 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 6093CEA82CA96BBD006699D1 /* Assets.xcassets */; };
6093CEAD2CA96BBD006699D1 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 6093CEAC2CA96BBD006699D1 /* Preview Assets.xcassets */; };
CE79A1EA2D38EC2200047A40 /* procaptcha.html in Resources */ = {isa = PBXBuildFile; fileRef = CE79A1E92D38EC2200047A40 /* procaptcha.html */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand All @@ -20,6 +21,7 @@
6093CEA82CA96BBD006699D1 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
6093CEAA2CA96BBD006699D1 /* procaptcha.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = procaptcha.entitlements; sourceTree = "<group>"; };
6093CEAC2CA96BBD006699D1 /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = "<group>"; };
CE79A1E92D38EC2200047A40 /* procaptcha.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = procaptcha.html; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -55,6 +57,7 @@
6093CEA42CA96BB9006699D1 /* procaptchaApp.swift */,
6093CEA62CA96BB9006699D1 /* ContentView.swift */,
6093CEA82CA96BBD006699D1 /* Assets.xcassets */,
CE79A1E92D38EC2200047A40 /* procaptcha.html */,
6093CEAA2CA96BBD006699D1 /* procaptcha.entitlements */,
6093CEAB2CA96BBD006699D1 /* Preview Content */,
);
Expand Down Expand Up @@ -127,6 +130,7 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
CE79A1EA2D38EC2200047A40 /* procaptcha.html in Resources */,
6093CEAD2CA96BBD006699D1 /* Preview Assets.xcassets in Resources */,
6093CEA92CA96BBD006699D1 /* Assets.xcassets in Resources */,
);
Expand Down Expand Up @@ -282,6 +286,7 @@
"LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = "@executable_path/../Frameworks";
MACOSX_DEPLOYMENT_TARGET = 13.3;
MARKETING_VERSION = 1.0;
NSExceptionAllInsecureHTTPLoads = YES;
PRODUCT_BUNDLE_IDENTIFIER = io.prosopo.procaptcha;
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = auto;
Expand Down Expand Up @@ -320,6 +325,7 @@
"LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = "@executable_path/../Frameworks";
MACOSX_DEPLOYMENT_TARGET = 13.3;
MARKETING_VERSION = 1.0;
NSExceptionAllInsecureHTTPLoads = YES;
PRODUCT_BUNDLE_IDENTIFIER = io.prosopo.procaptcha;
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = auto;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict/>
</plist>
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>BuildLocationStyle</key>
<string>UseAppPreferences</string>
<key>CustomBuildLocationType</key>
<string>RelativeToDerivedData</string>
<key>DerivedDataLocationStyle</key>
<string>Default</string>
<key>ShowSharedSchemesAutomaticallyEnabled</key>
<true/>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>SchemeUserState</key>
<dict>
<key>procaptcha.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
</dict>
</dict>
</dict>
</plist>
28 changes: 6 additions & 22 deletions demos/ios-webview/procaptcha/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import SwiftUI
import WebKit

struct WebView: UIViewRepresentable {
let htmlString: String
let filePath: String

func makeCoordinator() -> Coordinator {
return Coordinator(self)
Expand Down Expand Up @@ -49,8 +49,10 @@ struct WebView: UIViewRepresentable {
webView.isInspectable = true

//DispatchQueue.main.asyncAfter(deadline: .now() + 30) {
// baseURL must be set for localstorage to work. If localstorage is not required, it can be set to nil. Localstorage errors appear like "SecurityError: The operation is insecure."
webView.loadHTMLString(htmlString, baseURL: URL(string: "https://prosopo.io"))
guard let fileUrl = Bundle.main.url(forResource: filePath, withExtension: nil) else {
fatalError("html file \(filePath) not found")
}
webView.loadFileURL(fileUrl, allowingReadAccessTo: fileUrl.deletingLastPathComponent())
//}

return webView
Expand Down Expand Up @@ -89,25 +91,7 @@ struct ContentView: View {
var body: some View {
VStack {
Text("Demo Procaptcha:")
WebView(htmlString: """
<html>
<head>
<title>Procaptcha</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<script type="module" src="https://js.prosopo.io/js/procaptcha.bundle.js" async defer></script>
</head>
<body>
<form action="" method="POST">
<input type="text" name="email" placeholder="Email" />
<input type="password" name="password" placeholder="Password" />
<p>image</p>
<div class="procaptcha" data-sitekey="5FWCbfR7pH9QiZqLgmm5Rw4QbFwyU5EaMqUV4G6xrvrTZDtC" data-captcha-type="image"></div>
<br />
<input type="submit" value="Submit" />
</form>
</body>
</html>
""")
WebView(filePath: "procaptcha.html")
}
.padding()
}
Expand Down
17 changes: 17 additions & 0 deletions demos/ios-webview/procaptcha/procaptcha.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<html><div style='width:100%;height:100px'></div>
<head>
<title>Procaptcha</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<script type="module" src="https://js.prosopo.io/js/procaptcha.bundle.js" async defer></script>
</head>
<body>
<form action="" method="POST">
<input type="text" name="email" placeholder="Email" />
<input type="password" name="password" placeholder="Password" />
<div class="procaptcha" data-sitekey="5FWCbfR7pH9QiZqLgmm5Rw4QbFwyU5EaMqUV4G6xrvrTZDtC" data-captcha-type="image"></div>
<br />
<input type="submit" value="Submit" />
</form>
</body>
</html>

Loading