I have network code that uses NSStream and I want to add security. I tried to apply the documentation on this. I added the following lines to my working network code:
[input setValue:NSStreamSocketSecurityLevelNegotiatedSSL forKey:NSStreamSocketSecurityLevelKey]
[output setValue:NSStreamSocketSecurityLevelNegotiatedSSL forKey:NSStreamSocketSecurityLevelKey]
Initialization Code:
-(Connection*) initWithInput:(NSInputStream*) input Output:(NSOutputStream*) output Delegate: (id <ConnectionDelegate>) delegate{
self = [super init];
if (self) {
a_delegate=delegate;
[input setValue:NSStreamSocketSecurityLevelNegotiatedSSL forKey:NSStreamSocketSecurityLevelKey];
[output setValue:NSStreamSocketSecurityLevelNegotiatedSSL forKey:NSStreamSocketSecurityLevelKey];
a_input=input;
a_output=output;
[a_input setDelegate:self];
[a_output setDelegate:self];
[a_input scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
[a_output scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
[a_input open];
[a_output open];
}
return self;
}
But when my Connection object is initialized, an error message appears, and network connectivity does not work:
[<__NSCFInputStream 0x60800028e970> setValue:forUndefinedKey:]:
this class is not key value coding-compliant for the key kCFStreamPropertySocketSecurityLevel.
Is there something I'm doing wrong?
source
share