gpt4 book ai didi

ios - 清除IdleCellConnections

转载 作者:技术小花猫 更新时间:2023-10-29 10:46:46 24 4
gpt4 key购买 nike

关于本题的“重复”状态:
这个问题是在 2012 年 11 月提出的,它包含问题的详细描述并有 3 个答案。
被称为“原始”的问题是在 2013 年 2 月(此“重复”后 3 个月)提出的,没有详细说明,只有 2 个答案。它的两个答案中最好的只是一个链接答案。


为什么我会在我的控制台中收到此消息?

purgeIdleCellConnections: found one to purge conn = (some object-ID)

当我的应用程序启动时,我会向我的服务器发送一条消息。我用这行代码来做到这一点:

@implementation AppStatus {
NSMutableData* activeDownload;
NSURLConnection* Connection;
}

- (id) init {
self = [super init];
if (self) {
activeDownload = nil;
Connection = nil;
}
return self;
}

- (void)sendStatus:(NSString*)url {
NSString* escaped = [url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURLConnection* conn =[[NSURLConnection alloc] initWithRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:escaped]] delegate:self];
Connection = conn;
NSLog(@"%s Connection=%@",__PRETTY_FUNCTION__,Connection);
}

在同一个文件中我有这个委托(delegate)方法:

- (void)connection:(NSURLConnection*)connection didReceiveData:(NSData*)data {
NSLog(@"%s connection=%@",__PRETTY_FUNCTION__,connection);
[activeDownload appendData:data];
}

- (void)connection:(NSURLConnection*)connection didFailWithError:(NSError*)error {
NSLog(@"%s connection=%@",__PRETTY_FUNCTION__,connection);
activeDownload = nil;
Connection = nil;
//do nothing else; just ignore the error
}

- (void)connectionDidFinishLoading:(NSURLConnection*)connection {
NSLog(@"%s Connection=%@",__PRETTY_FUNCTION__,Connection);
NSString* answer = [[NSString alloc] initWithData:activeDownload encoding:NSUTF8StringEncoding];
//do something usefull with the server's answer
activeDownload = nil;
Connection = nil;
}

当我在真实设备(而不是模拟器)上运行此应用程序时,我在控制台中收到以下消息:

2012-11-22 20:41:51.309 BookMan[376:907] -[AppStatus sendStatus:] Connection=<NSURLConnection: 0x1dd7ff40>
2012-11-22 20:41:51.929 BookMan[376:907] -[AppStatus connection:didReceiveData:] Connection=<NSURLConnection: 0x1dd7ff40>
2012-11-22 20:41:51.935 BookMan[376:907] -[AppStatus connectionDidFinishLoading:] Connection=<NSURLConnection: 0x1dd7ff40>
purgeIdleCellConnections: found one to purge conn = 0x1dd8ff60

purgeIdleCellConnections 消息在 connectionDidFinishLoading 消息后约 4 或 5 秒出现。

如您所见,purgeIdleCellConnections 消息的对象编号与我在应用中创建和使用的连接编号不同。

也许重要:只有当我在真实设备(装有 iOS 6.0.1 的 iPhone 4)上运行应用程序时,我才会收到此消息。此设备使用 3G 连接,而不是 WIFI 连接。目前我没有 WIFI 网络来测试这种情况是否也发生在 WIFI 连接上。
当我在模拟器上运行应用程序时,我没有收到此消息。

当我将方法 sendStatus: 更改为:

- (void)sendStatus:(NSString*)url {
NSString* escaped = [url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
//NSURLConnection* conn =[[NSURLConnection alloc] initWithRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:escaped]] delegate:self];
//Connection = conn;
NSLog(@"%s Connection=%@",__PRETTY_FUNCTION__,Connection);
}

我在控制台中得到这个输出:

2012-11-22 20:45:11.927 BookMan[391:907] -[AppStatus sendStatus:] Connection=(null)

当我没有创建连接时,我没有收到 purgeIdleCellConnections 消息。


那么这条消息是什么意思,为什么我会收到它?

purgeIdleCellConnections: found one to purge conn = (some object-ID)

最佳答案

这意味着,一个空闲时间过长的连接已经关闭了它的 TCP 连接。这是一个基 native 制,它的日志不应该像 Apple 在 Technical QA1774 上声明的那样打扰您。 ,这是一条错误地启用的调试消息。

确实,此日志仅在清除WWAN 连接 时显示。

关于ios - 清除IdleCellConnections,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13519550/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com