听完背景插座几分钟后的SIGSTOP

Luk*_*uka 1 ios

我有一个在后台运行的背景cocoaasyncsocket套接字.

//DELEGATE
- (void) socket:(GCDAsyncSocket *)sock didReadData:(NSData *)data withTag:(long)tag
{
    self.i += 1;
    NSLog(@"didReadData %d %@", self.i, [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding]);
    [self.asyncSocket readDataWithTimeout:-1 tag:0];

}

- (void)socket:(GCDAsyncSocket *)sock didConnectToHost:(NSString *)host port:(UInt16)port 
{
    NSLog(@"socket:%p didConnectToHost:%@ port:%hu", sock, host, port);

    [self.asyncSocket performBlock:^{
        [self.asyncSocket enableBackgroundingOnSocket];
    }];

    [self.asyncSocket readDataWithTimeout:-1 tag:0];

}
Run Code Online (Sandbox Code Playgroud)

//.plist

<key>UIBackgroundModes</key>
<array>
    <string>voip</string>
</array>
Run Code Online (Sandbox Code Playgroud)

在我获得SIGSTOP并且应用程序"崩溃"后,它在前3分钟工作正常.你知道为什么吗?

小智 6

您可以在管理器中检查原因(从XCode点击Window - > Organizer - >您的iOS设备 - >设备日志 - >您的应用程序).

就我而言,它是这样的:

Application Specific Information:
BKUnsuspendLimit MyApp[5168] exceeded 15 wakes in 300 sec
Run Code Online (Sandbox Code Playgroud)

事实证明,你的应用程序在300秒内被唤醒的次数是有限的.