小编Amr*_*uta的帖子

cdvfile不支持的URL错误://

问题:

在我的应用程序中,我想通过cordova wkwebview访问图像.HTML元素如下所示.

<img src="cdvfile://localhost/library-nosync/MyFolder/file.jpg">
Run Code Online (Sandbox Code Playgroud)

在加载时,我收到错误"无法加载资源:不支持的URL".我正在使用iOS 10.2.

经验证/尝试的事情:

如果选中"myFolder"文件夹下"cordova.file.dataDirectory"中的文件列表,我确实会看到"file.jpg".它的原生URL为file:///var/mobile/Containers/Data/Application/app_id/Library/NoCloud/MyFolder/file.jpg.

我在Content-Security-Policy中添加了"img-src'self'cdvfile:".

我在config.xml中添加了以下内容

<access origin="cdvfile://*" /> 
<allow-navigation href="cdvfile://*" /> 
<allow-intent href="cdvfile://*" />
<preference name="iosPersistentFileLocation" value="Compatibility" />
<preference name="iosExtraFilesystems" value="library,library-nosync,documents,documents-nosync,cache,bundle,root" />
Run Code Online (Sandbox Code Playgroud)

URL中没有特殊(非ASCII)字符,如与此错误相关的线程中所述.还有什么可能是"不支持的URL"的原因?

我访问cdvfile://路径的方式是不正确的?

更新

我遇到了一个链接(忘了捕获),说webview需要相对路径,因此cdvfile://不起作用.我尝试将图像源更改为相对路径,将其更改为"../../../../../../../../..//var/mobile/Containers/数据/应用程序/ app-id/Library/NoCloud/MyFolder/file.jpg"我现在可以看到一个新错误 - "无法加载资源:操作无法完成.操作不允许"

我可以通过"读取"文件的内容并将该base64数据作为图像源传递来使图像工作.但那应该是怎么回事,不是吗?

ios cordova wkwebview cordova-plugin-file

7
推荐指数
2
解决办法
2449
查看次数

从JavaScript调用swift方法会挂起xcode和应用程序

我正在使用JavascriptCode框架编写iOS应用程序(使用xcode 7.3和swift 2.2).从swift调用javascript方法是完美的,但是当我从javascript调用swift方法时,xcode只显示一个"加载"类型的符号,没有任何反应.我需要"强制退出"xcode才能摆脱这种状态.我已经关注https://www.raywenderlich.com/124075/javascriptcore-tutorialhttp://nshipster.com/javascriptcore/,我正在尝试非常简单的电话.

有没有人遇到过这种问题?

我的快捷代码如下:

@objc protocol WindowJSExports : JSExport {
   var name: String { get set }
   func getName() -> String
   static func createWindowWithName(name: String) -> WindowJS
}

@objc class WindowJS : NSObject, WindowJSExports {
   dynamic var name: String
   init(name: String) {
       self.name = name
   }    
   class func createWindowWithName(name: String) -> WindowJS {
       return WindowJS(name: name)
   }    
   func getName() -> String {
       NSLog("getName called from JS context")
       return "\(name)"
   }
} 
Run Code Online (Sandbox Code Playgroud)

我正在初始化上下文如下:

runContext = JSContext() …
Run Code Online (Sandbox Code Playgroud)

xcode hang javascriptcore swift

6
推荐指数
1
解决办法
1184
查看次数

在Xamarin中使用Swift库

文章https://developer.xamarin.com/guides/cross-platform/macios/binding/提到了如何在Xamarin中使用使用Objective-C编写的本机库.是否有任何文档可用于使用Swift编写的本机框架执行相同的操作?https://developer.xamarin.com/guides/ios/advanced_topics/embedded_frameworks/讨论了使用嵌入式框架,但它没有提及任何关于swift的内容.同样的事情有效吗?

binding xamarin swift

5
推荐指数
1
解决办法
4877
查看次数