How do I clear the cache of Cordova Web View on Windows Phone 8? - caching

I'm developing a Cordova 2.9.0 app for Windows Phone 8. The app in question utilises external content heavily, using the JS and HTML content that's being served from another source. It all works fine, but the browser component caches heavily.
The only way I have discovered to clear caches is to uninstall-install the app again to take effect. The downside to this is that my localStorage also clears, slowing down my cycles.
I presume the cache can be cleared by writing extra C# into the Cordova template they serve, which I use by the way.

So while it was not that critical, I did stumble to a working answer. The WebBrowser class does have a suitable method to call: ClearInternetCacheAsync.
Since CordovaBrowser inherits from WebBrowser, it's just a matter of adding one line to MainPage.xaml.cs where the C# init of the start page happens:
namespace FooBarApp
{
public partial class MainPage : PhoneApplicationPage
{
// Constructor
public MainPage()
{
InitializeComponent();
this.CordovaView.Loaded += CordovaView_Loaded;
// blammo!
this.CordovaView.CordovaBrowser.ClearInternetCacheAsync();
}

Phonegap Cookies Plugin can be found HERE
A simple, lightweight jQuery plugin for reading, writing and deleting cookies can be found HERE
I hope it will resolve your problem. Thanks!!

Related

Load startup model in platform project code and pass it to PCL on Xamarin Forms Initialization

The application I'm currently working on requires data to be retrieved from a web service during app startup that roughly takes 1.5 seconds. After the data is retrieved, it needs to be displayed on the MainPage and that is another 1.5 - 2 seconds since the data is mostly URLs of images that have to be displayed, in my case, using ffimageloading library; which means actually downloading those images first to be displayed.
I have splash startup screens for both Android and iOS implemented separately in platform projects but splash screen only stays up for the amount of time Xamarin Forms needs to load and afterwards disappears not waiting for my actual model to load from the web service. I have searched for solutions to extend the splash screen duration and mostly every solution I have read involves creating another splash screen page, loading page if you will, that is already controlled in PCL project but having two separate splash loading screens just seams not feasible to me at the moment.
So I was wondering, how would one load the initial model in platform projects, during the actual splash screen, and then later pass it to PCL project when Xamarin Forms has finished initialization, presumably to App.xaml.cs 's App() constructor function?
There is no code or enough details so I am assuming this is what you want to do.
Call the APIs asynchrnously , till then show splash screen.
Before assigning MainPage in your App.xaml.cs you should call these APIs asynchronously with await and then you use the same for binding of your mainpage
public App()
{
InitializeComponent();
//do all my prefetch stuff for app initialization.
// API and what not
var viewmodel = new AppMainViewModel();
await viewmodel.CallFooFetchAsync();
await viewmodel.BlahBlahAsync();
MainPage = new NavigationPage(new AppMainPage(viewmodel));
}
In Page
public AppMainPage(AppMainViewModel vm)
{
BindingContext =vm;
}
So by the time page loads it has all the data handy.
You can explore adding this code in OnAppearing of the page.
Note that the concept of default Splash screen is just to show an image(with different theme in Android) and setting image in iOS. You need to have conventional UI technically its not splash screen anymore.
Alternatively you can get shared project handle in native
Android Sp
protected override void OnCreate(Bundle bundle)
{
...
var app = new App(); //this will be shared project App object
Device.BeginInvokeOnMainThread(async () => await app.DoPrefetchStuffFirst()); //API calls if needed in this async method
//then
LoadApplicationm(app)
}
You can do similar thing in iOS AppDelegate
And if you call native specific methods in platforms (may be for API calls) then you would use DependencyService feature , that will pass it to shared project or Custom renderer based on where you want to use it.

When using Appcenter, can I still call VersionTracking inside the App constructor?

The application I am working with uses AppCenter with code like this:
public App()
{
InitializeComponent();
VersionTracking.Track();
VersionChecks();
VersionChecks();
DB.CreateTables();
DB.GetSettings();
DB.PopulateTables();
SetDeviceInfo();
SetResourceColors();
SetResourceDimensions();
MainPage = new AppShell();
}
protected override void OnStart()
{
AppCenter.Start("xx", typeof(Crashes), typeof(Push));
Analytics.TrackEvent(VersionTracking.CurrentVersion);
}
Although I don't see any error messages when it starts up I am concerned about the way this is coded as from what I can see the App constructor fires first followed by the OnStart().
So if this happens, how can VersionTracking work. Should that code not be in the OnStart and how about the additional code that I have which sets up the application?
Would appreciate any advice that people can offer about the use of AppCenter with Xamarin forms.
Answer
Yes, you can use Xamarin.Essentials.VersionTracking in the constructor of App.
Explanation
You are confusing three different SDKs: Xamarin.Essentials, Xamarin.Forms and AppCenter.
VersionTracking is an API in Xamarin.Essentials.
App is a subclass of the Xamarin.Forms.Application API.
AppCenter.Start is an API in the AppCenter
These are three independent SDKs and each can be used independently of the others.
Xamarin.Forms app startup flow is like : Native App Startup -> Xamarin.Forms.Application Startup
Your App class is instantiated only after Native app has finished loading.
As versioning is managed by native app, there is no problem in initialising VersionTracking in constructor, as Native app has fully loaded by this time.

MiniProfiler with ASP.NET WebForms Classic Mode

We're trying to configure MiniProfiler with an ASP.NET WebForms app that runs in a classic mode app pool (cannot change it to integrated). We couldn't get the handlers to work so loading the resources failed.
To solve this we included the .js, .css, .tmpl, and .html from https://github.com/SamSaffron/MiniProfiler/tree/master/StackExchange.Profiling/UI After doing that these resources get loaded, but we still don't see anything.
The initialization script is rendered in the final html, but the ... block never gets generated. I'm assuming because the script never runs. We tried loading jQuery v1.7.1 and a newer version; neither worked.
There are no 404s or anything in the console (Chrome or FireFox). Any ideas? Thanks.
Are you having the issue running the profiler in IIS on your local machine or on a server?
The quick code sample on the miniprofiler.com site suggests wrapping the MiniProfile.Start() call in a Request.IsLocal condition (code below), this would prevent the profiler from being rendered on the server (unless you were viewing the page from the server itself). Try removing the Request.IsLocal code and see if that helps.
protected void Application_BeginRequest()
{
if (Request.IsLocal)
{
MiniProfiler.Start();
}
}

Play 1.2.4 Mobile and PC design on the same app

I am a new developer in Play world! For a project I need to have a mobile and desktop version. But I don't know how to!!
Create 2 applications, share the model..;
Create a mobile controller to separate the desktop views against the mobile views
I have no idea of how to make this properly. I know the responsive design but I can't use it on this project.
Thanks
PS: Sorry for my english
Depending on the use case I would have a look at a framework like Twitter Bootstrap. With the twitter bootstrap you can use ONE set of view templates for both desktop and mobile. There is also a framework called Kickstrap and a few others.
But on the other hand, if you want to develop some sort of 'backend' or 'admin' application (you still CAN use twitter bootstrap, but you might have a look at frameworks like Sencha (EXT JS and Touch) or Kendo UI.
What ever you choose, Play will enable you to develop the serverside as it should be (RESTful), so the choice for the frontend can change in time, but you app architecture will be fine :-)
Either one is okay. As they are essentially the same thing, 2 set of routes/controllers/views plus 1 set of domain models.
If you are using my play clone, then you can simplified it to 1 set of domain model + 1 set of routes/controllers + 2 set of views, as you can do something like follows:
public class Application extends Controller {
...
#OnApplicationStart
public static class ViewRouter extends Job {
Controller.registerTemplateNameResolver(new ITemplateNameResolver(){
#Override
public String resolveTemplateName(String templateName) {
return UserAgent.isMobile() ? "mobile/" + templateName : templateName;
}
});
}
}
Thus you just put your mobile views under app/views/mobile and all others still remain in app/views, the template will be loaded dynamically based on the request's user agent, if it's coming from a mobile device then app/views/mobile/.. version get loaded otherwise, the normal view will be loaded.

History issue combining WP7.5, phonegap and jqm

I have a phonegap app that uses jqm that works fine in android and ios.
Porting to WP7 i have an issue with the history, specifically history.back() (but also .go(-1) etc). This refers to going back in history where the previous 'page' was in the same physical html file, just a different data-role=page div.
using a jwm site in a regular browser is fine (with separate 'pages' in the same html file). Also, using history.back() when we go from one html file to another in the app is fine. It's the specific combination of WP7.5, jqm and PG.
Has anyone come across a solution for this? it's driving me crazy, and has been as issue since PG 1.4.1 and jwm 1.0.
EDIT 1: It's possible that the phonegap process of initialising the webview on WP7.5 somehow overrides the jqm history overrides, after they've loaded.
EDIT 2: definitely something to do with jqm not being able to modify the history. each time there is a 'page' change, history.length is still 0.
EDIT 3: When i inspect the 'history' object, i found there is no function for replaceState or pushState - i know jqm uses this for history nav, maybe that's the problem.
ok - this isn't perfect, but here's a solution (read: hack) that works for me. It only works for page hash changes, not actual url changes (but you could add a regex check for that). Put this somewhere in the code that runs on ondeviceready:
if (device.platform == 'WinCE') {
window.history.back = function () {
var p = $.mobile.urlHistory.getPrev();
if (p) {
$.mobile.changePage("#" + p.pageUrl, { reverse: true });
$.mobile.urlHistory.stack.splice(-2, 2);
$.mobile.urlHistory.activeIndex -= 2;
}
}
}

Resources