WebView vs WKWebView on OSX - macos

Apple's documentation suggests using WkWebView for new development, although it seems to have a typo where it recommends WKWebView over UIWebView in the mac developer library.
For new development, employ this class instead of the older UIWebView class.
The typo is probably because they are trying to unify the OSX and iOS interface to the web view by using the same header for both.
However, WKWebView doesn't have all the functionality that WebView has in OSX. For example, you can get access to DOM nodes in the native interface in WebView but I don't see any way of doing this from Swift/Objective-C in WKWebView.
For my purposes, it seems like WebView is what I need, but I'm weary of starting a project that relies on an API that will be removed. However, I don't see any mention of intent to deprecate WebView anywhere in the headers or the documentation.
What makes this even more confusing is the WebKit Framework Reference makes reference to both WK and older web view APIs without clarifying anything.
WKWebView
A WKWebView object displays interactive web content, such as for an in-app browser.
WebView
WebView is the core view class in the WebKit framework that manages interactions between the WebFrame and WebFrameView classes.
Is WebView going away in OSX?

Its not a false alarm. Apple moved Safari off of UIWebView/WebView in 6.0, so security fixes simply aren't happening in the old class as much. For that reason alone you should not use it for new stuff. Apple has been incrementally improving it with every OS release so much is now do-able with private extensions (file:// access, downloads, etc)
That being said, it won't be fully equivalent to old WebView. You can't directly access the DOM anymore because the Network/Rendering/UI processes were split up and you create locks by making element references like that. Use the postMessage() message handler and wkwebview.evaluateJavaScript() and callback-ish/promisy JS code between those two pillars to deal with web<>native interaction asynchronously.

Important
Starting in iOS 8.0 and OS X 10.10, use WKWebView to add web content to your app.
Do not use UIWebView or WebView.
https://developer.apple.com/documentation/webkit/wkwebview

Related

Xamarin WebView erroneous CanGoBack on single-page app

I'm new to mobile app dev, so I'm not sure whether this is Xamarin related, or is it just a general limitation on webview controls, or whether this is specific to Android (only tested it on android...), or whether its me just not understanding the underlying tech thoroughly :)
I'm building an app that has a WebView to some site.
The site is built with AngularJS and utilizes the HistoryAPI for manipulating navigation.
I started experimenting with Xamarin for the implementation.
I used the WebView sample and just updated the url to point to my site.
But it seems the sample is not functioning as it should for navigation.
The CanGoBack getter always returns false on my site and it seems to be related to the historyApi navigation...
One more note - if I bypass the CanGoBack and just call GoBack the view actually goes back to previous page, but of course this is unacceptable...

How can Xamarin be used to wrap a web app as if it were a native app for Android?

Say I build a super mobile friendly web application that I want in the Play Store for Android users to be able to download.
Could I use Xamarin to:
Wrap the entire mobile app as a single WebView
Register for mobile push notifications
Essentially shortlining an MVP of an android app by using an existing web app? If so, is there any well-known process or documentation that demonstrates this?
Probably the best approach for you would be using Xamarin Forms with one or more pages containing only web views.
I don't love Xamarin Forms because usually for me Xamarin Android+iOS gives a better result in similar time, but your app would be so simple that doesn't make sense to do it with Xamarin Android.
Make sure that your web app will show only what makes sense to be shown in your app, otherwise you risk to see double header/footer, useless buttons... but if the website is yours adding a few parameters to change a bit the UI won't be a problem I guess.
Have a look at this example:
https://github.com/xamarin/xamarin-forms-samples/tree/master/WorkingWithWebview
Another approach is the use of Razor to build your pages in html directly inside your app, but if I understood well it's not what you need:
https://developer.xamarin.com/guides/cross-platform/advanced/razor_html_templates/
Although it is technically possible to do this as the previous answer has suggested. I would recommended firstly reviewing, the relevant stores guidelines on submissions. Apple for example will not allow a submission to their store of any application that simply mirrors the functionality of a website. I suspect Google's would likely be the same.
However that said, to answer your question, Xamarin.Forms would be appropriate for a simple application like the one you are suggesting. Or if you prefer to build to a specific OS, then in iOS with Xamarin you would use the Safari View Controller that was added in it's xcode 8.1 release. Android uses something similar as does windows.
EDIT:
You can use the Web View control in Xamarins Andorid native PCL project to encapsulate your mobile friendly website within an application here is the documentation:
Xamarin Android Developer link to Android Web View
As for push notifications, yes this is perfectly possible using Xamarin.Android. and varies on implementation depending on what you want to use as the back end to handle them, I.E. Azure's notification hub etc.

Xamarin - create an environment to view HTML files

I have only written PC programs using C#, .NET, and WinForms, and am new to app development.
I have written a program that uses HTML files (as a type of "form"), that will then be passed to an app, which can then be used to read/record data. I.e.
On the PC, a user creates a HTML "form"
This is loaded onto a mobile device (phone or tablet)
The user can then open the app, and access each individual (or individual copies) a HTML form to read/record data.
This is then transferred back to the PC, and stored.
Now, I'm not too concerned with the transfer between the PC/device, or the storage of the data, or any of that at this point. What I am concerned about is the ability to open/view these HTML files within a single app.
As the program has already been written using .NET and WinForms, it needs to be converted to be used on a mobile device, and I have chosen Xamarin for this purpose. However I only have limited knowledge of this package, so I am not sure if I can achieve this within a single app (i.e. without having to pass it to a separate app to view the HTML files).
So: is there an environment in Xamarin that I can use to view HTML files within my app?
Xamarin.Forms has a WebView class that you can use to display HTML content, so viewing the content is rarely an issue.
Interacting with the HTML content can sometimes be a bit tricky because of the links not conforming to what the app expects. But you can often solve these issues using the WebView.Navigating event handler that will allow you to catch and change the navigation behavior.
Xamarin.Forms's WebView relies on the native UIWebView (iOS) and WebView (Android) and Xamarin.Forms allows you to override the native Renderers. Overriding the native renderer will give you access to the native WebView with full flexibility.
You also have the possibility to completely ignore Xamarin.Forms's WebView and write your own view using native views.
It would probably be smart to test your WinForms app on iOS using Safari and on Android using Chrome as they are using the same rendering engines that will be used in respectively UIWebView (iOS) and WebView (Android)

Chromium WebView instead of Native WebView

Is it possible to use a Chromium webview instead of the native webview on OSX?
I am guess it is a products like Sencha Desktop Packager exist.
As far as I can tell there drop no convenient libraries/wrappers, but most searches for OSX dev return results for a certain handheld device.
Note
So far I have found CEF and CEFSimpleSample
It's possible to use a Chromium webview instead of a native webview. But the documentation to code such a thing is very rare and poor.
The Chromium Embedded Framework Forum is a good place to ask questions.
I would highly recommend you to alter the CEFSimpleSample because there is a "Chromium Webview" included which works.

OSX: How to render office docs on my app?

On iOS it was really easy, the UIWebView renders them (office files). But, on the OSX side, the WebView does not do that. Is there any other class may I use?

Resources