@ -38,13 +38,17 @@
@ implementation GRPCSecureChannel
@ implementation GRPCSecureChannel
- ( instancetype ) initWithHost : ( NSString * ) host {
- ( instancetype ) initWithHost : ( NSString * ) host {
/ / TODO ( jcanizales ) : Load certs only once .
static const grpc_credentials * kCredentials ;
NSURL * certsURL = [ [ NSBundle mainBundle ] URLForResource : @ "gRPC . bundle / roots " withExtension : @ "pem "] ;
static dispatch_once_t loading ;
NSData * certsData = [ NSData dataWithContentsOfURL : certsURL ] ;
dispatch_once ( & loading , ^{
NSString * certsString = [ [ NSString alloc ] initWithData : certsData encoding : NSUTF8StringEncoding ] ;
/ / Do not use NSBundle . mainBundle , as it ' s nil for tests of library projects .
NSBundle * bundle = [ NSBundle bundleForClass : self . class ] ;
grpc_credentials * credentials = grpc_ssl_credentials_create ( certsString . UTF8String , NULL ) ;
NSString * certsPath = [ bundle pathForResource : @ "gRPC . bundle / roots " ofType : @ "pem "] ;
return ( self = [ super initWithChannel : grpc_secure_channel_create ( credentials ,
NSData * certsData = [ NSData dataWithContentsOfFile : certsPath ] ;
NSString * certsString = [ [ NSString alloc ] initWithData : certsData encoding : NSUTF8StringEncoding ] ;
kCredentials = grpc_ssl_credentials_create ( certsString . UTF8String , NULL ) ;
} ) ;
return ( self = [ super initWithChannel : grpc_secure_channel_create ( kCredentials ,
host . UTF8String ,
host . UTF8String ,
NULL ) ] ) ;
NULL ) ] ) ;
}
}