The C based gRPC (C++, Python, Ruby, Objective-C, PHP, C#)
https://grpc.io/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
108 lines
3.5 KiB
108 lines
3.5 KiB
8 years ago
|
# gRPC in 3 minutes (Objective-C)
|
||
10 years ago
|
|
||
6 years ago
|
There are currently two ways to build projects with the gRPC Objective-C library:
|
||
|
* Cocoapods & Xcode
|
||
|
* Bazel (experimental)
|
||
|
|
||
|
## Cocoapods
|
||
|
|
||
10 years ago
|
## Installation
|
||
|
|
||
10 years ago
|
To run this example you should have [Cocoapods](https://cocoapods.org/#install) installed, as well
|
||
|
as the relevant tools to generate the client library code (and a server in another language, for
|
||
|
testing). You can obtain the latter by following [these setup instructions](https://github.com/grpc/homebrew-grpc).
|
||
10 years ago
|
|
||
6 years ago
|
### Hello Objective-C gRPC!
|
||
10 years ago
|
|
||
10 years ago
|
Here's how to build and run the Objective-C implementation of the [Hello World](../../protos/helloworld.proto)
|
||
10 years ago
|
example used in [Getting started](https://github.com/grpc/grpc/tree/master/examples).
|
||
10 years ago
|
|
||
10 years ago
|
The example code for this and our other examples lives in the `examples` directory. Clone
|
||
5 years ago
|
this repository at the [latest stable release tag](https://github.com/grpc/grpc/releases) to your local machine by running the following commands:
|
||
10 years ago
|
|
||
|
|
||
|
```sh
|
||
5 years ago
|
$ git clone -b RELEASE_TAG_HERE https://github.com/grpc/grpc
|
||
10 years ago
|
$ cd grpc
|
||
|
$ git submodule update --init
|
||
10 years ago
|
```
|
||
|
|
||
10 years ago
|
Change your current directory to `examples/objective-c/helloworld`
|
||
10 years ago
|
|
||
|
```sh
|
||
10 years ago
|
$ cd examples/objective-c/helloworld
|
||
10 years ago
|
```
|
||
|
|
||
6 years ago
|
#### Try it!
|
||
10 years ago
|
To try the sample app, we need a gRPC server running locally. Let's compile and run, for example,
|
||
|
the C++ server in this repository:
|
||
10 years ago
|
|
||
|
```shell
|
||
|
$ pushd ../../cpp/helloworld
|
||
|
$ make
|
||
|
$ ./greeter_server &
|
||
|
$ popd
|
||
|
```
|
||
|
|
||
|
Now have Cocoapods generate and install the client library for our .proto files:
|
||
|
|
||
|
```shell
|
||
|
$ pod install
|
||
|
```
|
||
|
|
||
10 years ago
|
(This might have to compile OpenSSL, which takes around 15 minutes if Cocoapods doesn't have it yet
|
||
|
on your computer's cache.)
|
||
10 years ago
|
|
||
10 years ago
|
Finally, open the XCode workspace created by Cocoapods, and run the app. You can check the calling
|
||
|
code in `main.m` and see the results in XCode's log console.
|
||
10 years ago
|
|
||
10 years ago
|
The code sends a `HLWHelloRequest` containing the string "Objective-C" to a local server. The server
|
||
|
responds with a `HLWHelloResponse`, which contains a string that is then output to the log.
|
||
10 years ago
|
|
||
6 years ago
|
## Bazel
|
||
|
### Installation
|
||
|
To run the examples in Bazel, you should have [Bazel](https://docs.bazel.build/versions/master/install-os-x.html) installed.
|
||
|
|
||
|
### Hello Objective-C gRPC!
|
||
|
Here's how to build and run the Objective-C implementation of the [Hello World](helloworld) example.
|
||
|
|
||
|
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:
|
||
|
```shell
|
||
|
$ git clone --recursive https://github.com/grpc/grpc
|
||
|
```
|
||
|
|
||
|
Next, change your directory to `examples/objective-c`
|
||
|
```shell
|
||
|
$ cd grpc/examples/objective-c
|
||
|
```
|
||
|
|
||
|
Now build the Hello World project:
|
||
|
```shell
|
||
|
$ bazel build :HelloWorld
|
||
|
```
|
||
|
|
||
|
#### Try it!
|
||
|
To run the Hello World sample properly, we need a local server. Let's compile and run the corresponding C++ server:
|
||
|
```shell
|
||
4 years ago
|
$ bazel run //examples/cpp/helloworld:greeter_server
|
||
6 years ago
|
```
|
||
|
|
||
|
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:
|
||
|
```shell
|
||
|
$ xcrun simctl list
|
||
|
```
|
||
|
Or just try running the app and it will let you know what is available in the error messages:
|
||
|
```shell
|
||
|
$ bazel run :HelloWorld
|
||
|
```
|
||
|
Note that running this command will build the project even if it is not built beforehand.
|
||
|
|
||
|
Finally, launch the app with one of the available runtimes:
|
||
|
```shell
|
||
|
$ bazel run :HelloWorld --ios_simulator_version='<runtime>' --ios_sumlator_device='<device>'
|
||
|
```
|
||
|
|
||
10 years ago
|
## Tutorial
|
||
|
|
||
5 years ago
|
You can find a more detailed tutorial in [gRPC Basics: Objective-C](https://grpc.io/docs/languages/objective-c/basics).
|