murgatroid99 | 5de22f5 | 2015-06-12 11:21:55 -0700 | [diff] [blame] | 1 | #gRPC in 3 minutes (Objective-C) |
murgatroid99 | 042b912 | 2015-06-11 14:23:32 -0700 | [diff] [blame] | 2 | |
| 3 | ## Installation |
| 4 | |
Jorge Canizales | 54f4d53 | 2015-07-17 17:53:06 -0700 | [diff] [blame^] | 5 | To run this example you should have [Cocoapods](https://cocoapods.org/#install) installed, as well |
| 6 | as the relevant tools to generate the client library code (and a server in another language, for |
| 7 | testing). You can obtain the latter by following [these setup instructions](https://github.com/grpc/homebrew-grpc). |
murgatroid99 | 042b912 | 2015-06-11 14:23:32 -0700 | [diff] [blame] | 8 | |
murgatroid99 | 5de22f5 | 2015-06-12 11:21:55 -0700 | [diff] [blame] | 9 | ## Hello Objective-C gRPC! |
murgatroid99 | 042b912 | 2015-06-11 14:23:32 -0700 | [diff] [blame] | 10 | |
Jorge Canizales | 54f4d53 | 2015-07-17 17:53:06 -0700 | [diff] [blame^] | 11 | Here's how to build and run the Objective-C implementation of the [Hello World](https://github.com/grpc/grpc-common/blob/master/protos/helloworld.proto) |
| 12 | example used in [Getting started](https://github.com/grpc/grpc-common). |
murgatroid99 | 042b912 | 2015-06-11 14:23:32 -0700 | [diff] [blame] | 13 | |
Jorge Canizales | 54f4d53 | 2015-07-17 17:53:06 -0700 | [diff] [blame^] | 14 | The example code for this and our other examples lives in the `grpc-common` GitHub repository. Clone |
| 15 | this repository to your local machine by running the following command: |
murgatroid99 | 042b912 | 2015-06-11 14:23:32 -0700 | [diff] [blame] | 16 | |
| 17 | |
| 18 | ```sh |
| 19 | $ git clone https://github.com/grpc/grpc-common.git |
| 20 | ``` |
| 21 | |
murgatroid99 | 3ea5cc9 | 2015-06-12 16:06:37 -0700 | [diff] [blame] | 22 | Change your current directory to `grpc-common/objective-c/helloworld` |
murgatroid99 | 042b912 | 2015-06-11 14:23:32 -0700 | [diff] [blame] | 23 | |
| 24 | ```sh |
murgatroid99 | 3ea5cc9 | 2015-06-12 16:06:37 -0700 | [diff] [blame] | 25 | $ cd grpc-common/objective-c/helloworld |
murgatroid99 | 042b912 | 2015-06-11 14:23:32 -0700 | [diff] [blame] | 26 | ``` |
| 27 | |
| 28 | ### Try it! |
Jorge Canizales | 54f4d53 | 2015-07-17 17:53:06 -0700 | [diff] [blame^] | 29 | To try the sample app, we need a gRPC server running locally. Let's compile and run, for example, |
| 30 | the C++ server in this repository: |
murgatroid99 | 042b912 | 2015-06-11 14:23:32 -0700 | [diff] [blame] | 31 | |
| 32 | ```shell |
| 33 | $ pushd ../../cpp/helloworld |
| 34 | $ make |
| 35 | $ ./greeter_server & |
| 36 | $ popd |
| 37 | ``` |
| 38 | |
| 39 | Now have Cocoapods generate and install the client library for our .proto files: |
| 40 | |
| 41 | ```shell |
| 42 | $ pod install |
| 43 | ``` |
| 44 | |
Jorge Canizales | 54f4d53 | 2015-07-17 17:53:06 -0700 | [diff] [blame^] | 45 | (This might have to compile OpenSSL, which takes around 15 minutes if Cocoapods doesn't have it yet |
| 46 | on your computer's cache.) |
murgatroid99 | 042b912 | 2015-06-11 14:23:32 -0700 | [diff] [blame] | 47 | |
Jorge Canizales | 54f4d53 | 2015-07-17 17:53:06 -0700 | [diff] [blame^] | 48 | Finally, open the XCode workspace created by Cocoapods, and run the app. You can check the calling |
| 49 | code in `main.m` and see the results in XCode's log console. |
murgatroid99 | 042b912 | 2015-06-11 14:23:32 -0700 | [diff] [blame] | 50 | |
Jorge Canizales | 54f4d53 | 2015-07-17 17:53:06 -0700 | [diff] [blame^] | 51 | The code sends a `HLWHelloRequest` containing the string "Objective-C" to a local server. The server |
| 52 | responds with a `HLWHelloResponse`, which contains a string that is then output to the log. |
murgatroid99 | 5de22f5 | 2015-06-12 11:21:55 -0700 | [diff] [blame] | 53 | |
murgatroid99 | 042b912 | 2015-06-11 14:23:32 -0700 | [diff] [blame] | 54 | ## Tutorial |
| 55 | |
Jorge Canizales | 54f4d53 | 2015-07-17 17:53:06 -0700 | [diff] [blame^] | 56 | You can find a more detailed tutorial in [gRPC Basics: Objective-C](https://github.com/grpc/grpc-common/blob/master/objective-c/route_guide/README.md). |