Prevent cached iPhone webapp from reloading (scrolling to top) - iphone

I have an iPhone webapp that uses a cache manifest to work offline. I add the webapp to my home screen, use it (say scroll to a certain location on a page), then go back to homescreen.
When I open the app again, for a brief moment I see where I used to be (at that scrolled location on that page), but then the app "reloads" and I get scrolled to the top of the mainpage. Is there a way to prevent this "reloading"? This happens even in airplane mode (ie everything is working off the cache).

You're just seeing the default startup image, which is just a screenshot of the last place you were at. It's not "reloading"; the app wasn't loaded to begin with.
Search for "apple-touch-startup-image" to set a real loading image.

What I'm struggling with here is that the app actually seems to stay "in memory" longer if I use regular Safari as opposed to running in "apple-mobile-web-app-capable" mode. In the later case something as simple as pressing the home button, then task-switching back to the app causes a reload. Doing the same thing just in Safari often does not reload. So I'm worse off by using "apple-mobile-web-app-capable".

I don't believe there is a real 'reload' event. onload and onunload are all we get.
the onload handler starts up as if it is your first time coming to the page.
the onunload handler is the key to clearing out old content.
I like to provide alternate content for people who are coming back to my web app.
window.onunload=function(){
document.getElementsByTagName('body')[0].className+=' unloading'
}
And let the CSS do the dirty work to hide most of the body and show alternate content.
(this answer does not rely on jQuery or other frameworks)

// on load
window.scroll(0,0);
To ensure no old content is displayed while launching I use this in my page:
window.addEventListener('unload', function() { $('body').hide(); } );
Thus the last state of the page is empty and is what is shown to the user when the page is opened again.

Related

How to close System dialogs that appears on app crash?

I'm using xcuitest framework to automate mac application. I get system dialogs when the app is opened again after it crashes. I want to handle the dialog programmatically. But the dialog appears under the process `UserNotificationCenter' instead of the application under test. How can I handle the alert in such case?
You have two options:
Use InterruptionMonitor (documentation, use-case). This
approach is however kinda old and I found, that it does not work for
all dialogs and situations.
Create a method, which will wait for some regular app's button. If the app's button (or tab bar or other such XCUIElement) is visible and hittable after your app started, you can proceed with your test and if it's not, you can wait for the UserNotificationCenter dialog's button and identify&tap it by its string/position.
I'm using the second approach and its working much better, than the InterruptionMonitor. But it really depends on your app layout and use-case.
You should be able to revent it from appearing in the first place. Something like:
defaults write com.apple.CrashReporter DialogType none

Template10 - return user to the main page after resuming

Let's assume that my UWP app gets suspended and it is not used for a long time. When a user opens the app again (previous ApplicationExecutionState is Suspended or Terminated), I don't want the user to be navigated to the page he/she was viewing last (it became irrelevant since then), but instead do a fresh navigation to the main page. How can I do this using Template10?
It seems that when the user returns to the app, Template10 always returns the user to the page which was being viewed last. I tried overriding the OnResuming method in App.xaml.cs, however it had no effect.
I had this problem.
I solved saving a bool property like ItWasSuspended in the LocalSettings of my app.
When the OnResumming is activated I set to True this property or when the launched event was raised I set this property false.
Finally in my pages in the OnNavigatedTo I get the value of this property if this property is true I navigate to the main page and I clear the back stack.
Here is how to use the local settings
https://msdn.microsoft.com/library/windows/apps/windows.storage.applicationdata.localsettings.aspx
you can clear the back stack doing something like this
this.Frame.BackStack.Clear();
please mark this answer if it's useful for you!
Best regards

Anyone implemented/used Mobile Device Screen Orientation plugin?

Has anyone successfully implemented screen orientation plugin in Sitecatalyst to capture mobile device orientation?. When we use the below code in the s_code, in the web page i am seeing some unusual behavior(ie: when we scroll the page to the bottom and then if i click anywhere on the content section, page goes to the top by default). I understand, that's happening because of this line "window.scroll(0,0)". Any help or thoughts?
Plugin Code below:
function screenOrientation(){switch(window.orientation){case 0:case 180:return("Portrait");break;case 90:case -90:return("Landscape");}window.scroll(0,0)}
Reference: [http://webanalyticsland.com/sitecatalyst-implementation/capture-mobile-device-screen-orientation-in-sitecatalyst]
Thanks in Advance.
This is clearly a code bug (or more a typo I think) and the line window.scroll(0,0) can be safely removed from the 'plugin' (its not really a plugin, just a js function that returns the orientation).
The reason this fires every time a user clicks on anywhere on the page is because you have ClickMap functionality enabled in your s_code.js configuration. This will fire an s.tl() everytime a click event occurs. the s.tl() will call the screenOrientation() function to populate your required prop/eVar.
So if you were to turn off clickMap (s.trackInlineStats=false;) this random scrolling to the top would stop even if you didn't remove the offending line. That said, remove the scrolling code, its not right or required!

how to load aplication from start up page each time in iphone

I have application for iphone i want to open it from start up page always but when i load first time app on ipad it loads from startup page but when i close app and second time run on ipad then it opens from the same screen from where i left i want that again it should open from startup page also.I have start up page with enter button when i click to button i move to calulations screen where i perform calculations .If i close on calculation screen the app when i again open it it opens from calculation screens not from the startup screen
In plist file add one more field
Application does not run in background : make it true
This is your perfect ans.
Second time app will be in Background thats why it is not starting with start app page. Dont allow application to run in background. Set Key "" in info.plist file
You should add in your plist that property :
UIApplicationExitsOnSuspend
This will allow your application to "restart" instead of saving its state. This will allow you to load the start up page each time.
(documentation)
Well it is discouraged by apple , according to it's documentation:-
There is no API provided for gracefully terminating an iOS application.
In iOS,user presses the Home button to close applications. Should your application have conditions in which it cannot provide its intended function, the recommended approach is to display an alert for the user that indicates the nature of the problem and possible actions the user could take — turning on WiFi, enabling Location Services, etc. Allow the user to terminate the application at their own discretion.
Warning Do not call the exit function. Applications calling exit will appear to the user to have crashed, rather than performing a graceful termination and animating back to the Home screen.
Here's the link to it.Anyway nobody stops you from using
exit(0) , but is discouraged.
Another way to do is is simply change your application's pList property "Application does not run in background" to true.

Wicket Pagemap Correct Use

I'm working on an app. with a homepage that contains two iframes. Each one of these iframes is refreshed every 5 seconds. Also, from the homepage the user can open several popup windows. Right now, when I open one of the popup windows, and reload it 3 or 4 times, one of the iframes in the homepage crashes because of a PageExpiredException. My question is, what would be the right way to use PageMaps to avoid this PageExpiredException? Also, the back button won't be available, so I don't need to keep previous versions of any page in session, is there a way to tell app. not to store previous versions of the pages?
Thanks,
Juan.
Each window, frame or iframe should have a PageMap of its own, so they don't conflict with each other. When you create the initial URL of an iframe, use the urlFor(PageMap,Class,PageParameter) method, so that page and pages navigated from there are part of that PageMap.
Stateless pages don't go into the PageMaps, so if a window only shows stateless pages, it doesn't really matter what is its PageMap (you may use the default).
If you upgrade to Wicket 1.5 (in RC right now), you don't have to worry about that anymore, since they discarded the whole PageMaps concept.