I tried this code in my project to download large files in background and it works fine. I start downloading in UIViewController. If I go to another view and back to the UIViewController ,it stop reloading the progress bar.
I got the Issues with A background URLSession with identifier already exists!. I Want to create new session every time when UIViewController load. I want invalidate all background session when dismiss the view controller. I tried all possibilities to resolve this issue but don’t get succeed.
Click Here
When you create a background session, you're doing two things:
Telling nsurlsessiond (a background daemon) to create a session.
Creating a local session in your app that is connected to that session.
The purpose of the identifier is to allow your app to reconnect to the external session (controlled by nsurlsessiond) if your app gets terminated by the operating system.
To my knowledge, it is not normally possible for your app to voluntarily dissociate its session from the background session. So when your app tries to create a session with the same identifier, suddenly there are two sessions that are both trying to talk to the same external session in nsurlsessiond, and things go very wrong. That's not a supported way to use the API.
The background session object must be kept alive the entire time that your app is running. Don't try to dispose of it and recreate it within a single launch. You should not ever create a session with the same ID unless your app gets relaunched.
Note, however, that if your app gets relaunched to handle background events (iOS only), when you call the completion handler provided by the event, your app's local session does get invalidated, and you need to create it if your app does anything after that. That's the only situation I'm aware of where a background session ever stops being associated with the background session in nsurlsessiond, and thus that's the only situation where you should ever create a session with the same ID twice in a single launch (once when you're asked to handle background events, and then potentially again when you get a didFinishLaunching call to indicate that the user foregrounded your app).
Related
I wish to record the login and the logout timestamp for users.
I understand that as soon as a user hits the login page a new browser specific session is created & sessionCreated(HttpSessionEvent se) is executed. When the session is invalidated that session gets destroyed & the sessionDestroyed(HttpSessionEvent se) is executed. In this scenario recording the login and logout timestamps will work perfectly.
However, say, the user is logged in but closes the browser window. The next time when the browser is opened a new session id will be generated and the user needs to login again. Hence, the previous login-logout record for that user will be incomplete and a new record with the current session id will be inserted in the database.
How do I tackle this design issue? I read some answers where AJAX polling & JS onunload were discussed but those did not seem to be a reliable solution.
Also, on the other hand, is there a way to keep the session alive even on browser close?
Thanks in advance.
Session can be kept recorded on users browser via Cookies.
It basically allow use to re login to the system without having to authenticate itself. In this case you can store the bare minimum state information you need to restore when the client open the browser again.
But the session id's is definitely going to change.
I understand implementing a transaction observer at time of app load is recommended. I am executing below line in viewDidLoad:
SKPaymentQueue.defaultQueue().addTransactionObserver(self)
But this causes the app to ask for user's App Store credentials at app launch which is not the behaviour we would want. What is wrong?
I'm using the windows live sign in strategy of the PhotoSkyOnTheGo example provided by MS. So when my app starts, it shows a windows live sign in page.
During app runtime I remember the LiveConnectSession to connect to SkyDrive.
Now when the app tombstones, I need a way to save the LiveConnectSession. IsolatedStorageSettings.ApplicationSettings does not work, probably because the LiveConnectSession is not serializable (it shows some InvalidDataContractException in the debug output).
So how do I store the Session in case the app tombstones? Or is the provided PhotoSkyOnTheGo-example rubbish and I need to be able to reconnect anytime I'm accessing SkyDrive?
If your app uses wl.offline_access scope than the live:SignInButton control saves it for you and loads it automatically. Just use the SessionChanged event to capture the session object. This way the user will need to sign in only once.
Scope:
http://msdn.microsoft.com/en-us/library/live/hh243646.aspx#wlofflineaccess
Event:
http://msdn.microsoft.com/en-us/library/live/microsoft.live.controls.signinbutton.sessionchanged.aspx
Use case:
I have two web application running on tomcat which are deployed on two different machines. One of my application is a parent and other is a child. I login to my parent application and hitting a link on one of the pages of parent application i sends a browser request to my child application that open's one of its page in a separate browser window. In this scenario i would want both of my application to share the same timeout value and should behave like one complete application.
Scenarios to handle:
If i logout from my parent app, my child app should also get logout
If i close parent window, parent should get logout along with child
If i close child window, child should get logout and parent should remain logged in
If both the window are closed, both parent and child should get logout
Solution:
Set parent session time out to some value..say 30mins
Create a REST service on parent..let's say "parentisAlive()"
Create a REST service on child..let's say "childisAlive()"
Create session listeners on parent and child
Each of the session listeners would invoke its respective REST service
REST service would talk to each other based on its own application's sessionID
Parent would presist(memory/DB) child's sessionID and vice versa
Respective applications session listener would get activated when each of its timeout value reaches a specific value..say 20mins
Session listeners would invoke respective REST service that will be responsible to synch each others session time out value
Can anyone please suggest if this would be a good solution to implement session synchronization, does anyone see any flaw in this?
Tomcats Single sign on valve will handle most of your needs. But if you close a browser window the sessions will still remain, as long as at least on window or tab is open.
I want to handle following scenarios in my new web application.
If multiple users log into the application with same credentials, the application should deny access.
Since I have out of process session store, I would be able to make out when this situation happens. So I can deny all requests after first successful attempt. This will however not work if the user instead of logging out of the application, closes the browser. The session will continue to reflect in the store for the period of timeout value.
If a user attempts to open a new browser windows (Ctrl+N), the application should defeat this attempt. Every new page can potentially fiddle with cookies. I want to therefore deny the users the ability to open new window.
How about?
Having a server timer and then track users session. Reset the timer when you get the request back to the server.
Not possible. Ctrl + N is for opening a new browser window and this does not mean that the user is going to visit your site.
Also check out this question which might be of some interest.
How to differ sessions in browser-tabs?