2017-01-25 3 views
0

스트림에서 오류를 처리하는 방법은 무엇입니까? 사용자가 잘못된 네트워크에 연결되어 있다면이를 처리하고 싶습니다. 감사!CFReadStream의 처리 오류 - Obj-C

코드 :

- (void)initNetworkCommunication { 
CFReadStreamRef readStream; 
CFWriteStreamRef writeStream; 
CFStreamCreatePairWithSocketToHost(NULL, (CFStringRef)@"IP HERE", 7777, &readStream, &writeStream); 
_inputStream = (NSInputStream *)CFBridgingRelease(readStream); 
_outputStream = (NSOutputStream *)CFBridgingRelease(writeStream); 

[_inputStream setDelegate:self]; 
[_outputStream setDelegate:self]; 

[_inputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode]; 
[_outputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode]; 

[_inputStream open]; 
[_outputStream open]; 
} 

답변

0

나는 내 경우에는 근무 해결책을 알아 냈어. 이 코드는 현재 네트워크의 BSSID를 콘솔에 출력하고 if-statement를 사용하여 선호하는 네트워크에 맞는 BSSID가 있는지 확인합니다 :

#import <SystemConfiguration/CaptiveNetwork.h> 

//Checks which network the user is connected to. 
CFArrayRef myArray = CNCopySupportedInterfaces(); 
CFDictionaryRef myDict = CNCopyCurrentNetworkInfo(CFArrayGetValueAtIndex(myArray, 0)); 
NSLog(@"Connected at: %@", myDict); 
NSDictionary *myDictionary = (__bridge_transfer NSDictionary*)myDict; 
NSString * BSSID = [myDictionary objectForKey:@"BSSID"]; 
NSLog(@"BSSID is: %@", BSSID); 

//Handling wrong/correct BSSID. 
if (![BSSID isEqualToString:@"PREFERRED BSSID HERE"]) { 
    //Handle error however you want. 
} 
else { 
    //If correct BSSID, handle that here however you want. 
} 
}