MegaBits / SIOSocket

Realtime iOS application framework (client) http://socket.io
MIT License
494 stars 80 forks source link

Handle background mode #43

Open aoopvn opened 9 years ago

aoopvn commented 9 years ago

How do we handle new event when the app enter background mode? Here under is my approach for this, but it still doesn't work Thank you very much for your suggestion

// on app delegate
- (void)applicationDidEnterBackground:(UIApplication *)application {
    [self.sharedSocket on:kMESSAGE callback:^(SIOParameterArray *args) {
           NSLog(@"it does work in here too!");          
    }];
}
// on other controller
AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
[SIOSocket socketWithHost:kHOST_URL response:^(SIOSocket *socket) {
      appDelegate.sharedSocket = socket;
      self.mySocket = socket;
      [self.mySocket on:kMESSAGE callback:^(SIOParameterArray *args) {
            NSLog(@"it works!");
      }];
      //other logic code
}];
ahallora commented 9 years ago

I'm having a similar issue with emits not working when the app goes in background mode. The log shows that the emit function has been called but the callback is not triggered and the log goes quiet. - Until I open the app again, that is. Then the log floods with error messages from siosocket with the error: "type = TransportError;".

Could be related to https://github.com/MegaBits/SIOSocket/issues/36 and https://github.com/MegaBits/SIOSocket/issues/16 ...

Anyone got an idea for a fix? :smile:

zulkis commented 9 years ago

You could try background tasks iOS7+ feature or 'simulate' geolocation activity to simulate 'background work'.

josefrm commented 9 years ago

Background task means the app got killed by task manager (mean double tapping and removing form active app)?

Cuz im searching an answer to it