Check if optional method of GRPCCallOptions are implemented

pull/16190/head
Muxi Yan 6 years ago
parent 413077101e
commit f18b08a1a4
  1. 2
      src/objective-c/GRPCClient/GRPCCall.h
  2. 32
      src/objective-c/GRPCClient/GRPCCall.m

@ -149,7 +149,7 @@ extern id const kGRPCHeadersKey;
extern id const kGRPCTrailersKey; extern id const kGRPCTrailersKey;
/** An object can implement this protocol to receive responses from server from a call. */ /** An object can implement this protocol to receive responses from server from a call. */
@protocol GRPCResponseHandler @protocol GRPCResponseHandler <NSObject>
@optional @optional

@ -149,12 +149,16 @@ const char *kCFStreamVarName = "grpc_cfstream";
} }
if (headers) { if (headers) {
dispatch_async(handler.dispatchQueue, ^{ dispatch_async(handler.dispatchQueue, ^{
[handler receivedInitialMetadata:headers]; if ([handler respondsToSelector:@selector(receivedInitialMetadata:)]) {
[handler receivedInitialMetadata:headers];
}
}); });
} }
if (value) { if (value) {
dispatch_async(handler.dispatchQueue, ^{ dispatch_async(handler.dispatchQueue, ^{
[handler receivedMessage:value]; if ([handler respondsToSelector:@selector(receivedMessage:)]) {
[handler receivedMessage:value];
}
}); });
} }
} }
@ -171,11 +175,15 @@ const char *kCFStreamVarName = "grpc_cfstream";
} }
if (headers) { if (headers) {
dispatch_async(handler.dispatchQueue, ^{ dispatch_async(handler.dispatchQueue, ^{
[handler receivedInitialMetadata:headers]; if ([handler respondsToSelector:@selector(receivedInitialMetadata:)]) {
[handler receivedInitialMetadata:headers];
}
}); });
} }
dispatch_async(handler.dispatchQueue, ^{ dispatch_async(handler.dispatchQueue, ^{
[handler closedWithTrailingMetadata:self->_call.responseTrailers error:errorOrNil]; if ([handler respondsToSelector:@selector(closedWithTrailingMetadata:error:)]) {
[handler closedWithTrailingMetadata:self->_call.responseTrailers error:errorOrNil];
}
}); });
} }
}); });
@ -193,13 +201,15 @@ const char *kCFStreamVarName = "grpc_cfstream";
if (self->_handler) { if (self->_handler) {
id<GRPCResponseHandler> handler = self->_handler; id<GRPCResponseHandler> handler = self->_handler;
dispatch_async(handler.dispatchQueue, ^{ dispatch_async(handler.dispatchQueue, ^{
[handler closedWithTrailingMetadata:nil if ([handler respondsToSelector:@selector(closedWithTrailingMetadata:error:)]) {
error:[NSError errorWithDomain:kGRPCErrorDomain [handler closedWithTrailingMetadata:nil
code:GRPCErrorCodeCancelled error:[NSError errorWithDomain:kGRPCErrorDomain
userInfo:@{ code:GRPCErrorCodeCancelled
NSLocalizedDescriptionKey : userInfo:@{
@"Canceled by app" NSLocalizedDescriptionKey :
}]]; @"Canceled by app"
}]];
}
}); });
self->_handler = nil; self->_handler = nil;
} }

Loading…
Cancel
Save