md_src_objective-c__r_e_a_d_m_e.html 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
  5. <meta http-equiv="X-UA-Compatible" content="IE=9"/>
  6. <meta name="generator" content="Doxygen 1.8.17"/>
  7. <meta name="viewport" content="width=device-width, initial-scale=1"/>
  8. <title>GRPC Objective-C: README</title>
  9. <link href="tabs.css" rel="stylesheet" type="text/css"/>
  10. <script type="text/javascript" src="jquery.js"></script>
  11. <script type="text/javascript" src="dynsections.js"></script>
  12. <link href="search/search.css" rel="stylesheet" type="text/css"/>
  13. <script type="text/javascript" src="search/searchdata.js"></script>
  14. <script type="text/javascript" src="search/search.js"></script>
  15. <link href="doxygen.css" rel="stylesheet" type="text/css" />
  16. </head>
  17. <body>
  18. <div id="top"><!-- do not remove this div, it is closed by doxygen! -->
  19. <div id="titlearea">
  20. <table cellspacing="0" cellpadding="0">
  21. <tbody>
  22. <tr style="height: 56px;">
  23. <td id="projectalign" style="padding-left: 0.5em;">
  24. <div id="projectname">GRPC Objective-C
  25. &#160;<span id="projectnumber">1.36.1</span>
  26. </div>
  27. </td>
  28. </tr>
  29. </tbody>
  30. </table>
  31. </div>
  32. <!-- end header part -->
  33. <!-- Generated by Doxygen 1.8.17 -->
  34. <script type="text/javascript">
  35. /* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
  36. var searchBox = new SearchBox("searchBox", "search",false,'Search');
  37. /* @license-end */
  38. </script>
  39. <script type="text/javascript" src="menudata.js"></script>
  40. <script type="text/javascript" src="menu.js"></script>
  41. <script type="text/javascript">
  42. /* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
  43. $(function() {
  44. initMenu('',true,false,'search.php','Search');
  45. $(document).ready(function() { init_search(); });
  46. });
  47. /* @license-end */</script>
  48. <div id="main-nav"></div>
  49. <!-- window showing the filter options -->
  50. <div id="MSearchSelectWindow"
  51. onmouseover="return searchBox.OnSearchSelectShow()"
  52. onmouseout="return searchBox.OnSearchSelectHide()"
  53. onkeydown="return searchBox.OnSearchSelectKey(event)">
  54. </div>
  55. <!-- iframe showing the search results (closed by default) -->
  56. <div id="MSearchResultsWindow">
  57. <iframe src="javascript:void(0)" frameborder="0"
  58. name="MSearchResults" id="MSearchResults">
  59. </iframe>
  60. </div>
  61. </div><!-- top -->
  62. <div class="PageDoc"><div class="header">
  63. <div class="headertitle">
  64. <div class="title">README </div> </div>
  65. </div><!--header-->
  66. <div class="contents">
  67. <div class="textblock"><p><a href="https://cocoapods.org/pods/gRPC"><object type="image/svg+xml" data="https://img.shields.io/cocoapods/v/gRPC.svg" style="pointer-events: none;">Cocoapods</object></a> </p>
  68. <h1><a class="anchor" id="autotoc_md268"></a>
  69. gRPC for Objective-C</h1>
  70. <p>gRPC Objective C library provides Objective C API for users to make gRPC calls on iOS or OS X platforms. Currently, the minimum supported iOS version is 9.0 and OS X version is 10.10 (Yosemite).</p>
  71. <p>While gRPC doesn't require the use of an IDL to describe the API of services, using one simplifies usage and adds some interoperability guarantees. Here we use <a href="https://developers.google.com/protocol-buffers/">Protocol Buffers</a>, and provide a plugin for the Protobuf Compiler (<em>protoc</em>) to generate client libraries to communicate with gRPC services.</p>
  72. <ul>
  73. <li><a href="#write-protos">Write your API declaration in proto format</a></li>
  74. <li><a href="#cocoapods">Integrate a proto library in your project</a></li>
  75. <li><a href="#use">Use the generated library in your code</a></li>
  76. <li><a href="#no-proto">Use gRPC without Protobuf</a></li>
  77. <li><a href="#alternatives">Alternatives to the steps above</a><ul>
  78. <li><a href="#install">Install protoc with the gRPC plugin</a></li>
  79. <li><a href="#no-homebrew">Install protoc and the gRPC plugin without using Homebrew</a></li>
  80. <li><a href="#no-cocoapods">Integrate the generated gRPC library without using Cocoapods</a></li>
  81. </ul>
  82. </li>
  83. </ul>
  84. <p><a class="anchor" id="write-protos"></a> </p>
  85. <h2><a class="anchor" id="autotoc_md269"></a>
  86. Write your API declaration in proto format</h2>
  87. <p>For this you can consult the <a href="https://developers.google.com/protocol-buffers/">Protocol Buffers</a>' official documentation, or learn from a quick example <a href="https://github.com/grpc/grpc/tree/master/examples#defining-a-service">here</a>.</p>
  88. <p><a class="anchor" id="cocoapods"></a> </p>
  89. <h2><a class="anchor" id="autotoc_md270"></a>
  90. Integrate a proto library in your project</h2>
  91. <p>Install <a href="https://cocoapods.org/#install">Cocoapods</a>.</p>
  92. <p>You need to create a Podspec file for your proto library. You may simply copy the following example to the directory where your <code>.proto</code> files are located, updating the name, version and license as necessary. You also need to set the <code>pods_root</code> variable to the correct value, depending on where you place this podspec relative to your Podfile.</p>
  93. <div class="fragment"><div class="line">Pod::Spec.new do |s|</div>
  94. <div class="line"> s.name = &#39;&lt;Podspec file name&gt;&#39;</div>
  95. <div class="line"> s.version = &#39;0.0.1&#39;</div>
  96. <div class="line"> s.license = &#39;...&#39;</div>
  97. <div class="line"> s.authors = { &#39;&lt;your name&gt;&#39; =&gt; &#39;&lt;your email&gt;&#39; }</div>
  98. <div class="line"> s.homepage = &#39;...&#39;</div>
  99. <div class="line"> s.summary = &#39;...&#39;</div>
  100. <div class="line"> s.source = { :git =&gt; &#39;https://github.com/...&#39; }</div>
  101. <div class="line"> </div>
  102. <div class="line"> s.ios.deployment_target = &#39;9.0&#39;</div>
  103. <div class="line"> s.osx.deployment_target = &#39;10.10&#39;</div>
  104. <div class="line"> </div>
  105. <div class="line"> # Base directory where the .proto files are.</div>
  106. <div class="line"> src = &#39;.&#39;</div>
  107. <div class="line"> </div>
  108. <div class="line"> # We&#39;ll use protoc with the gRPC plugin.</div>
  109. <div class="line"> s.dependency &#39;!ProtoCompiler-gRPCPlugin&#39;, &#39;~&gt; 1.0&#39;</div>
  110. <div class="line"> </div>
  111. <div class="line"> # Pods directory corresponding to this app&#39;s Podfile, relative to the location of this podspec.</div>
  112. <div class="line"> pods_root = &#39;&lt;path to your Podfile&gt;/Pods&#39;</div>
  113. <div class="line"> </div>
  114. <div class="line"> # Path where Cocoapods downloads protoc and the gRPC plugin.</div>
  115. <div class="line"> protoc_dir = &quot;#{pods_root}/!ProtoCompiler&quot;</div>
  116. <div class="line"> protoc = &quot;#{protoc_dir}/protoc&quot;</div>
  117. <div class="line"> plugin = &quot;#{pods_root}/!ProtoCompiler-gRPCPlugin/grpc_objective_c_plugin&quot;</div>
  118. <div class="line"> </div>
  119. <div class="line"> # Directory where you want the generated files to be placed. This is an example.</div>
  120. <div class="line"> dir = &quot;#{pods_root}/#{s.name}&quot;</div>
  121. <div class="line"> </div>
  122. <div class="line"> # Run protoc with the Objective-C and gRPC plugins to generate protocol messages and gRPC clients.</div>
  123. <div class="line"> # You can run this command manually if you later change your protos and need to regenerate.</div>
  124. <div class="line"> # Alternatively, you can advance the version of this podspec and run `pod update`.</div>
  125. <div class="line"> s.prepare_command = &lt;&lt;-CMD</div>
  126. <div class="line"> mkdir -p #{dir}</div>
  127. <div class="line"> #{protoc} \</div>
  128. <div class="line"> --plugin=protoc-gen-grpc=#{plugin} \</div>
  129. <div class="line"> --objc_out=#{dir} \</div>
  130. <div class="line"> --grpc_out=#{dir} \</div>
  131. <div class="line"> -I #{src} \</div>
  132. <div class="line"> -I #{protoc_dir} \</div>
  133. <div class="line"> #{src}/*.proto</div>
  134. <div class="line"> CMD</div>
  135. <div class="line"> </div>
  136. <div class="line"> # The --objc_out plugin generates a pair of .pbobjc.h/.pbobjc.m files for each .proto file.</div>
  137. <div class="line"> s.subspec &#39;Messages&#39; do |ms|</div>
  138. <div class="line"> ms.source_files = &quot;#{dir}/*.pbobjc.{h,m}&quot;</div>
  139. <div class="line"> ms.header_mappings_dir = dir</div>
  140. <div class="line"> ms.requires_arc = false</div>
  141. <div class="line"> # The generated files depend on the protobuf runtime.</div>
  142. <div class="line"> ms.dependency &#39;Protobuf&#39;</div>
  143. <div class="line"> end</div>
  144. <div class="line"> </div>
  145. <div class="line"> # The --objcgrpc_out plugin generates a pair of .pbrpc.h/.pbrpc.m files for each .proto file with</div>
  146. <div class="line"> # a service defined.</div>
  147. <div class="line"> s.subspec &#39;Services&#39; do |ss|</div>
  148. <div class="line"> ss.source_files = &quot;#{dir}/*.pbrpc.{h,m}&quot;</div>
  149. <div class="line"> ss.header_mappings_dir = dir</div>
  150. <div class="line"> ss.requires_arc = true</div>
  151. <div class="line"> # The generated files depend on the gRPC runtime, and on the files generated by `--objc_out`.</div>
  152. <div class="line"> ss.dependency &#39;gRPC-ProtoRPC&#39;</div>
  153. <div class="line"> ss.dependency &quot;#{s.name}/Messages&quot;</div>
  154. <div class="line"> end</div>
  155. <div class="line"> </div>
  156. <div class="line"> s.pod_target_xcconfig = {</div>
  157. <div class="line"> # This is needed by all pods that depend on Protobuf:</div>
  158. <div class="line"> &#39;GCC_PREPROCESSOR_DEFINITIONS&#39; =&gt; &#39;$(inherited) GPB_USE_PROTOBUF_FRAMEWORK_IMPORTS=1&#39;,</div>
  159. <div class="line"> # This is needed by all pods that depend on gRPC-RxLibrary:</div>
  160. <div class="line"> &#39;CLANG_ALLOW_NON_MODULAR_INCLUDES_IN_FRAMEWORK_MODULES&#39; =&gt; &#39;YES&#39;,</div>
  161. <div class="line"> }</div>
  162. <div class="line">end</div>
  163. </div><!-- fragment --><p>The file should be named <code>&lt;Podspec file name&gt;.podspec</code>.</p>
  164. <p>Note: If your proto files are in a directory hierarchy, you might want to adjust the <em>globs</em> used in the sample Podspec above. For example, you could use:</p>
  165. <p>```ruby s.prepare_command = &lt;&lt;-CMD ... <code>find . -name *.proto -print | xargs</code> CMD ... ms.source_files = "#{dir}/*.pbobjc.{h,m}", "#{dir}/**/*.pbobjc.{h,m}" ... ss.source_files = "#{dir}/*.pbrpc.{h,m}", "#{dir}/**/*.pbrpc.{h,m}" </p><div class="fragment"><div class="line">Once your library has a Podspec, Cocoapods can install it into any XCode project. For that, go into</div>
  166. <div class="line">your project&#39;s directory and create a Podfile by running:</div>
  167. <div class="line"> </div>
  168. <div class="line">```sh</div>
  169. <div class="line">pod init</div>
  170. </div><!-- fragment --><p>Next add a line to your Podfile to refer to your library's Podspec. Use <code>:path</code> as described <a href="https://guides.cocoapods.org/using/the-podfile.html#using-the-files-from-a-folder-local-to-the-machine">here</a>:</p>
  171. <div class="fragment"><div class="line">pod &#39;&lt;Podspec file name&gt;&#39;, :path =&gt; &#39;path/to/the/directory/of/your/podspec&#39;</div>
  172. </div><!-- fragment --><p>You can look at this <a href="https://github.com/grpc/grpc/blob/master/examples/objective-c/helloworld/Podfile">example Podfile</a>.</p>
  173. <p>Finally, in your project's directory, run:</p>
  174. <div class="fragment"><div class="line">pod install</div>
  175. </div><!-- fragment --><p><a class="anchor" id="use"></a> </p>
  176. <h2><a class="anchor" id="autotoc_md271"></a>
  177. Use the generated library in your code</h2>
  178. <p>Please check the <a href="https://github.com/grpc/grpc/tree/master/examples/objective-c">example apps</a> for examples of how to use a generated gRPC library.</p>
  179. <p><a class="anchor" id="no-proto"></a> </p>
  180. <h2><a class="anchor" id="autotoc_md272"></a>
  181. Use gRPC without Protobuf</h2>
  182. <p>This <a href="https://github.com/grpc/grpc/tree/master/src/objective-c/tests/GRPCClientTests.m">tests file</a> shows how to use the generic gRPC Objective-C client without generated protobuf files.</p>
  183. <p><a class="anchor" id="alternatives"></a> </p>
  184. <h2><a class="anchor" id="autotoc_md273"></a>
  185. Alternatives to the steps above</h2>
  186. <p><a class="anchor" id="install"></a> </p>
  187. <h3><a class="anchor" id="autotoc_md274"></a>
  188. Install &lt;em&gt;protoc&lt;/em&gt; with the gRPC plugin</h3>
  189. <p>Although it's not recommended (because it can lead to hard-to-solve version conflicts), it is sometimes more convenient to install <em>protoc</em> and the gRPC plugin in your development machine, instead of letting Cocoapods download the appropriate versions for you. To do so, on Mac OS X or later, install <a href="http://brew.sh">homebrew</a>.</p>
  190. <p>The run the following command to install <em>protoc</em> and the gRPC <em>protoc</em> plugin: </p><div class="fragment"><div class="line">$ curl -fsSL https://goo.gl/getgrpc | bash -</div>
  191. </div><!-- fragment --><p>This will download and run the <a href="https://raw.githubusercontent.com/grpc/homebrew-grpc/master/scripts/install">gRPC install script</a>.</p>
  192. <p><a class="anchor" id="no-homebrew"></a> </p>
  193. <h3><a class="anchor" id="autotoc_md275"></a>
  194. Install &lt;em&gt;protoc&lt;/em&gt; and the gRPC plugin without using Homebrew</h3>
  195. <p>First install v3 of the Protocol Buffers compiler (<em>protoc</em>), by cloning <a href="https://github.com/google/protobuf">its Git repository</a> and following these <a href="https://github.com/google/protobuf#c-installation---unix">installation instructions</a> (the ones titled C++; don't miss the note for Mac users).</p>
  196. <p>Then clone this repository and execute the following commands from the root directory where it was cloned.</p>
  197. <p>Compile the gRPC plugins for <em>protoc</em>: </p><div class="fragment"><div class="line">make grpc_objective_c_plugin</div>
  198. </div><!-- fragment --><p>Create a symbolic link to the compiled plugin binary somewhere in your <code>$PATH</code>: </p><div class="fragment"><div class="line">ln -s `pwd`/bins/opt/grpc_objective_c_plugin /usr/local/bin/protoc-gen-objcgrpc</div>
  199. </div><!-- fragment --><p>(Notice that the name of the created link must begin with "`protoc-gen-`" for <em>protoc</em> to recognize it as a plugin).</p>
  200. <p>If you don't want to create the symbolic link, you can alternatively copy the binary (with the appropriate name). Or you might prefer instead to specify the plugin's path as a flag when invoking <em>protoc</em>, in which case no system modification nor renaming is necessary.</p>
  201. <p><a class="anchor" id="no-cocoapods"></a> </p>
  202. <h3><a class="anchor" id="autotoc_md276"></a>
  203. Integrate the generated gRPC library without using Cocoapods</h3>
  204. <p>You need to compile the generated <code>.pbobjc.*</code> files (the enums and messages) without ARC support, and the generated <code>.pbrpc.*</code> files (the services) with ARC support. The generated code depends on v0.12+ of the Objective-C gRPC runtime library and v3.0.0-alpha-4+ of the Objective-C Protobuf runtime library.</p>
  205. <p>These libraries need to be integrated into your project as described in their respective Podspec files:</p>
  206. <ul>
  207. <li><a href="https://github.com/grpc/grpc/blob/master/gRPC.podspec">Podspec</a> for the Objective-C gRPC runtime library. This can be tedious to configure manually.</li>
  208. <li><a href="https://github.com/google/protobuf/blob/master/Protobuf.podspec">Podspec</a> for the Objective-C Protobuf runtime library.</li>
  209. </ul>
  210. <h2><a class="anchor" id="autotoc_md277"></a>
  211. Use gRPC with OpenSSL</h2>
  212. <p>gRPC uses BoringSSL as its dependency, which is a fork of OpenSSL and export a number of symbols that are the same as OpenSSL. gRPC avoids conflicts of these symbols by renaming BoringSSL symbols.</p>
  213. <p>If you need gRPC to use OpenSSL instead of BoringSSL (e.g. for the benefit of reducing the binary size of your product), you need to make a local <code>gRPC-Core</code> podspec and tweak it accordingly:</p><ul>
  214. <li>Copy the version of <code>/gRPC-Core.podspec</code> you wish to use from Github into the repository of your app;</li>
  215. <li>In your <code>Podfile</code>, add the following line: <div class="fragment"><div class="line">pod `gRPC-Core`, :podspec =&gt; &quot;.&quot; # assuming gRPC-Core.podspec is in the same directory as your Podfile</div>
  216. </div><!-- fragment --></li>
  217. <li>Remove <a href="https://github.com/grpc/grpc/blob/b24b212ee585d376c618235905757b2445ac6461/gRPC-Core.podspec#L186">the macro</a> <code>GRPC_SHADOW_BORINGSSL_SYMBOLS</code> to disable symbol renaming;</li>
  218. <li>Substitude the <code>BoringSSL-GRPC</code> <a href="https://github.com/grpc/grpc/blob/b24b212ee585d376c618235905757b2445ac6461/gRPC-Core.podspec#L184">dependency</a> to whatever pod of OpenSSL your other libraries use.</li>
  219. </ul>
  220. <p>These steps should allow gRPC to use OpenSSL and drop BoringSSL dependency. If you see any issue, file an issue to us.</p>
  221. <h2><a class="anchor" id="autotoc_md278"></a>
  222. Upgrade issue with BoringSSL</h2>
  223. <p>If you were using an old version of gRPC (&lt;= v1.14) which depended on pod <code>BoringSSL</code> rather than <code>BoringSSL-GRPC</code> and meet issue with the library like: </p><div class="fragment"><div class="line">ld: framework not found openssl</div>
  224. </div><!-- fragment --><p>updating <code>-framework openssl</code> in Other Linker Flags to <code>-framework openssl_grpc</code> in your project may resolve this issue (see <a href="https://github.com/grpc/grpc/issues/16821">#16821</a>). </p>
  225. </div></div><!-- contents -->
  226. </div><!-- PageDoc -->
  227. <!-- start footer part -->
  228. <hr class="footer"/><address class="footer"><small>
  229. Generated on Wed Mar 3 2021 19:20:10 for GRPC Objective-C by &#160;<a href="http://www.doxygen.org/index.html">
  230. <img class="footer" src="doxygen.png" alt="doxygen"/>
  231. </a> 1.8.17
  232. </small></address>
  233. </body>
  234. </html>