|
Name |
|
Date |
Size |
#Lines |
LOC |
| .. | | - | - |
| GRPCClient/ | H | 25-Apr-2025 | - | 7,899 | 5,095 |
| ProtoRPC/ | H | 25-Apr-2025 | - | 1,083 | 727 |
| RxLibrary/ | H | 25-Apr-2025 | - | 1,760 | 1,019 |
| examples/ | H | 25-Apr-2025 | - | 5,855 | 5,186 |
| manual_tests/ | H | 25-Apr-2025 | - | 1,426 | 1,282 |
| tests/ | H | 25-Apr-2025 | - | 14,611 | 12,405 |
| !ProtoCompiler-gRPCCppPlugin.podspec | H A D | 25-Apr-2025 | 5.4 KiB | 119 | 107 |
| !ProtoCompiler-gRPCPlugin.podspec | H A D | 25-Apr-2025 | 5.8 KiB | 126 | 113 |
| !ProtoCompiler.podspec | H A D | 25-Apr-2025 | 6.2 KiB | 135 | 120 |
| BUILD | H A D | 25-Apr-2025 | 7.5 KiB | 280 | 258 |
| BoringSSL-GRPC.podspec | H A D | 25-Apr-2025 | 53.9 KiB | 715 | 686 |
| CronetFramework.podspec | H A D | 25-Apr-2025 | 3.8 KiB | 78 | 72 |
| NetworkTransitionBehavior.md | H A D | 25-Apr-2025 | 5.1 KiB | 93 | 81 |
| PrivacyInfo.xcprivacy | H A D | 25-Apr-2025 | 599 | 24 | 23 |
| README-CFSTREAM.md | H A D | 25-Apr-2025 | 2.3 KiB | 41 | 32 |
| README.md | H A D | 25-Apr-2025 | 10.2 KiB | 256 | 204 |
| change-comments.py | H A D | 25-Apr-2025 | 2.9 KiB | 112 | 61 |
| format-all-comments.sh | H A D | 25-Apr-2025 | 742 | 17 | 1 |
| grpc_objc_internal_library.bzl | H A D | 25-Apr-2025 | 6.6 KiB | 228 | 201 |
README-CFSTREAM.md
1[](https://cocoapods.org/pods/gRPC)
2# gRPC Objective-C with CFStream
3
4gRPC now provides the option to use Apple's CFStream API (rather than TCP
5sockets) for networking. Using CFStream resolves a bunch of network connectivity transition issues
6(see the [doc](https://github.com/grpc/grpc/blob/master/src/objective-c/NetworkTransitionBehavior.md)
7for more information).
8
9<s>CFStream integration is now in experimental state. You will need explicit opt-in to use it to get
10the benefits of resolving the issues above. We expect to make CFStream the default networking
11interface that gRPC uses when it is ready for production.</s>
12
13As of v1.21.0, CFStream integration is now the default networking stack being used by gRPC
14Objective-C on iOS layer. You get to use it automatically without special configuration needed. See
15below on how to disable CFStream in case of problem.
16
17As of v1.23.0, CFStream is enabled by default on iOS for all wrapped languages. See below on how to
18disable CFStream in case of a problem.
19
20## Usage
21If you use gRPC on iOS, CFStream is on automatically. If you use it on other
22platforms, you can turn it on with macro `GRPC_CFSTREAM=1` for the pod 'gRPC-Core' and 'gRPC'. In
23case of problem and you want to disable CFStream on iOS, you can set environment variable
24"grpc\_cfstream=0".
25
26## Caveats
27It is known to us that the CFStream API has some bug (FB6162039) which will cause gRPC's CFStream
28networking layer to stall occasionally. The issue mostly occur on MacOS systems (including iOS
29simulators on MacOS); iOS may be affected too but we have not seen issue there. gRPC provides a
30workaround to this problem with an alternative poller based on CFRunLoop. The poller can be enabled
31by setting environment variable `GRPC_CFSTREAM_RUN_LOOP=1`. Note that the poller is a client side
32only poller that does not support running a server on it. That means if an app opts in to the
33CFRunLoop-based poller, the app cannot host a gRPC server (gRPC Objective-C does not support running
34a server but other languages running on iOS do support it).
35
36## Notes
37
38- Currently we do not support platforms other than iOS, although it is likely that this integration
39 can run on MacOS targets with Apple's compiler.
40- Let us know if you meet any issue by filing issue and ping @stanleycheung.
41
README.md
1[](https://cocoapods.org/pods/gRPC)
2# gRPC for Objective-C
3gRPC Objective C library provides Objective C API for users to make gRPC calls on iOS or OS X
4platforms. Currently, the minimum supported iOS version is 9.0 and OS X version is 10.10 (Yosemite).
5
6While gRPC doesn't require the use of an IDL to describe the API of services, using one simplifies
7usage and adds some interoperability guarantees. Here we use [Protocol Buffers][], and provide a
8plugin for the Protobuf Compiler (_protoc_) to generate client libraries to communicate with gRPC
9services.
10
11- [Write your API declaration in proto format](#write-protos)
12- [Integrate a proto library in your project](#cocoapods)
13- [Use the generated library in your code](#use)
14- [Use gRPC without Protobuf](#no-proto)
15- [Alternatives to the steps above](#alternatives)
16 - [Install protoc with the gRPC plugin](#install)
17 - [Install protoc and the gRPC plugin without using Homebrew](#no-homebrew)
18 - [Integrate the generated gRPC library without using Cocoapods](#no-cocoapods)
19
20<a name="write-protos"></a>
21## Write your API declaration in proto format
22
23For this you can consult the [Protocol Buffers][]' official documentation, or learn from a quick
24example [here](https://github.com/grpc/grpc/tree/master/examples#defining-a-service).
25
26<a name="cocoapods"></a>
27## Integrate a proto library in your project
28
29Install [Cocoapods](https://cocoapods.org/#install).
30
31You need to create a Podspec file for your proto library. You may simply copy the following example
32to the directory where your `.proto` files are located, updating the name, version and license as
33necessary. You also need to set the `pods_root` variable to the correct value, depending on where
34you place this podspec relative to your Podfile.
35
36```ruby
37Pod::Spec.new do |s|
38 s.name = '<Podspec file name>'
39 s.version = '0.0.1'
40 s.license = '...'
41 s.authors = { '<your name>' => '<your email>' }
42 s.homepage = '...'
43 s.summary = '...'
44 s.source = { :git => 'https://github.com/...' }
45
46 s.ios.deployment_target = '10.0'
47 s.osx.deployment_target = '10.12'
48 s.tvos.deployment_target = '12.0'
49 s.watchos.deployment_target = '6.0'
50
51 # Base directory where the .proto files are.
52 src = '.'
53
54 # We'll use protoc with the gRPC plugin.
55 s.dependency '!ProtoCompiler-gRPCPlugin', '~> 1.0'
56
57 # Pods directory corresponding to this app's Podfile, relative to the location of this podspec.
58 pods_root = '<path to your Podfile>/Pods'
59
60 # Path where Cocoapods downloads protoc and the gRPC plugin.
61 protoc_dir = "#{pods_root}/!ProtoCompiler"
62 protoc = "#{protoc_dir}/protoc"
63 plugin = "#{pods_root}/!ProtoCompiler-gRPCPlugin/grpc_objective_c_plugin"
64
65 # Directory where you want the generated files to be placed. This is an example.
66 dir = "#{pods_root}/#{s.name}"
67
68 # Run protoc with the Objective-C and gRPC plugins to generate protocol messages and gRPC clients.
69 # You can run this command manually if you later change your protos and need to regenerate.
70 # Alternatively, you can advance the version of this podspec and run `pod update`.
71 s.prepare_command = <<-CMD
72 mkdir -p #{dir}
73 #{protoc} \
74 --plugin=protoc-gen-grpc=#{plugin} \
75 --objc_out=#{dir} \
76 --grpc_out=#{dir} \
77 -I #{src} \
78 -I #{protoc_dir} \
79 #{src}/*.proto
80 CMD
81
82 # The --objc_out plugin generates a pair of .pbobjc.h/.pbobjc.m files for each .proto file.
83 s.subspec 'Messages' do |ms|
84 ms.source_files = "#{dir}/*.pbobjc.{h,m}"
85 ms.header_mappings_dir = dir
86 ms.requires_arc = false
87 # The generated files depend on the protobuf runtime.
88 ms.dependency 'Protobuf'
89 end
90
91 # The --objcgrpc_out plugin generates a pair of .pbrpc.h/.pbrpc.m files for each .proto file with
92 # a service defined.
93 s.subspec 'Services' do |ss|
94 ss.source_files = "#{dir}/*.pbrpc.{h,m}"
95 ss.header_mappings_dir = dir
96 ss.requires_arc = true
97 # The generated files depend on the gRPC runtime, and on the files generated by `--objc_out`.
98 ss.dependency 'gRPC-ProtoRPC'
99 ss.dependency "#{s.name}/Messages"
100 end
101
102 s.pod_target_xcconfig = {
103 # This is needed by all pods that depend on Protobuf:
104 'GCC_PREPROCESSOR_DEFINITIONS' => '$(inherited) GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS=1',
105 # This is needed by all pods that depend on gRPC-RxLibrary:
106 'CLANG_ALLOW_NON_MODULAR_INCLUDES_IN_FRAMEWORK_MODULES' => 'YES',
107 }
108end
109```
110
111The file should be named `<Podspec file name>.podspec`.
112
113Note: If your proto files are in a directory hierarchy, you might want to adjust the _globs_ used in
114the sample Podspec above. For example, you could use:
115
116```ruby
117 s.prepare_command = <<-CMD
118 ...
119 `find . -name *.proto -print | xargs`
120 CMD
121 ...
122 ms.source_files = "#{dir}/*.pbobjc.{h,m}", "#{dir}/**/*.pbobjc.{h,m}"
123 ...
124 ss.source_files = "#{dir}/*.pbrpc.{h,m}", "#{dir}/**/*.pbrpc.{h,m}"
125```
126
127Once your library has a Podspec, Cocoapods can install it into any XCode project. For that, go into
128your project's directory and create a Podfile by running:
129
130```sh
131pod init
132```
133
134Next add a line to your Podfile to refer to your library's Podspec. Use `:path` as described
135[here](https://guides.cocoapods.org/using/the-podfile.html#using-the-files-from-a-folder-local-to-the-machine):
136
137```ruby
138pod '<Podspec file name>', :path => 'path/to/the/directory/of/your/podspec'
139```
140
141You can look at this [example Podfile][].
142
143Finally, in your project's directory, run:
144
145```sh
146pod install
147```
148
149<a name="use"></a>
150## Use the generated library in your code
151
152Please check the [example apps][] for examples of how to use a generated gRPC library.
153
154<a name="no-proto"></a>
155## Use gRPC without Protobuf
156
157This [tests file](https://github.com/grpc/grpc/tree/master/src/objective-c/tests/GRPCClientTests.m)
158shows how to use the generic gRPC Objective-C client without generated protobuf files.
159
160<a name="alternatives"></a>
161## Alternatives to the steps above
162
163<a name="install"></a>
164### Install _protoc_ with the gRPC plugin
165
166Although it's not recommended (because it can lead to hard-to-solve version conflicts), it is
167sometimes more convenient to install _protoc_ and the gRPC plugin in your development machine,
168instead of letting Cocoapods download the appropriate versions for you. To do so, on Mac OS X or
169later, install [homebrew][].
170
171The run the following command to install _protoc_ and the gRPC _protoc_ plugin:
172```sh
173$ curl -fsSL https://goo.gl/getgrpc | bash -
174```
175This will download and run the [gRPC install script][].
176
177<a name="no-homebrew"></a>
178### Install _protoc_ and the gRPC plugin without using Homebrew
179
180First install v3 of the Protocol Buffers compiler (_protoc_), by cloning
181[its Git repository](https://github.com/protocolbuffers/protobuf) and following these
182[installation instructions](https://github.com/protocolbuffers/protobuf#c-installation---unix)
183(the ones titled C++; don't miss the note for Mac users).
184
185Then clone this repository and execute the following commands from the root directory where it was
186cloned.
187
188Compile the gRPC plugins for _protoc_:
189```sh
190make grpc_objective_c_plugin
191```
192
193Create a symbolic link to the compiled plugin binary somewhere in your `$PATH`:
194```sh
195ln -s `pwd`/bins/opt/grpc_objective_c_plugin /usr/local/bin/protoc-gen-objcgrpc
196```
197(Notice that the name of the created link must begin with "`protoc-gen-`" for _protoc_ to recognize
198it as a plugin).
199
200If you don't want to create the symbolic link, you can alternatively copy the binary (with the
201appropriate name). Or you might prefer instead to specify the plugin's path as a flag when invoking
202_protoc_, in which case no system modification nor renaming is necessary.
203
204<a name="no-cocoapods"></a>
205### Integrate the generated gRPC library without using Cocoapods
206
207You need to compile the generated `.pbobjc.*` files (the enums and messages) without ARC support,
208and the generated `.pbrpc.*` files (the services) with ARC support. The generated code depends on
209v0.12+ of the Objective-C gRPC runtime library and v3.0.0-alpha-4+ of the Objective-C Protobuf
210runtime library.
211
212These libraries need to be integrated into your project as described in their respective Podspec
213files:
214
215* [Podspec](https://github.com/grpc/grpc/blob/master/gRPC.podspec) for the Objective-C gRPC runtime
216library. This can be tedious to configure manually.
217* [Podspec](https://github.com/protocolbuffers/protobuf/blob/master/Protobuf.podspec) for the
218Objective-C Protobuf runtime library.
219
220[Protocol Buffers]:https://developers.google.com/protocol-buffers/
221[homebrew]:http://brew.sh
222[gRPC install script]:https://raw.githubusercontent.com/grpc/homebrew-grpc/master/scripts/install
223[example Podfile]:https://github.com/grpc/grpc/blob/master/examples/objective-c/helloworld/Podfile
224[example apps]: https://github.com/grpc/grpc/tree/master/examples/objective-c
225
226## Use gRPC with OpenSSL
227gRPC uses BoringSSL as its dependency, which is a fork of OpenSSL and export a number of symbols
228that are the same as OpenSSL. gRPC avoids conflicts of these symbols by renaming BoringSSL symbols.
229
230If you need gRPC to use OpenSSL instead of BoringSSL (e.g. for the benefit of reducing the binary
231size of your product), you need to make a local `gRPC-Core` podspec and tweak it accordingly:
232- Copy the version of `/gRPC-Core.podspec` you wish to use from Github into the repository of your
233 app;
234- In your `Podfile`, add the following line:
235```
236pod `gRPC-Core`, :podspec => "." # assuming gRPC-Core.podspec is in the same directory as your Podfile
237```
238- Remove [the
239 macro](https://github.com/grpc/grpc/blob/b24b212ee585d376c618235905757b2445ac6461/gRPC-Core.podspec#L186)
240 `GRPC_SHADOW_BORINGSSL_SYMBOLS` to disable symbol renaming;
241- Substitude the `BoringSSL-GRPC`
242 [dependency](https://github.com/grpc/grpc/blob/b24b212ee585d376c618235905757b2445ac6461/gRPC-Core.podspec#L184)
243 to whatever pod of OpenSSL your other libraries use.
244
245These steps should allow gRPC to use OpenSSL and drop BoringSSL dependency. If you see any issue,
246file an issue to us.
247
248## Upgrade issue with BoringSSL
249If you were using an old version of gRPC (<= v1.14) which depended on pod `BoringSSL` rather than
250`BoringSSL-GRPC` and meet issue with the library like:
251```
252ld: framework not found openssl
253```
254updating `-framework openssl` in Other Linker Flags to `-framework openssl_grpc` in your project
255may resolve this issue (see [#16821](https://github.com/grpc/grpc/issues/16821)).
256