Grpc
export http_proxy=socks5://127.0.0.1:1086 export https_proxy=$http_proxy export all_proxy=$http_proxy
~/grpc/examples/objective-c/helloworld ➦ cb81fe0dfa ● pod install
新版的 CocoaPods 不允许用pod repo add直接添加master库了,但是依然可以: $ cd ~/.cocoapods/repos $ pod repo remove master $ git clone https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git master 最后进入自己的工程,在自己工程的podFile第一行加上: source 'https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git'
~/grpc/examples/cpp/helloworld ➦ cb81fe0dfa ● ./greeter_server Server listening on 0.0.0.0:50051
~/grpc/examples/objective-c/helloworld ➦ cb81fe0dfa ● open HelloWorld.xcworkspace
There are currently two ways to build projects with the gRPC Objective-C library:
To run this example you should have Cocoapods 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.
Here's how to build and run the Objective-C implementation of the Hello World example used in Getting started.
The example code for this and our other examples lives in the examples
directory. Clone
this repository at the latest stable release tag to your local machine by running the following commands:
$ git clone -b RELEASE_TAG_HERE https://github.com/grpc/grpc
$ cd grpc
$ git submodule update --init
Change your current directory to examples/objective-c/helloworld
$ cd examples/objective-c/helloworld
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:
$ pushd ../../cpp/helloworld
$ make
$ ./greeter_server &
$ popd
Now have Cocoapods generate and install the client library for our .proto files:
$ pod install
(This might have to compile OpenSSL, which takes around 15 minutes if Cocoapods doesn't have it yet on your computer's cache.)
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.
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.
To run the examples in Bazel, you should have Bazel installed.
Here's how to build and run the Objective-C implementation of the Hello World 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:
$ git clone --recursive https://github.com/grpc/grpc
Next, change your directory to examples/objective-c
$ cd grpc/examples/objective-c
Now build the Hello World project:
$ bazel build :HelloWorld
To run the Hello World sample properly, we need a local server. Let's compile and run the corresponding C++ server:
$ bazel run //examples:greeter_server
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:
$ xcrun simctl list
Or just try running the app and it will let you know what is available in the error messages:
$ 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:
$ bazel run :HelloWorld --ios_simulator_version='<runtime>' --ios_sumlator_device='<device>'
You can find a more detailed tutorial in gRPC Basics: Objective-C.
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。