¿Cómo manejar los eventos de conexión de socket cuando la aplicación está en segundo plano?
¿Quiero usar la siguiente función incluso cuando la aplicación está en segundo plano?
- (void)stream:(NSStream *)theStream handleEvent:(NSStreamEvent)streamEvent
{
case NSStreamEventHasBytesAvailable:
{ NSLog(@"Event:NSStreamEventHasBytesAvailable");
if (theStream == _inputStream) {
NSLog(@"NSStreamEventHasBytesAvailable: on Input Stream");
uint8_t buffer[1024];
int len;
while ([_inputStream hasBytesAvailable]) {
len = [_inputStream read:buffer maxLength:sizeof(buffer)];
if (len > 0) {
NSString *output = [[NSString alloc] initWithBytes:buffer length:len encoding:NSASCIIStringEncoding];
if (nil != output) {
NSLog(@"server said: %@", output);
// to get local notification I am calling below method.
[self scheduleNotification];
}
}
}
}
break;
}
El código anterior está trabajando hecho en primer plano. He hecho todos los cambios dados en el documento de Apple para ejecutar la aplicación en el modo de fondo: voip. ¿Qué debo escribir en el método AppDelegate?
- (void)applicationDidEnterBackground:(UIApplication *)application
{
}
¿Cómo obtener la secuencia: se llama handleEvent en segundo plano?