0

I would like to load a local html file from resources into a web view in a applescript objc app. I have added the files to the bundled resources but I'm not sure how to load them into the web view with something like

tell myWebView to setMainFrameURL_("file.html")

sorry for the trivial question, any help would be appreciated

4

1 回答 1

0

要完成这项工作,您必须

  1. WebKit.framework添加到应用程序General Settings的Linked Frameworks and Libraries部分。没有这个,我最终得到错误无法解码类对象(WebView)

  2. 创建一个出口。这是让您的 Applescript 与 UI 元素对话所必需的。

    1. 写入property myWebView : missing value您的AppDelegate.applescript并保存。
    2. 使用 Interface Builder 视图将App Delegate与您的Web视图连接(按住 CTRL 并拖动)并选择myWebView
    3. 现在属性 myWebView直接指向您的 Web 视图。
  3. 告诉 WebView 从应用的资源文件夹中加载您的 HTML 文件:

    set appResourcesPosixPath to POSIX PATH of (path to current application as text) & "Contents/Resources/"
    tell myWebView to setMainFrameURL_(appResourcesPosixPath & "File.html")
    

享受,迈克尔/汉堡

于 2014-10-31T22:50:36.937 回答