Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In case anyone else has this issue, you can solve it by adding this code to your App Delegate. My full source code is here if you want to check it out: <a href="https://github.com/chrisballinger/Off-the-Record-iOS/blob/master/Off%20the%20Record/OTRAppDelegate.m" rel="nofollow">OTRAppDelegate.m</a>. The other relevant code is in receiveMessage: of <a href="https://github.com/chrisballinger/Off-the-Record-iOS/blob/master/Off%20the%20Record/OTRBuddy.m" rel="nofollow">OTRBuddy.m</a>.</p> <pre><code>- (void)applicationDidEnterBackground:(UIApplication *)application { NSLog(@"Application entered background state."); NSAssert(self.backgroundTask == UIBackgroundTaskInvalid, nil); self.didShowDisconnectionWarning = NO; self.backgroundTask = [application beginBackgroundTaskWithExpirationHandler: ^{ dispatch_async(dispatch_get_main_queue(), ^{ NSLog(@"Background task expired"); if (self.backgroundTimer) { [self.backgroundTimer invalidate]; self.backgroundTimer = nil; } [application endBackgroundTask:self.backgroundTask]; self.backgroundTask = UIBackgroundTaskInvalid; }); }]; dispatch_async(dispatch_get_main_queue(), ^{ self.backgroundTimer = [NSTimer scheduledTimerWithTimeInterval:10 target:self selector:@selector(timerUpdate:) userInfo:nil repeats:YES]; }); } - (void) timerUpdate:(NSTimer*)timer { UIApplication *application = [UIApplication sharedApplication]; NSLog(@"Timer update, background time left: %f", application.backgroundTimeRemaining); if ([application backgroundTimeRemaining] &lt; 60 &amp;&amp; !self.didShowDisconnectionWarning) { UILocalNotification *localNotif = [[UILocalNotification alloc] init]; if (localNotif) { localNotif.alertBody = EXPIRATION_STRING; localNotif.alertAction = OK_STRING; [application presentLocalNotificationNow:localNotif]; } self.didShowDisconnectionWarning = YES; } if ([application backgroundTimeRemaining] &lt; 10) { // Clean up here [self.backgroundTimer invalidate]; self.backgroundTimer = nil; [application endBackgroundTask:self.backgroundTask]; self.backgroundTask = UIBackgroundTaskInvalid; } } - (void)applicationWillEnterForeground:(UIApplication *)application { } - (void)applicationDidBecomeActive:(UIApplication *)application { /* Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. */ NSLog(@"Application became active"); if (self.backgroundTimer) { [self.backgroundTimer invalidate]; self.backgroundTimer = nil; } if (self.backgroundTask != UIBackgroundTaskInvalid) { [application endBackgroundTask:self.backgroundTask]; self.backgroundTask = UIBackgroundTaskInvalid; } application.applicationIconBadgeNumber = 0; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload