相关疑难解决方法(0)

Cordova iOS视频标签本地文件源

我在基于Cordova的应用程序上在iOS上播放本地视频时遇到问题.一开始我想强调,只有当我使用WKWebView时才会出现这个问题,如果使用UiWebView,视频播放就可以了.这是我的情景:

- 用户进入屏幕传递视频网址

-Via FileTransfer我将其下载到手机并将其存储在所需位置

- 使用JS视频加载<video>标记和播放.

基本上我正在回答这个问题所描述的一切.UiWebView的问题是,如果相对路径设置为src,由于某种原因无法加载视频(无论我使用哪种组合),所以这个解决方案对我很有用,因为它基于这行代码:

entry.toURL()
Run Code Online (Sandbox Code Playgroud)

这将返回下载视频的完整路径,这很好,至少对于UiWebView.

WkWebView的问题是entry.toURL()返回smth.像这样:

file:///var/mobile/Containers/Data/Application/3A43AFB5-BEF6-4A0C-BBDB-FC7D2D98BEE9/Documents/videos/Dips.mp4
Run Code Online (Sandbox Code Playgroud)

并且WKWebView不适用于file://协议.此外,WKWebView都不适用于相对路径:(

任何人都可以帮我解决这个问题吗?

video html5-video ios cordova phonegap-build

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

Swift WKWebView加载本地文件无法在设备上运行

我试图在iPad(或任何设备)上运行我的应用程序时遇到一些问题,它在模拟器上按预期运行,因此它在设备上不起作用很奇怪.我想知道是否有人可以指出我正确的方向.我花了很多时间阅读这里关于相同问题的所有其他帖子,但是没有一个建议的解决方案有效.

我有一个WKWebView,我正在加载一个本地的html文件.在模拟器上加载文件并且一切正常但在设备上我在日志中收到一条消息:

无法为'/'创建沙箱扩展名

这是我将文件加载到的代码

override func viewDidLoad() {
    super.viewDidLoad()
    var path = NSBundle.mainBundle().pathForResource("Login_UK",
        ofType: "html")
    var url = NSURL(fileURLWithPath: path!)
    var request = NSURLRequest(URL: url!)

    var theConfiguration = WKWebViewConfiguration()
    theConfiguration.userContentController.addScriptMessageHandler(self,
        name: "callbackHandler")

    webView = WKWebView(frame: self.view.frame,
        configuration: theConfiguration)
    webView!.loadRequest(request)
    self.view.addSubview(webView!)
}
Run Code Online (Sandbox Code Playgroud)

任何帮助将不胜感激

亲切的问候,Dimitar

web-applications objective-c webview ios swift

5
推荐指数
2
解决办法
8939
查看次数

加速加载WKWebView

正如解释在这里,WKWebView有一个bug,从而捆绑本地的网页应用程序都捆绑复制到tmp目录中.我将包复制到的代码tmp是:

// Clear tmp directory
NSArray* temporaryDirectory = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:NSTemporaryDirectory() error:NULL];
for (NSString *file in temporaryDirectory) {
    [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@%@", NSTemporaryDirectory(), file] error:NULL];
}

NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *sourcePath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"build"];
NSString *temporaryPath = [NSTemporaryDirectory() stringByAppendingPathComponent:@"build"];
NSError *error = nil;

// Copy directory
if(![fileManager copyItemAtPath:sourcePath toPath:temporaryPath error:&error]) {
    [self logError:@"Could not copy directory" :error];
}
Run Code Online (Sandbox Code Playgroud)

我已经定时了这个特定的代码片段,它占用了我应用程序启动时间的50%!(约0.5s,总共~1s.)

有没有办法在iOS 8下加速(或完全避免)这个特定的代码片段?线程可以帮忙吗?

performance startup ios ios8 wkwebview

5
推荐指数
2
解决办法
3955
查看次数

WKWebView不会在设备上打开本地pdf文件,但会在Xcode Simulator中打开

我正在尝试打开我存储在设备上的PDF。这些文件在Xcode Simulator中打开,但在iPhone上不打开。

这些是我所知道的:

  • 文件在那里,我可以通过contentsOfDirectory看到它们
  • 如果它们是http链接,则可以使用相同的代码打开网页,但如果它们是https链接,则不能打开网页
  • 我也可以从网上打开pdf文件(如果它们位于https链接中),但不能打开为http时

这是某种安全问题吗?我能做什么?谢谢!

let documentDirectory = URL(fileURLWithPath: NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0])
var pdfToOpen: URL!
var fileName = "fileName.pdf"

override func viewDidLoad() {
    super.viewDidLoad()
    pdfToOpen = documentDirectory.appendingPathComponent(fileName)
    openPDF(pdfToOpen)
    }

func openPdf(input: URL?) {
        if let url = input {
                let webView = WKWebView(frame: CGRect(x: 0, y: 20, width: self.view.frame.width, height: self.view.frame.height-20))
                let urlRequest = URLRequest(url: url)
                webView.load(urlRequest as URLRequest)
                self.view.addSubview(webView)
        }
Run Code Online (Sandbox Code Playgroud)

pdf swift wkwebview

5
推荐指数
0
解决办法
1380
查看次数

WKWebView使用LoadFileUrl加载本地内容

我正在尝试使用LoadFileUrl方法在WKWebView中加载本地html文件,但我得到的只是一个空白视图.这是一个Xamarin.Mac应用程序(还没有Sandbox).

WKWebViewConfiguration conf = new WKWebViewConfiguration();
WKWebView www = new WKWebView (View.Frame, conf);
View = www;

string index = Path.Combine (NSBundle.MainBundle.BundlePath, "WebApp/Index.html");
string webAppFolder = Path.Combine (NSBundle.MainBundle.BundlePath, "WebApp");

www.LoadFileUrl (new NSUrl ("file://"+index), new NSUrl ("file://"+webAppFolder));
Run Code Online (Sandbox Code Playgroud)

使用"LoadRequest"从远程服务器加载网页工作得很好.

"Index.html"文件的构建操作是"BundleResource"

感谢你的帮助!

c# xamarin xamarin.mac wkwebview

3
推荐指数
1
解决办法
2906
查看次数

加载本地文件在模拟器中工作正常但在设备上崩溃

使用WKWebview播放本地文件在模拟器上工作,但在设备上给我这个错误(iOS 9.2.1)

fail in didFailProvisionalNavigation Error Domain=NSPOSIXErrorDomain Code=1 "Operation not permitted"
UserInfo={NSErrorFailingURLKey=file:///var/mobile/Containers/Data/Application/2FBE4DE6-9441-4C5A-BB1F-8598CA89664C/Documents/courses/agdg_test1455704820291/index.html?jqueryFilePath=file:///var/mobile/Containers/Bundle/Application/5A442D34-3360-46C7-8B28-B6F3AED373CE/elearning.app/view/jquery.js&commandsFilePath=file:///var/mobile/Containers/Bundle/Application/5A442D34-3360-46C7-8B28-B6F3AED373CE/elearning.app/view/commands.js,
_WKRecoveryAttempterErrorKey=<WKReloadFrameErrorRecoveryAttempter: 0x15e295f0>,NSErrorFailingURLStringKey=file:///var/mobile/Containers/Data/Application/2FBE4DE6-9441-4C5A-BB1F-8598CA89664C/Documents/courses/agdg_test1455704820291/index.html?jqueryFilePath=file:///var/mobile/Containers/Bundle/Application/5A442D34-3360-46C7-8B28-B6F3AED373CE/elearning.app/view/jquery.js&commandsFilePath=file:///var/mobile/Containers/Bundle/Application/5A442D34-3360-46C7-8B28-B6F3AED373CE/elearning.app/view/commands.js}
Run Code Online (Sandbox Code Playgroud)

这是配置webView的代码:

let lesson:NSMutableArray = courseDB_Manager.getInstance().getRowDB("SELECT * FROM lesson_chapter WHERE lesson_chapter_id = ?", args: [chapterToPlay], structType: "lesson_chapter")
let occ: lesson_chapter_struct = lesson[0] as! lesson_chapter_struct
fileToPlay = Utility.getPath("courses/" + occ.lesson_chapter_fichier)

let commandsFilePath = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("commands", ofType: "js", inDirectory: "view")!, isDirectory: false)
let jqueryFilePath = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("jquery", ofType: "js", inDirectory: "view")!, isDirectory: false)

let target = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("start", ofType: "html", inDirectory: "view")!, isDirectory: false)
let params = "?fileToPlay=" + …
Run Code Online (Sandbox Code Playgroud)

uiwebview ios

3
推荐指数
1
解决办法
3842
查看次数