{"id":509,"date":"2018-04-12T20:06:12","date_gmt":"2018-04-12T12:06:12","guid":{"rendered":"http:\/\/www.fh1986.com\/?p=509"},"modified":"2018-04-12T20:09:13","modified_gmt":"2018-04-12T12:09:13","slug":"reactive-native-%e5%9c%a8ios%e4%b8%ad%e9%9b%86%e6%88%90%e4%b8%ad%e7%9a%84%e8%b8%a9%e5%9d%91%e7%bb%8f%e5%8e%86","status":"publish","type":"post","link":"https:\/\/www.fh1986.com\/index.php\/archives\/509.html","title":{"rendered":"Reactive Native \u5728IOS\u4e2d\u96c6\u6210\u4e2d\u7684\u8e29\u5751\u7ecf\u5386"},"content":{"rendered":"<h2>\u4ec0\u4e48\u662fReact Native<\/h2>\n<p>React-Native \u662f\u7531Facebook\u51fa\u54c1\u7684\u4e00\u6b3e\u53ef\u4ee5\u4f7f\u7528JavaScript\u6765\u7f16\u5199\u539f\u751fapp\u7684\u6846\u67b6\uff0c\u5b98\u65b9\u8bf4\u660e\u662f\uff1aA framework for building native app with React(\u4e00\u4e2a\u4f7f\u7528React\u6765\u7f16\u5199\u539f\u751fapp\u7684\u6846\u67b6)\uff0c\u7136\u800c\u8fd9\u4e2aReact\u4e5f\u662f\u7531\u8be5\u516c\u53f8\u51fa\u54c1\u7684\u4e00\u6b3e\u53ef\u4ee5\u7528\u6765\u7f16\u5199\u7528\u6237\u754c\u9762\u7684JS\u5e93\u3002\u4e8c\u8005\u7684\u51fa\u73b0\uff0c\u4ee5\u5176\u5f3a\u5927\u7684\u529f\u80fd\u548c\u4fbf\u6377\u7684\u4f7f\u7528\u65b9\u5f0f\u8fc5\u901f\u88ab\u5e7f\u5927\u5f00\u53d1\u8005\u4f7f\u7528\uff0c\u5e76\u5728\u5404\u5927\u5e73\u53f0\u7684\u5e94\u7528\u7814\u53d1\u4e2d\u5360\u636e\u4e86\u81ea\u5df1\u7684\u4e00\u5e2d\u4e4b\u5730\u3002<\/p>\n<p><!--more--><\/p>\n<blockquote><p>GitHub: <a href=\"https:\/\/github.com\/facebook\/react-native\">React-Native<\/a> ,\u00a0 <a href=\"https:\/\/github.com\/facebook\/react\">React<\/a><\/p>\n<p>\u5b98\u7f51\uff1a<a href=\"http:\/\/facebook.github.io\/react-native\/\">React-Native<\/a> ,<a href=\"http:\/\/reactnative.cn\/\">React-Native\u4e2d\u6587\u5b98\u7f51<\/a> , <a href=\"https:\/\/facebook.github.io\/react\/\">React<\/a><\/p><\/blockquote>\n<h2>\u642d\u5efaReact-Native\u5f00\u53d1\u73af\u5883<\/h2>\n<p>1.\u8fd9\u4e00\u6b65\u6bd4\u8f83\u7b80\u5355\uff0c\u5982\u679c\u4e0d\u61c2\uff0c\u53ef\u4ee5\u53c2\u8003\u7f51\u4e0a\u7684\u6587\u7ae0\uff0c\u6216\u8005ReactNative\u5b98\u7f51\u7684\u76f8\u5173\u9875\u9762\u3002<\/p>\n<p>2.\u5b89\u88c5cocoapods\uff0c\u8fd9\u662f\u4e00\u4e2a\u5305\u7ba1\u7406\u5de5\u5177\u3002<\/p>\n<p>3.\u4e00\u4e2a\u6bd4\u8f83\u597d\u7528\u7684\u6587\u672c\u7f16\u8f91\u5668\u3002\u6ce8\u610f\uff0c\u4e0d\u8981\u4f7f\u7528mac\u81ea\u5e26\u7684\u6587\u672c\u7f16\u8f91\u5668\uff0c\u4e0d\u597d\u7528\uff0c\u5982\u679c\u8981\u7528\uff0c\u8bf7\u628a\u8bed\u8a00\u8bbe\u7f6e\u4e3a\u82f1\u6587\uff0c\u5426\u5219\u5404\u79cd\u4e2d\u6587\u5168\u534a\u89d2\u8981\u6298\u817e\u6b7b\u4eba\u3002<\/p>\n<h2><\/h2>\n<h2>\u5f00\u59cb\u96c6\u6210<\/h2>\n<p>\u5b98\u7f51\u7684\u63a8\u8350\u65b9\u6cd5\u662f\u65b0\u5efaios\u76ee\u5f55\uff0c\u628a\u6211\u4eec\u7684\u4e1c\u897f\u90fd\u653e\u5230ios\u76ee\u5f55\u91cc\uff0c\u4e0d\u8fc7\u6211\u4eec\u4e0d\u7ba1\u5b83\u3002\u6211\u4eec\u53ef\u4ee5\u5728\u6211\u4eec\u7684\u9879\u76ee\u76ee\u5f55\u91cc\u65b0\u5efareactnaive\u76ee\u5f55\u3002\u7528\u4e8e\u653e\u7f6e\u548cReactNative\u76f8\u5173\u7684\u6587\u4ef6\u548c\u6587\u4ef6\u5939\u3002<\/p>\n<p>\u7136\u540e\u6253\u5f00\u6b64\u6587\u4ef6\u5939\u3002\u4f7f\u7528touch\u65b0\u5efapackage.json\u6587\u4ef6\u3002<\/p>\n<blockquote><p>{<br \/>\n&#8220;name&#8221;: &#8220;YouProjectName&#8221;,<br \/>\n&#8220;version&#8221;: &#8220;0.0.1&#8221;,<br \/>\n&#8220;private&#8221;: true,<br \/>\n&#8220;scripts&#8221;: {<br \/>\n&#8220;start&#8221;: &#8220;node node_modules\/react-native\/local-cli\/cli.js start&#8221;<br \/>\n},<br \/>\n&#8220;dependencies&#8221;: {<br \/>\n&#8220;react&#8221;: &#8220;16.0.0-alpha.12&#8221;,<br \/>\n&#8220;react-native&#8221;: &#8220;0.47.1&#8221;<br \/>\n}<\/p><\/blockquote>\n<p>\u8fd9\u91cc\u9700\u8981\u6ce8\u610f\u5c06name\u6362\u6210\u4f60\u81ea\u5df1\u7684\u9879\u76ee\u540d\u79f0\u5c31\u53ef\u4ee5\u4e86\u3002\u4e0d\u5efa\u8bae\u4f7f\u7528\u6700\u65b0\u7684\u7248\u672c\uff0c\u6700\u65b0\u7684\u7248\u672c\u6709\u4e0d\u5c0f\u7684BUG\u3002\u89e3\u51b3\u8d77\u6765\u5f88\u8d39\u529b\u8d39\u65f6\u3002<\/p>\n<p>\u7f16\u8f91\u540e\u3002\u56de\u5230\u6211\u4eec\u7684\u76ee\u5f55\uff0c\u6267\u884c<\/p>\n<p>npm install<\/p>\n<p>\u6b64\u547d\u4ee4\u5c06\u5b89\u88c5\u6240\u6709\u7684\u4e4b\u540e\u5c31\u662f\u5b89\u88c5React \u548cReact-Native\u6a21\u5757\uff0c\u7b49\u5f85\u7ec8\u7aef\u6267\u884c\u5b8c\u6bd5\u540e\uff0c\u8be5\u6587\u4ef6\u5939\u4e0b\u4f1a\u591a\u51fa\u4e00\u4e2anode_modules\u7684\u6587\u4ef6\u5939\uff0c\u91cc\u9762\u662f\u6240\u6709React \u548cReact-Native\u76f8\u5173\u6a21\u5757\u3002<\/p>\n<p>\u63a5\u4e0b\u6765\u662f\u4f7f\u7528cocoapods\uff0c\u5b89\u88c5\u4f9d\u8d56\u5e93\uff0c\u5728\u6b64\u4e4b\u524d\uff0c\u9700\u8981\u65b0\u5efa\u914d\u7f6e\u6587\u4ef6podfile\uff0c\u6839\u636e\u9700\u8981\u7f16\u5199\u5e76\u8f93\u5165\u4ee5\u4e0b\u5185\u5bb9<\/p>\n<p>pod &#8216;React&#8217;, :path =&gt; &#8216;.\/YourReactNativeFolder\/node_modules\/react-native&#8217;, :subspecs =&gt; [<br \/>\n&#8216;Core&#8217;,\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 #\u6838\u5fc3\u5e93<br \/>\n&#8216;BatchedBridge&#8217;,\u00a0\u00a0\u00a0 #RN\u7248\u672c\u9ad8\u4e8e0.45\u4e4b\u540e\u5fc5\u987b\u5bfc\u5165<br \/>\n&#8216;DevSupport&#8217;,\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 # \u5982\u679cRN\u7248\u672c &gt;= 0.43\uff0c\u5219\u9700\u8981\u52a0\u5165\u6b64\u884c\u624d\u80fd\u5f00\u542f\u5f00\u53d1\u8005\u83dc\u5355<br \/>\n&#8216;ART&#8217;,<br \/>\n&#8216;RCTActionSheet&#8217;,<br \/>\n&#8216;RCTAdSupport&#8217;,<br \/>\n&#8216;RCTAnimation&#8217;,<br \/>\n&#8216;RCTCameraRoll&#8217;,<br \/>\n&#8216;RCTGeolocation&#8217;,<br \/>\n&#8216;RCTImage&#8217;,<br \/>\n&#8216;RCTNetwork&#8217;,<br \/>\n&#8216;RCTPushNotification&#8217;,<br \/>\n&#8216;RCTSettings&#8217;,<br \/>\n&#8216;RCTText&#8217;,<br \/>\n&#8216;RCTVibration&#8217;,<br \/>\n&#8216;RCTWebSocket&#8217;,\u00a0\u00a0\u00a0\u00a0 # \u8fd9\u4e2a\u6a21\u5757\u662f\u7528\u4e8e\u8c03\u8bd5\u529f\u80fd\u7684<br \/>\n&#8216;RCTLinkingIOS&#8217;<br \/>\n]<br \/>\n# \u5982\u679c\u4f60\u7684RN\u7248\u672c &gt;= 0.42.0\uff0c\u5219\u52a0\u5165\u4e0b\u9762\u8fd9\u884c<br \/>\npod &#8216;Yoga&#8217;, :path =&gt; &#8216;.\/YourReactNativeFolder\/node_modules\/react-native\/ReactCommon\/yoga&#8217;<\/p>\n<p>\u9700\u8981\u6ce8\u610f\u7684\u662fReactNative\u76ee\u5f55\u7684\u6b63\u786e\u6027\u3002\u5982\u679c\u4e07\u4e8bOK\u3002\u5c31\u76f4\u63a5\u6267\u884c\u4e0b\u9762\u7684\u547d\u4ee4\u3002<\/p>\n<p>pod install<\/p>\n<p>\u6b64\u547d\u4ee4\u6267\u884c\u5b8c\u6bd5\u540e\u3002\u7f16\u8bd1\u7a0b\u5e8f\uff0c\u770b\u6709\u65e0\u62a5\u9519\uff0c\u5982\u679c\u6ca1\u6709\uff0c\u5219\u96c6\u6210\u6210\u529f\u3002<\/p>\n<h2>\u9875\u9762\u5d4c\u5165\u548c\u96c6\u6210<\/h2>\n<p>\u96c6\u6210\u624d\u662f\u6211\u4eec\u7684\u6700\u7ec8\u76ee\u7684\uff0c\u6211\u4eec\u6765\u5b9e\u73b0\u5b83\u3002\u9996\u5148\uff0c\u65b0\u5efa\u4e00\u4e2aios\u7684\u5165\u53e3\u6587\u4ef6.index.ioss.js.<\/p>\n<p>\u6b64\u6587\u4ef6\u662f\u5fc5\u987b\u521b\u5efa\u7684\uff0c\u6bd4\u8f83\u7b80\u5355\u3002<\/p>\n<blockquote><p>&#8216;use strict&#8217;;<\/p>\n<p>import React, { Component } from &#8216;react&#8217;;<br \/>\nimport {<br \/>\nAppRegistry,<br \/>\nStyleSheet,<br \/>\nText,<br \/>\nView<br \/>\n} from &#8216;react-native&#8217;;<br \/>\n\/\/{&#8216;\\n&#8217;}\u6362\u884c\u7b26<br \/>\nexport default class ReactPage extends Component {<br \/>\nrender() {<br \/>\nreturn (<br \/>\n&lt;View style={styles.container}&gt;<br \/>\n&lt;Text style={styles.welcome}&gt;<br \/>\n\u8fd9\u5c31\u662f\u6240\u8c13\u7684{&#8216;\\n&#8217;}<br \/>\nReact Native<br \/>\n&lt;\/Text&gt;<br \/>\n&lt;Text style={styles.instructions}&gt;<br \/>\n\u6a21\u62df\u5668\u4e2dcmd+R\u5237\u65b0\u9875\u9762\uff0ccmd+D\u8c03\u51fa\u8c03\u8bd5\u83dc\u5355<br \/>\n&lt;\/Text&gt;<br \/>\n&lt;\/View&gt;<br \/>\n);<br \/>\n}<br \/>\n}<\/p>\n<p>const styles = StyleSheet.create({<br \/>\ncontainer: {<br \/>\nflex: 1,<br \/>\njustifyContent: &#8216;center&#8217;,<br \/>\nalignItems: &#8216;center&#8217;,<br \/>\nbackgroundColor: &#8216;#F2F2F2&#8217;,<br \/>\n},<br \/>\nwelcome: {<br \/>\nfontSize: 24,<br \/>\ntextAlign: &#8216;center&#8217;,<br \/>\nmargin: 10,<br \/>\n},<br \/>\ninstructions: {<br \/>\ntextAlign: &#8216;center&#8217;,<br \/>\ncolor: &#8216;#333333&#8217;,<br \/>\nmarginBottom: 5,<br \/>\n},<br \/>\n});<\/p>\n<p>AppRegistry.registerComponent(&#8216;YourProjectName&#8217;, () =&gt; ReactPage);<\/p><\/blockquote>\n<p>\u7136\u540e\u627e\u5230\u4f60\u7684Object C\u4ee3\u7801\u3002\u627e\u5230\u4f60\u8981\u5f15\u5165\u7684\u4e8b\u4ef6\u5904\u7406\u7a0b\u5e8f\u3002\u5728\u5bf9\u5e94\u7684\u9875\u9762\u4e0a\u589e\u52a0React\u7684\u5f15\u7528\u3002<\/p>\n<ol>\n<li>#import &lt;React\/RCTRootView.h&gt;<\/li>\n<\/ol>\n<p>\u7136\u540e\u5728\u4e8b\u4ef6\u5904\u7406\u65b9\u6cd5\u4e2d\u6dfb\u52a0\u5982\u4e0b\u4ee3\u7801\uff1a<\/p>\n<p>NSURL *jsCodeLocation = [NSURL URLWithString:@&#8221;<a href=\"http:\/\/localhost:8081\/index.ios.bundle?platform=ios&amp;dev=true&quot;];\">http:\/\/localhost:8081\/index.ios.bundle?platform=ios&amp;dev=true&#8221;];<\/a><\/p>\n<p>RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation moduleName:@&#8221;AiFlow&#8221; initialProperties:nil launchOptions:nil];<br \/>\nrootView.backgroundColor = [UIColor colorWithHexString:@&#8221;#F2F2F2&#8243;];<\/p>\n<p>UIViewController *vc = [[UIViewController alloc] init];<br \/>\nvc.view = rootView;<\/p>\n<p>[self presentViewController:vc animated:YES completion:nil];<\/p>\n<p>\u6267\u884c\u3002\u70b9\u51fb\u3002\u8fd0\u884c\u3002OK\u3002<\/p>\n<p>\u53e6\u5916\uff0c\u5982\u679c\u65e0\u6cd5\u5c55\u793a\u9875\u9762\uff0c\u5219\u9700\u8981npm start\u542f\u52a8\u670d\u52a1\u7aef\u3002<\/p>\n<p>\u5f53\u7136\uff0c\u8fd9\u91cc\u53ea\u662fHello World\uff0c\u5269\u4e0b\u7684\u624d\u662f\u91cd\u4e2d\u91cd\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4ec0\u4e48\u662fReact Native React-Native \u662f\u7531Facebook\u51fa\u54c1\u7684\u4e00\u6b3e\u53ef\u4ee5\u4f7f\u7528JavaScr &hellip; <a href=\"https:\/\/www.fh1986.com\/index.php\/archives\/509.html\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">Reactive Native \u5728IOS\u4e2d\u96c6\u6210\u4e2d\u7684\u8e29\u5751\u7ecf\u5386<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":513,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"_links":{"self":[{"href":"https:\/\/www.fh1986.com\/index.php\/wp-json\/wp\/v2\/posts\/509"}],"collection":[{"href":"https:\/\/www.fh1986.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.fh1986.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.fh1986.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.fh1986.com\/index.php\/wp-json\/wp\/v2\/comments?post=509"}],"version-history":[{"count":2,"href":"https:\/\/www.fh1986.com\/index.php\/wp-json\/wp\/v2\/posts\/509\/revisions"}],"predecessor-version":[{"id":511,"href":"https:\/\/www.fh1986.com\/index.php\/wp-json\/wp\/v2\/posts\/509\/revisions\/511"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.fh1986.com\/index.php\/wp-json\/wp\/v2\/media\/513"}],"wp:attachment":[{"href":"https:\/\/www.fh1986.com\/index.php\/wp-json\/wp\/v2\/media?parent=509"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.fh1986.com\/index.php\/wp-json\/wp\/v2\/categories?post=509"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.fh1986.com\/index.php\/wp-json\/wp\/v2\/tags?post=509"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}