相关疑难解决方法(0)

如何在应用程序处于后台时处理套接字连接的事件?

即使应用程序在后台,我也想使用以下功能?

- (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;
        }
Run Code Online (Sandbox Code Playgroud)

上面的代码在foreGround中完成.我已经在apple文档中给出了所有更改,以在后台模式中运行应用程序 - voip.我应该在AppDelegate方法中写什么?

- (void)applicationDidEnterBackground:(UIApplication *)application
{
} …
Run Code Online (Sandbox Code Playgroud)

sockets iphone background multitasking ios

4
推荐指数
1
解决办法
2万
查看次数

标签 统计

background ×1

ios ×1

iphone ×1

multitasking ×1

sockets ×1