main.m 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. *
  3. * Copyright 2015 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. #import <UIKit/UIKit.h>
  19. #import "AppDelegate.h"
  20. #import <GRPCClient/GRPCCall+ChannelArg.h>
  21. #import <GRPCClient/GRPCCall+Tests.h>
  22. #import <GRPCClient/GRPCTransport.h>
  23. #if COCOAPODS
  24. #import <HelloWorld/Helloworld.pbrpc.h>
  25. #else
  26. #import "examples/protos/Helloworld.pbrpc.h"
  27. #endif
  28. static NSString * const kHostAddress = @"localhost:50051";
  29. @interface HLWResponseHandler : NSObject<GRPCProtoResponseHandler>
  30. @end
  31. // A response handler object dispatching messages to main queue
  32. @implementation HLWResponseHandler
  33. - (dispatch_queue_t)dispatchQueue {
  34. return dispatch_get_main_queue();
  35. }
  36. - (void)didReceiveProtoMessage:(GPBMessage *)message {
  37. NSLog(@"%@", message);
  38. }
  39. @end
  40. int main(int argc, char * argv[]) {
  41. @autoreleasepool {
  42. HLWGreeter *client = [[HLWGreeter alloc] initWithHost:kHostAddress];
  43. HLWHelloRequest *request = [HLWHelloRequest message];
  44. request.name = @"Objective-C";
  45. GRPCMutableCallOptions *options = [[GRPCMutableCallOptions alloc] init];
  46. // this example does not use TLS (secure channel); use insecure channel instead
  47. options.transport = GRPCDefaultTransportImplList.core_insecure;
  48. options.userAgentPrefix = @"HelloWorld/1.0";
  49. [[client sayHelloWithMessage:request
  50. responseHandler:[[HLWResponseHandler alloc] init]
  51. callOptions:options] start];
  52. return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
  53. }
  54. }