xcode에서 iPad로 실행할 때 작동하는 앱이 있지만 AdHoc 배포를 위해 준비 할 때 제대로 작동하지 않습니다.iOS 스레딩은 AdHoc 배포판에서 특정 기능을 호출하지 않지만 xcode에서 실행하면 작동합니다.
내 스레드는 다음과 같습니다
[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];
}
}
socketDidRead : 본질적으로
- (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];
}
}
가
: wifiBackground가 인터넷에 연결되어 있는지 확인, 연결 소켓, 네트워크에 패킷을 보내고 (타임 아웃 5 초), 읽기가 완료 될 때까지 기다린다 (timeou t는 5 초), 전송 된 패킷을 업데이트하면서 반복합니다. 네트워크가 닫히면 연결을 다시 시도해야합니다.AdHoc으로 실행하면 바로 연결할 수없는 경우 루프가 돌아 오지만 processRead를 사용하지 않고 읽기가 완료되면 멈추게됩니다 (전체 스레드). 예)
socketDidDisconnect
socketDidDisconnect
socketDidRead
tcp size = but_ptr
socketDidDisconnect (error = null)
processRead가 호출되지 않는 이유는 무엇입니까? 이것은 xcode에서 작동하며 왜 지금 작동하지 않는지 확신 할 수 없습니다.
dispatch_async(dispatch_get_main_queue(), ^{
[self processRead:allDataBytes];
});
하지만 같은 일이 위와 같이 발생합니다
이 나는 노력했다.
performSelectorOnMainThread를 시도하려고했으나 processRead가 const unsigned char
을 사용하기 때문에 올바른 객체가 아니라는 오류가 발생합니다.