iOS线程在临时发行版中不调用特定函数,但在从xcode运行时工作

iOS线程在临时发行版中不调用特定函数,但在从xcode运行时工作,ios,multithreading,xcode5,ad-hoc-distribution,gcdasyncsocket,Ios,Multithreading,Xcode5,Ad Hoc Distribution,Gcdasyncsocket,我有一个应用程序,当我从xcode在我的iPad上运行它时可以正常工作,但当我准备进行临时分发时,它将无法正常工作 我的帖子是: [NSThread detachNewThreadSelector:@selector(wifiBackground) toTarget:self withObject:nil]; wifiBackground是: -(void)wifiBackground { [self setupSocket]; [NSThread sleepForTimeInterval:

我有一个应用程序,当我从xcode在我的iPad上运行它时可以正常工作,但当我准备进行临时分发时,它将无法正常工作

我的帖子是:

[NSThread detachNewThreadSelector:@selector(wifiBackground) toTarget:self withObject:nil];
wifiBackground是:

-(void)wifiBackground
{

[self setupSocket];
[NSThread sleepForTimeInterval:1.0f];

while (YES) {
    [NSThread sleepForTimeInterval:3.0f];
    if (mNetAlive == [NSNumber numberWithInt:TCP_PORT_OK]) //is connected (can send messages through internet)
    {
        //setup for sending tcp msg, grab network info
        NSString *mWifiname = [self fetchSSIDInfo];
        NSLog(@"mWifiname %@", mWifiname);
        [self writeToCSV:autoErrLogg :[[NSString alloc] initWithFormat:@"mWifiname %@,,,,",mWifiname] :YES :YES];


        //send messages if new or changed
        if ((wifi_name == nil || wifi_name == (id)[NSNull null] || ([wifi_name length] == 0)) ) { //is null
             NSLog(@"is null");
            [self sendMsgType:WIFI_UDP_CX msgArg1:WIFI_CX_NEW msgArg2:[NSNumber numberWithInt:0] wifiName:mWifiname buffer:nil];
        } else if ([wifi_name containsString:mWifiname]) {
            [self sendMsgType:WIFI_UDP_CX msgArg1:WIFI_CX_CHANGE msgArg2:[NSNumber numberWithInt:0] wifiName:mWifiname buffer:nil];
        }

        wifi_name = mWifiname;
        mTcpState = [NSNumber numberWithInt:TCP_PORT_OPEN];
        retrycount = 0;
        [NSThread sleepForTimeInterval:1.0f];


        while (mTcpState == [NSNumber numberWithInt:TCP_PORT_OPEN] && ([mWifiname containsString:mCurrentSSID])) {
            [self setupSocket];
            [NSThread sleepForTimeInterval:2.0f];

            mTcpAlive = [NSNumber numberWithInt:TCP_PORT_OK];
            mWifiAlert = [NSNumber numberWithInt:0];

            [self writeToCSV:autoErrLogg :[[NSString alloc] initWithFormat:@"connected %d,mwifiName %@,current ssid %@,,",[asyncSocket isConnected],mWifiname,mCurrentSSID] :YES :YES];
            while ([asyncSocket isConnected] && ([mWifiname containsString:mCurrentSSID])) {
                if (reading == NO) {
                    NSMutableArray *mytx = tx;
                    [self send:mytx];
                }

                //recieve info
                reading = YES;
                [self startRead];
                while (reading == YES) {} //wait
            }
            retrycount++;
            if (retrycount >= 3) {
                NSLog(@"in retry");
                [self writeToCSV:autoErrLogg :[[NSString alloc] initWithFormat:@"in retry,,,,"] :YES :YES];

                if (([mWifiAlert intValue] == 0) && ![mWifiname containsString:mCurrentSSID]) { mWifiAlert = [NSNumber numberWithInt:1]; }

                [asyncSocket disconnect];
                [NSThread sleepForTimeInterval:1.5f];
                //obviously not connected to internet so shut down
                mTcpAlive =  [NSNumber numberWithInt:TCP_PORT_OFF];
                [self sendMsgType:WIFI_UDP_CX msgArg1:WIFI_CX_RX_ERROR msgArg2:[NSNumber numberWithInt:0] wifiName:mWifiname buffer:nil];
                break; //breaks out of while
            }
        }

        if (!([mWifiname containsString:mCurrentSSID])) {
            NSLog(@"not correct wifi");
            [self writeToCSV:autoErrLogg :[[NSString alloc] initWithFormat:@"not correct wifi,,,,"] :YES :YES];
            if ([mWifiAlert intValue] == 0) {
                mWifiAlert = [NSNumber numberWithInt:1];
            }

            [NSThread sleepForTimeInterval:5.0f];
        }

     } else {
         noWifiOn++;

         NSLog(@"in else mNetAlive");
         [self writeToCSV:autoErrLogg :[[NSString alloc] initWithFormat:@"in else mNetAlive,,,,"] :YES :YES];
         if (noWifiOn >= 5) {
             if ([mWifiAlert intValue] == 0) {
                 mWifiAlert = [NSNumber numberWithInt:2];
             }

             NSLog(@"alert view");
             noWifiOn = 0;
             [NSThread sleepForTimeInterval:5.0f];
         }
         mTcpAlive = [NSNumber numberWithInt:TCP_PORT_FAIL];

     }
    [NSThread sleepForTimeInterval:2.0f];
 }
}
袜子上写着:

- (void)socket:(GCDAsyncSocket *)sock didReadData:(NSData *)data withTag:(long)tags
{
reading = YES;
const unsigned char *dataBytes = [data bytes];
NSUInteger dataLength = [data length];

if (buf_ptr == 0) {
    TCP_size = [self strintvalue:[NSString stringWithFormat:@"%02x%02x",dataBytes[2],dataBytes[1]]];
}

buf_ptr = buf_ptr + (int)dataLength;
//NSLog(@"buf ptr = %i",buf_ptr);

if ((buf_ptr < TCP_size) && (TCP_size <=12000)) {
    [ds appendData:data];
    [self startRead];
} else if (buf_ptr == TCP_size){
    [ds appendData:data]; //append the final bit for this package
    //NSLog(@"ds = %@",ds);
    [self writeToCSV:autoErrLogg :[[NSString alloc] initWithFormat:@"socketDidRead,,,,"] :YES :YES];
    NSLog(@"tcp size = buf_ptr");
    [self writeToCSV:autoErrLogg :[[NSString alloc] initWithFormat:@"tcp size = buf_ptr,,,,"] :YES :YES];
    const unsigned char *allDataBytes = [ds bytes];
    [self processRead:allDataBytes];
    reading = NO;
    mTcpAlive = [NSNumber numberWithInt:TCP_PORT_OK];
    retrycount = 0;
    buf_ptr = 0;
    [ds setLength:0];
} else {
    [self sendMsgType:WIFI_UDP_CX msgArg1:WIFI_CX_RX_ERROR msgArg2:0 wifiName:wifi_name buffer:nil];
    buf_ptr = 0;
    [ds setLength:0];
}
}
为什么从未调用processRead?这是从xcode开始工作的,我不确定为什么它现在不工作

我试过:

dispatch_async(dispatch_get_main_queue(), ^{
        [self processRead:allDataBytes];
    });
但同样的事情如上所述


我本来打算尝试performSelectorOnMainThread,但由于processRead使用的是
常量unsigned char
,因此它给我一个错误,即它不是正确的对象。

我的问题是这些行:

//recieve info
reading = YES;
[self startRead];
while (reading == YES) {} //wait
它会卡在while循环中。我删除了它,并改变了它周围的一些逻辑

//recieve info
reading = YES;
[self startRead];
while (reading == YES) {} //wait