Debian Codegraph @

examples/objective-c/helloworld/README.md

raw
1 # gRPC in 3 minutes (Objective-C)
2
3 There are currently two ways to build projects with the gRPC Objective-C library:
4 * Cocoapods & Xcode
5 * Bazel (experimental)
6
7 ## Cocoapods
8
9 ## Installation
10
11 To run this example you should have [Cocoapods](https://cocoapods.org/#install) installed, as well
12 as the relevant tools to generate the client library code (and a server in another language, for
13 testing). You can obtain the latter by following [these setup instructions](https://github.com/grpc/homebrew-grpc).
14
15 ### Hello Objective-C gRPC!
16
17 Here's how to build and run the Objective-C implementation of the [Hello World](../../protos/helloworld.proto)
18 example used in [Getting started](https://github.com/grpc/grpc/tree/master/examples).
19
20 The example code for this and our other examples lives in the `examples` directory. Clone
21 this repository at the [latest stable release tag](https://github.com/grpc/grpc/releases) to your local machine by running the following commands:
22
23
24 ```sh
25 $ git clone -b RELEASE_TAG_HERE https://github.com/grpc/grpc
26 $ cd grpc
27 $ git submodule update --init
28 ```
29
30 Change your current directory to `examples/objective-c/helloworld`
31
32 ```sh
33 $ cd examples/objective-c/helloworld
34 ```
35
36 #### Try it!
37 To try the sample app, we need a gRPC server running locally. Let's compile and run, for example,
38 the C++ server in this repository:
39
40 ```shell
41 $ pushd ../../cpp/helloworld
42 $ make
43 $ ./greeter_server &
44 $ popd
45 ```
46
47 Now have Cocoapods generate and install the client library for our .proto files:
48
49 ```shell
50 $ pod install
51 ```
52
53 (This might have to compile OpenSSL, which takes around 15 minutes if Cocoapods doesn't have it yet
54 on your computer's cache.)
55
56 Finally, open the XCode workspace created by Cocoapods, and run the app. You can check the calling
57 code in `main.m` and see the results in XCode's log console.
58
59 The code sends a `HLWHelloRequest` containing the string "Objective-C" to a local server. The server
60 responds with a `HLWHelloResponse`, which contains a string that is then output to the log.
61
62 ## Bazel
63 ### Installation
64 To run the examples in Bazel, you should have [Bazel](https://docs.bazel.build/versions/master/install-os-x.html) installed.
65
66 ### Hello Objective-C gRPC!
67 Here's how to build and run the Objective-C implementation of the [Hello World](helloworld) example.
68
69 The code for the Hello World example and others live in the `examples` directory. Clone this repository to your local machine by running the following commands:
70 ```shell
71 $ git clone --recursive https://github.com/grpc/grpc
72 ```
73
74 Next, change your directory to `examples/objective-c`
75 ```shell
76 $ cd grpc/examples/objective-c
77 ```
78
79 Now build the Hello World project:
80 ```shell
81 $ bazel build :HelloWorld
82 ```
83
84 #### Try it!
85 To run the Hello World sample properly, we need a local server. Let's compile and run the corresponding C++ server:
86 ```shell
87 $ bazel run //examples/cpp/helloworld:greeter_server
88 ```
89
90 To run the sample, you need to know the available simulator runtimes in your machine. You could either list the available runtimes yourself by running:
91 ```shell
92 $ xcrun simctl list
93 ```
94 Or just try running the app and it will let you know what is available in the error messages:
95 ```shell
96 $ bazel run :HelloWorld
97 ```
98 Note that running this command will build the project even if it is not built beforehand.
99
100 Finally, launch the app with one of the available runtimes:
101 ```shell
102 $ bazel run :HelloWorld --ios_simulator_version='<runtime>' --ios_sumlator_device='<device>'
103 ```
104
105 ## Tutorial
106
107 You can find a more detailed tutorial in [gRPC Basics: Objective-C](https://grpc.io/docs/languages/objective-c/basics).