Permalink
Browse files

Handle when the user force-quits the app

  • Loading branch information...
paulcbetts committed Mar 20, 2013
1 parent c50b4e0 commit 2f198f398b8114a69c49b380b48f8c931105c054
Showing with 10 additions and 2 deletions.
  1. +10 −2 ReactiveUI.Mobile/AutoSuspendAppDelegate.cs
@@ -59,9 +59,17 @@ public AutoSuspendAppDelegate()
AppDomain.CurrentDomain.UnhandledException += (o,e) => untimelyDeath.OnNext(Unit.Default);
host.ShouldInvalidateState = untimelyDeath;
- host.ShouldPersistState = _willTerminate.Select(app => {
+ host.ShouldPersistState = _willTerminate.SelectMany(app => {
var taskId = app.BeginBackgroundTask(new NSAction(() => {}));
- return Disposable.Create(() => app.EndBackgroundTask(taskId));
+
+ // NB: We're being force-killed, signal invalidate instead
+ if (taskId == UIApplication.BackgroundTaskInvalid) {
+ untimelyDeath.OnNext(Unit.Default);
+ return Observable.Empty<IDisposable>();
+ }
+
+ return Observable.Return(
+ Disposable.Create(() => app.EndBackgroundTask(taskId)));
});
SuspensionHost = host;

0 comments on commit 2f198f3

Please sign in to comment.