1/* 2 * 3 * Copyright 2018 gRPC authors. 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 * 17 */ 18 19#import <Cocoa/Cocoa.h> 20 21#import <GRPCClient/GRPCCall+ChannelArg.h> 22#import <GRPCClient/GRPCCall+Tests.h> 23#import <GRPCClient/GRPCTransport.h> 24#if COCOAPODS 25#import <HelloWorld/Helloworld.pbrpc.h> 26#else 27#import "examples/protos/Helloworld.pbrpc.h" 28#endif 29 30static NSString * const kHostAddress = @"localhost:50051"; 31 32@interface HLWResponseHandler : NSObject<GRPCProtoResponseHandler> 33 34@end 35 36// A response handler object dispatching messages to main queue 37@implementation HLWResponseHandler 38 39- (dispatch_queue_t)dispatchQueue { 40 return dispatch_get_main_queue(); 41} 42 43- (void)didReceiveProtoMessage:(GPBMessage *)message { 44 NSLog(@"%@", message); 45} 46 47@end 48 49int main(int argc, const char * argv[]) { 50 @autoreleasepool { 51 HLWGreeter *client = [[HLWGreeter alloc] initWithHost:kHostAddress]; 52 53 HLWHelloRequest *request = [HLWHelloRequest message]; 54 request.name = @"Objective-C"; 55 56 GRPCMutableCallOptions *options = [[GRPCMutableCallOptions alloc] init]; 57 // this example does not use TLS (secure channel); use insecure channel instead 58 options.transport = GRPCDefaultTransportImplList.core_insecure; 59 options.userAgentPrefix = @"HelloWorld/1.0"; 60 61 GRPCUnaryProtoCall *call = [client sayHelloWithMessage:request 62 responseHandler:[[HLWResponseHandler alloc] init] 63 callOptions:options]; 64 65 [call start]; 66 } 67 68 return NSApplicationMain(argc, argv); 69} 70