client :在plist文件中所需的背景模式:
[App plays audio or streams audio/video using AirPlay,App provides Voice over IP services]在函数createStream中
CFReadStreamSetProperty(readStream, kCFStreamNetworkServiceType, kCFStreamNetworkServiceTypeVoIP);
CFWriteStreamSetProperty(writeStream, kCFStreamNetworkServiceType, kCFStreamNetworkServiceTypeVoIP);在函数applicationDidEnterBackground中
BOOL backgroundAccepted = [application setKeepAliveTimeout:600 handler:^{
[self send:[NSString stringWithFormat:@"%@ KeepAliveTimeout",[NSDate date]]];
}];
if (backgroundAccepted)
{
DLog(@"VOIP background");
}
_bgTaskId=[application beginBackgroundTaskWithExpirationHandler:^{
[self alert:@"ExpirationHandler"];
[application endBackgroundTask:_bgTaskId];
_bgTaskId=UIBackgroundTaskInvalid;
}];在函数applicationWillEnterForeground中
[application clearKeepAliveTimeout];服务器每5次用NSTimer.client应用程序向客户发送消息,使用本地通知立即在后台显示消息;
发布于 2014-03-12 18:10:50
发布于 2015-04-22 06:25:18
我和你一样经历了问题,你要做的就是删除代码
_bgTaskId=[application beginBackgroundTaskWithExpirationHandler:^{
[self alert:@"ExpirationHandler"];
[application endBackgroundTask:_bgTaskId];
_bgTaskId=UIBackgroundTaskInvalid;
}];我已经尝试过几次了,如果您调用beginBackgroundTaskWithExpirationHandler,您的应用程序无论如何都会被系统终止。
只需保留代码BOOL backgroundAccepted = [application setKeepAliveTimeout:600处理程序:^{ [self send:[NSString stringWithFormat:@"%@ KeepAliveTimeout",NSDate date]];//除非您在这里有更多的工作要做。};if (backgroundAccepted) { DLog(@"VOIP背景“);}
从结果中我可以看到,如果您已经为套接字保留了正确的句柄,您的句柄代码将被自动调用,就像您在前台一样。
https://stackoverflow.com/questions/21248844
复制相似问题