即使应用程序在后台,我也想使用以下功能?
- (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;
}
上面的代码是在前台完成的。我已经对苹果文档中给出的所有更改进行了更改,以在后台模式下运行应用程序 - voip。我应该在 AppDelegate 方法中写什么?
- (void)applicationDidEnterBackground:(UIApplication *)application
{
}
如何获取流:后台调用的handleEvent?