• Home
Name
Date
Size
#Lines
LOC

..--

HelloWorld/12-May-2024-215185

HelloWorld.xcodeproj/12-May-2024-474459

HelloWorld.podspecD12-May-20242.2 KiB6756

PodfileD12-May-2024231 107

README.mdD12-May-20243.5 KiB10879

main.mD12-May-20242 KiB6954

README.md

1# gRPC in 3 minutes (Objective-C)
2
3There 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
11To run this example you should have [Cocoapods](https://cocoapods.org/#install) installed, as well
12as the relevant tools to generate the client library code (and a server in another language, for
13testing). You can obtain the latter by following [these setup instructions](https://github.com/grpc/homebrew-grpc).
14
15### Hello Objective-C gRPC!
16
17Here's how to build and run the Objective-C implementation of the [Hello World](../../protos/helloworld.proto)
18example used in [Getting started](https://github.com/grpc/grpc/tree/master/examples).
19
20The example code for this and our other examples lives in the `examples` directory. Clone
21this 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
30Change your current directory to `examples/objective-c/helloworld`
31
32```sh
33$ cd examples/objective-c/helloworld
34```
35
36#### Try it!
37To try the sample app, we need a gRPC server running locally. Let's compile and run, for example,
38the C++ server in this repository:
39
40```shell
41$ pushd ../../cpp/helloworld
42$ make
43$ ./greeter_server &
44$ popd
45```
46
47Now 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
54on your computer's cache.)
55
56Finally, open the XCode workspace created by Cocoapods, and run the app. You can check the calling
57code in `main.m` and see the results in XCode's log console.
58
59The code sends a `HLWHelloRequest` containing the string "Objective-C" to a local server. The server
60responds with a `HLWHelloResponse`, which contains a string that is then output to the log.
61
62## Bazel
63### Installation
64To 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!
67Here's how to build and run the Objective-C implementation of the [Hello World](helloworld) example.
68
69The 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
74Next, change your directory to `examples/objective-c`
75```shell
76$ cd grpc/examples/objective-c
77```
78
79Now build the Hello World project:
80```shell
81$ bazel build :HelloWorld
82```
83
84#### Try it!
85To 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:greeter_server
88```
89
90To 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```
94Or 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```
98Note that running this command will build the project even if it is not built beforehand.
99
100Finally, 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
107You can find a more detailed tutorial in [gRPC Basics: Objective-C](https://grpc.io/docs/languages/objective-c/basics).
108