Como lidar com eventos de conexão de soquete quando o aplicativo está em segundo plano?
Eu quero usar a seguinte função, mesmo quando o aplicativo está em 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;
}
O código acima está funcionando em foreGround. Eu fiz toda a mudança dada no documento da apple para executar o aplicativo no modo de fundo-voip. O que devo escrever no método AppDelegate?
- (void)applicationDidEnterBackground:(UIApplication *)application
{
}
Como obter o fluxo: handleEvent chamado em segundo plano?