我在用 swift 编写的 iOS 应用程序中创建了一个本地 HTML 文件。HTML 文件被加载到 WKWebView 中,如下所示:
let url = Bundle(identifier: myIdentifier).url(forResource: "localHtmlFile", withExtension: "html")
let htmlFormatString = try String(contentsOf: url)
loadHTMLString(string: htmlFormatString, baseURL: nil)
Run Code Online (Sandbox Code Playgroud)
HTML 页面包含一个 iframe,我希望它加载一个外部页面:
<div>Test</div>
<iframe src="https://www.somepage.com"></iframe>
Run Code Online (Sandbox Code Playgroud)
本地HTML文件加载成功,可以看到Testdiv中的文字。iframe 也已创建,但为空。如果我使用 Safari Developer Tools 进行调试,则只有一个空的 html 页面,但没有加载任何内容。此外,根本不执行对 url 的网络请求。
但是如果我插入一个带有 的外部 JavaScript 文件<script src="https://url-to-some-js">,则 JS 代码将成功加载,因此没有网络问题。另外,如果我直接用 加载 url webView.load(URLRequest(url: url)),它工作正常。仅在 iframe 内,它不起作用。
如何为在 iOS WKWebView 中工作的外部资源制作 iframe?这完全被iOS阻止了还是我必须配置其他东西?
我已经使用visionKit 实现了文档扫描仪。最初我遇到了相机关闭问题并且它已修复。现在我试图在相机从框架中关闭后将图像发送到示例项目。
我试过使用完成处理程序,但它不起作用。
这是框架的代码:
public class A8Scan: NSObject, VNDocumentCameraViewControllerDelegate {
var imageNew: UIImage?
var statusImage: UIImageView?
private var clientView: UIViewController?
public init(_ viewController:UIViewController){
self.clientView = viewController
}
public func showScanner(imgData: UIImage?){
self.createTaskController(img: imgData)
print("Called Build")
}
private func createTaskController(img: UIImage?){
let scannerViewController = VNDocumentCameraViewController()
scannerViewController.delegate = self
self.clientView?.present(scannerViewController,animated:true,completion: {
self.imageNew = img
})
}
public func imageFromFile(result: @escaping (_ image: UIImage?) -> Void){
//the image
let scannerViewController = VNDocumentCameraViewController()
scannerViewController.delegate = self
self.clientView?.present(scannerViewController,animated:true,completion: nil)
if imageNew != nil {
result(imageNew) …Run Code Online (Sandbox Code Playgroud) 这是我的JSON响应值:
{
"_embedded": {
"task": [
{
"_embedded": {
"variable": [
{
"_links": {
"self": {
"href": "/process-instance/412a03b7-06ae-11ea-8860-120ef5ab2c25/variables/loanAmount"
}
},
"_embedded": null,
"name": "loanAmount",
"value": "650000",
"type": "String",
"valueInfo": {}
}
]
},
"id": "412a2aca-06ae-11ea-8860-120ef5ab2c25",
"name": "Quick Evaluation",
"assignee": "demo",
"created": "2019-11-14T07:13:27.558+0000",
"processDefinitionId": "quickEvaluation:1:129ce2b1-0616-11ea-8860-120ef5ab2c25"
}
]
},
"count": 13
}
Run Code Online (Sandbox Code Playgroud)
这是struct可编码的代码:
import Foundation
public struct TaskID: Codable {
let embedded: Embedded
}
public struct Embedded: Codable {
let task: [Task]
}
public struct Task : Codable {
let embedded: EmbeddedVariable …Run Code Online (Sandbox Code Playgroud) 我尝试使用套接字连接服务器,但它拒绝连接。在这里,我尝试发送带有基本 URL 的查询参数(令牌)来连接服务器。但仍然没有连接。
这是控制台输出错误:
manager <SocketIO.SocketManager: 0x283542f00>
2020-01-23 17:59:12.872248+0530 A8FlowSampleApp[34442:7736351] LOG SocketIOClient{/}: Handling event: statusChange with data: [connecting, 2]
2020-01-23 17:59:12.872415+0530 A8FlowSampleApp[34442:7736351] LOG SocketIOClient{/}: Joining namespace /
2020-01-23 17:59:12.872543+0530 A8FlowSampleApp[34442:7736351] LOG SocketManager: Tried connecting socket when engine isn't open. Connecting
2020-01-23 17:59:12.872621+0530 A8FlowSampleApp[34442:7736351] LOG SocketManager: Adding engine
2020-01-23 17:59:12.873836+0530 A8FlowSampleApp[34442:7736455] LOG SocketEngine: Starting engine. Server: https://base url/event-stream/
2020-01-23 17:59:12.874735+0530 A8FlowSampleApp[34442:7736455] LOG SocketEngine: Handshaking
2020-01-23 17:59:13.452879+0530 A8FlowSampleApp[34442:7736457] ERROR SocketEngine: Invalid HTTP upgrade. code=404, type=upgradeError
2020-01-23 17:59:13.455416+0530 A8FlowSampleApp[34442:7736351] LOG SocketIOClient{/}: Handling event: …Run Code Online (Sandbox Code Playgroud) 我正在研究框架。在框架内部,我在 Xib 中创建了UIViewController -> UICollectionView。为 UICollectionView 单元格创建了单独的 Xib。并将单元格注册为“TaskCollectionViewCell”
我尝试为 collectionView 注册 nib,它崩溃并显示无法在捆绑包中加载 NIB:NSBundle
这是我的 UIViewController -> UICollectionView 代码:
override public func viewDidLoad() {
super.viewDidLoad()
self.collectionView.delegate = self
self.collectionView.dataSource = self
self.collectionView.register(UINib(nibName: "TaskCollectionViewCell", bundle: nil), forCellWithReuseIdentifier: "TaskCollectionViewCell")
}
public func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 10
}
public func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "TaskCollectionViewCell", for: indexPath) as! TaskCollectionViewCell
return cell
}
Run Code Online (Sandbox Code Playgroud)
控制台错误:
2019-11-12 12:08:00.487285+0530 …Run Code Online (Sandbox Code Playgroud) ios ×5
swift ×5
xcode ×3
alamofire ×1
delegates ×1
frameworks ×1
iframe ×1
json ×1
jsondecoder ×1
socket.io ×1
uiimageview ×1
websocket ×1
wkwebview ×1
xib ×1