"> a few questions and googled for d...">

Local OSX Swift webview download file

I know this has been asked many times, and I read a href = " <a 1> "> a few questions and googled for days without success so far.

I just want to load a local html file in a desktop application, however, for this project I need a JS library, and most of it is already running as a web page (css, js and html, server side processing is not required), I don’t want to force application to download a web page from an Internet server so as not to force users to have an Internet connection. Needless to say, I'm completely inexperienced in developing Swift and Apple.

Right now this is the problem I am facing: enter image description here complaints about the parameters, and I cannot understand them correctly.

For reference, here is a snippet of my last code:

class AppDelegate: NSObject, NSApplicationDelegate
{
    @IBOutlet weak var window: NSWindow!
    @IBOutlet weak var webView: WebView!
    typealias NSSize = CGSize

    func applicationDidFinishLaunching(aNotification: NSNotification?)
    {
        self.window.title = "Chess Study Room"

        var try1 = "main.html";
        println(try1);

        var try2 = NSURL(string: try1)!;
        println(try2);

        var try3 =
        NSBundle.URLForResource("main", withExtension: "html", subdirectory: "web", inBundleWithURL: try2);
        println(try3);

        var try4 = NSBundle.pathForResource("main", ofType: "html", inDirectory: "web");
        println(try4);

        var try5 = NSString.stringByAppendingPathComponent("main.html");
        println(try5);
        // var myInternalUrl = NSURL(string: myInternalHtml)!;
        //NSLog("%s", myInternalHtml!);
        var request = NSURLRequest(try1,
            NSURLRequestCachePolicy.ReloadIgnoringLocalAndRemoteCacheData,
            60
        );

        self.webView.frameLoadDelegate = self;
        self.webView.mainFrame.loadRequest(
            request!
        );
    }

But, as you can see from my gif, I also tried other things. Complete errors: /path/TestWebView/AppDelegate.swift:32:35: Extra argument in calland/path/TestWebView/AppDelegate.swift:32:36: Missing argument for parameter 'cachePolicy' in call

At this point, try1 and try2 output "main.html", try3 and try4 output nil and try5 outputs "(Function)"

The folder structure is as follows: enter image description here

I added the "web" folder as a link (as was said in another question), but I doubt it will work to send just one package ...

I don’t know if there is a difference, but I am not targeting iOS, I want this to be a desktop application.

Any recommendations would be greatly appreciated.

+4
source share
1 answer

:

func applicationDidFinishLaunching(aNotification: NSNotification?)
    {
        self.window.title = "My App Title"

        var try6 = NSURL(fileURLWithPath:NSBundle.mainBundle().pathForResource("main", ofType:"html")!)

        var request = NSURLRequest(URL: try6!);

        self.webView.frameLoadDelegate = self;
        self.webView.mainFrame.loadRequest(request);
    }
+3

All Articles