Ok I found the issue, I should use setProperty:forKey: instead of setValue:forKey:
Setting SSL or TLS security on NSStream
-
12-10-2022 - |
Question
I have a networking code that uses NSStream, and I want to add security. I tried to apply the documentation on the subject. I added the following lines to my working networking code:
[input setValue:NSStreamSocketSecurityLevelNegotiatedSSL forKey:NSStreamSocketSecurityLevelKey];
[output setValue:NSStreamSocketSecurityLevelNegotiatedSSL forKey:NSStreamSocketSecurityLevelKey];
The initialization code is:
-(Connection*) initWithInput:(NSInputStream*) input Output:(NSOutputStream*) output Delegate: (id <ConnectionDelegate>) delegate{
self = [super init];
if (self) {
a_delegate=delegate;
//set security
[input setValue:NSStreamSocketSecurityLevelNegotiatedSSL forKey:NSStreamSocketSecurityLevelKey];
[output setValue:NSStreamSocketSecurityLevelNegotiatedSSL forKey:NSStreamSocketSecurityLevelKey];
a_input=input;
a_output=output;
//Set delegate to self
[a_input setDelegate:self];
[a_output setDelegate:self];
//Schedule in run loop
[a_input scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
[a_output scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
//open streams
[a_input open];
[a_output open];
}
return self;
}
But when my Connection object is initialized, I get an error message and the networking doesn't work:
[<__NSCFInputStream 0x60800028e970> setValue:forUndefinedKey:]:
this class is not key value coding-compliant for the key kCFStreamPropertySocketSecurityLevel.
Is there anything I am doing wrong?
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow