microsoft / WinObjC

Objective-C for Windows
MIT License
6.24k stars 808 forks source link

Navigate to .html located in app's LocalFolder #2888

Open Liastre opened 6 years ago

Liastre commented 6 years ago

Hello, I'm experiencing issue with WebView right now, the main problem is I need to access temporary files I downloading to LocalFolder, but the WebView placed in bundle folder obviously has no access there, so I decided to create new html right in LocalFolder and navigate to there using navigate API, according to docs i'm able to use ms-appdata://local/ for that. Since i'm using WinObjC I used [UIWebView loadRequest] API https://github.com/Microsoft/WinObjC/blob/979c77ed0fb6ef3a23328cb68fe0e2c35756df85/Frameworks/UIKit/UIWebView.mm#L102 for that purpose, as you know under the hood that uses NavigateWithHttpRequestMessage of _xamlWebControl winrt::Windows::UI::Xaml::FrameworkElement which allow only ms-appx-web:// and http/https prefixes, and another method [UIWebView loadHTMLString] which works via NavigateToString and doesn't allow "ms-appdata" prefix either.

How ever WXCWebView class for example has navigate method inside https://github.com/Microsoft/WinObjC/blob/87178d255e882e4c909774bb25bff3c7c3695a37/include/Platform/Universal%20Windows/UWP/WindowsUIXamlControls.h#L4540 and winrt::Windows::UI::Xaml::FrameworkElement has it too, but it never been used in winobjc framework for UIWebKit.

So, is there way to use navigate method from winobjc or a way to obtain current WebView from C++/CX extension language or maybe convert UIWebView to WXCWebView? Any possible solution would be awesome

Liastre commented 6 years ago

For now I've rebuilt Foundation framework with additional method navigation, here the code I'm using inside:

- (void)navigate:(NSURL*)baseURL {
    NSString* urlStr = [baseURL absoluteString];
    WF::Uri uri = winrt::hstring_view(objcwinrt::string(urlStr));

    _isLoading = true;

    RunSynchronouslyOnMainThread(^{
        _xamlWebControl.Navigate(uri);
    });
}

Works for links like "ms-appx-web://" but not with "ms-appdata://" Link I'am using for navigation: ms-appdata:///local/MobileEngine/index.html

Liastre commented 6 years ago

Got navigation to work, html file seems loaded but with the followed error: DOM7010: Unable to receive a ScriptNotify event from: 'ms-local-stream://3d4medical.comllc.completeanatomy_local_4d6f62696c653344344d456e67696e65/index.html'. The website attempted to send a ScriptNotify event to the app from a WebView URI that is not included in the ApplicationContentUriRules for this app. To permit this event, add the URI to the ApplicationContentUriRules section of the package manifest. (In Visual Studio, add this URI to the Content URIs tab of the Manifest Designer.)

Related topics: https://social.msdn.microsoft.com/Forums/en-US/ae350e1f-cca6-4f9a-ba2c-ab45e7e0ebcf/mslocalstream-asking-to-add-rule-in-app-content-uri-for-windowexternalnotify-windows-81?forum=winappswithhtml5

https://social.msdn.microsoft.com/Forums/sqlserver/en-US/9507fc3b-479f-4998-9490-b305eec7e6b6/uwpdifficult-question-loading-dynamic-html-and-running-script?forum=wpdevelop

Okaay got it, how can I avoid that?