即使应用程序在后台,我也想使用以下功能?
- (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)