当前位置: 首页 > news >正文

网站开发后端框架域名解析ip地址

网站开发后端框架,域名解析ip地址,wordpress更换域名后登陆不了后台,上海 经营性网站备案本篇文章以MacOS环境开发iOS平台为例,记录一下在原生APP基础上集成React Native React Native中文网 详细介绍了搭建环境和集成RN的步骤。 环境搭建 必须安装的依赖有:Node、Watchman、Xcode 和 CocoaPods。 安装Homebrew Homebrew是一款Mac OS平台下…

本篇文章以MacOS环境开发iOS平台为例,记录一下在原生APP基础上集成React Native

React Native中文网 详细介绍了搭建环境和集成RN的步骤。

环境搭建

必须安装的依赖有:Node、Watchman、Xcode 和 CocoaPods。

安装Homebrew

Homebrew是一款Mac OS平台下的软件包管理工具,拥有安装、卸载、更新、查看、搜索等很多实用的功能。

  • 安装brew
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
  • 查看brew版本
brew -v

Node & Watchman

Node.js是在Google Chrome V8 JavaScript引擎的基础上构建的,一个开源的跨平台JavaScript运行时环境。

Watchman是由 Facebook 提供的监视文件系统变更的工具。安装此工具可以提高开发时的性能(packager 可以快速捕捉文件的变化从而实现实时刷新)。

  • 安装

推荐使用Homebrew来安装 Node 和 Watchman。

brew install node
brew install watchman
  • 查看版本
node -v
  • 卸载node
brew uninstall node

安装完 Node 后建议设置 npm 镜像(淘宝源)

# 使用nrm工具切换淘宝源
npx nrm use taobao# 如果之后需要切换回官方源可使用
npx nrm use npm
  • 安装Yarn

Yarn是 Facebook 提供的替代 npm 的工具,可以加速 node 模块的下载。安装完 yarn 之后就可以用 yarn 代替 npm 了。

npm install -g yarn

Xcode & CocoaPods

这两个就不过多解释了。
CocoaPods安装

sudo gem install cocoapods

或者

brew install cocoapods

关于更多CocoaPods问题参考:CocoaPods安装 CocoaPods常见错误总结

集成React Native

其实有两种集成方案,第一种就是按照官方的步骤,在RN项目中添加自己原生的iOS和Android项目。

另一种就是在原生项目中以submodule或子组件的形式添加RN,个人认为后者的项目管理方式较好,不影响主项目的架构。

请添加图片描述

But,网上给的Podfile配置都是低版本的react-native,我使用的版本是0.73.0的,我配置Podfile一直出错,在官方GitHub或QQ群提问也没人理我,最后我就按第一种配置了,后面有哪位大神有第二种的配置方案,可以教我一下~

创建React Native新项目

默认会创建最新的版本

npx react-native init MyReactNative

或者安装指定版本

//最新版本
npx react-native@latest init MyReactNative//注意版本号必须精确到两个小数点
npx react-native@0.68.0 init MyReactNative

安装完成后,不需要加载cocoaPods依赖
请添加图片描述

这是的项目目录如下图,每个文件做什么的,我做了标注。

请添加图片描述

我们把androidios 两个文件夹下的文件清空就行,把自己的项目放到对应的目录下。

配置CocoaPods

  • 创建配置文件Podfile
    在项目根目录下,来到/ios目录
cd ios
pod init

打开Podfile,键入以下内容

source 'https://github.com/CocoaPods/Specs.git'# Resolve react_native_pods.rb with node to allow for hoisting
require Pod::Executable.execute_command('node', ['-p','require.resolve("react-native/scripts/react_native_pods.rb",{paths: [process.argv[1]]},)', __dir__]).stripplatform :ios, min_ios_version_supported
prepare_react_native_project!# If you are using a `react-native-flipper` your iOS build will fail when `NO_FLIPPER=1` is set.
# because `react-native-flipper` depends on (FlipperKit,...) that will be excluded
#
# To fix this you can also exclude `react-native-flipper` using a `react-native.config.js`
# ```js
# module.exports = {
#   dependencies: {
#     ...(process.env.NO_FLIPPER ? { 'react-native-flipper': { platforms: { ios: null } } } : {}),
# ```
flipper_config = ENV['NO_FLIPPER'] == "1" ? FlipperConfiguration.disabled : FlipperConfiguration.enabledlinkage = ENV['USE_FRAMEWORKS']
if linkage != nilPod::UI.puts "Configuring Pod with #{linkage}ally linked Frameworks".greenuse_frameworks! :linkage => linkage.to_sym
enddef common_pods# 网络请求pod 'AFNetworking'# 时间选择器pod 'FQDateTimePicker'# 锁屏pod 'FQLockSDK'
endtarget 'MyReactNative(你的iOS项目名字)' do
# iOS原生的三方依赖common_podsconfig = use_native_modules!use_react_native!(:path => config[:reactNativePath],# Enables Flipper.## Note that if you have use_frameworks! enabled, Flipper will not work and# you should disable the next line.:flipper_configuration => flipper_config,# An absolute path to your application root.:app_path => "#{Pod::Config.instance.installation_root}/..")target 'MyReactNativeTests' doinherit! :complete# Pods for testingendpost_install do |installer|# https://github.com/facebook/react-native/blob/main/packages/react-native/scripts/react_native_pods.rb#L197-L202react_native_post_install(installer,config[:reactNativePath],:mac_catalyst_enabled => false)end
end

然后下载三方依赖

pod install

iOS原生运行RN

配置Xcode

Info.plist文件中配置本地运行的 Metro 服务。

<key>NSAppTransportSecurity</key>
<dict><key>NSExceptionDomains</key><dict><key>localhost</key><dict><key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key><true/></dict></dict>
</dict>
编写index.js

iOS和RN交互的入口就是RN项目根目录下的index.js文件,官方给的index.js案例代码是:

import React from 'react';
import {AppRegistry, StyleSheet, Text, View} from 'react-native';const RNHighScores = ({scores}) => {const contents = scores.map(score => (<Text key={score.name}>{score.name}:{score.value}{'\n'}</Text>));return (<View style={styles.container}><Text style={styles.highScoresTitle}>2048 High Scores!</Text><Text style={styles.scores}>{contents}</Text></View>);
};const styles = StyleSheet.create({container: {flex: 1,justifyContent: 'center',alignItems: 'center',backgroundColor: '#FFFFFF',},highScoresTitle: {fontSize: 20,textAlign: 'center',margin: 10,},scores: {textAlign: 'center',color: '#333333',marginBottom: 5,},
});// 模块名称
AppRegistry.registerComponent('RNHighScores', () => RNHighScores);
iOS原生跳转RN页面

在原生开发中,你可以通过一个点击事件或函数跳转到RN页面。

首先导入RCTRootView的头文件。

#import <React/RCTRootView.h>
- (void)highScoreButtonPressed {NSLog(@"High Score Button Pressed");//这里给的是localhost本地的服务地址,当你上线后要动态配置下你自己服务器的地址NSURL *jsCodeLocation = [NSURL URLWithString:@"http://localhost:8081/index.bundle?platform=ios"];RCTRootView *rootView =[[RCTRootView alloc] initWithBundleURL: jsCodeLocationmoduleName: @"RNHighScores"initialProperties:@{@"scores" : @[@{@"name" : @"Alex",@"value": @"42"},@{@"name" : @"Joel",@"value": @"10"}]}launchOptions: nil];UIViewController *vc = [[UIViewController alloc] init];vc.view = rootView;[self presentViewController:vc animated:YES completion:nil];
}
开启Metro服务

要运行应用,首先需要启动开发服务器(即 Metro,它负责实时监测 js 文件的变动并实时打包,输出给客户端运行,所以需要你有metro.config.js配置文件)。

进入到RN项目根目录中,然后运行:

yarn start

如果报错 yarn start Command react-native not found.
请添加图片描述
那是react-native-cli命令行工具影响的,先卸载掉。

npm uninstall -g react-native-cli
npm uninstall -g react-native-cli @react-native-community/cli

然后再执行yarn start,如果还报错,就主动安装下react-native-cli

yarn add react-native-cli 

启动之后如下图:
在这里插入图片描述

这时候打开Xcode,选择模拟器(run)运行iOS项目就可以了。
如果遇到CocoaPods报错,比如RN依赖的某个文件找不到,来到RN根目录下拉取一下三方依赖。

npx pod-install ios        

✿✿ヽ(°▽°)ノ✿✿✿ヽ(°▽°)ノ✿✿

http://www.ds6.com.cn/news/96157.html

相关文章:

  • 专业做网站建设公最近营销热点
  • 专业网站制作服务p2p万能搜索引擎
  • 婚庆公司网站建设策划书招聘网站排名
  • 中国人做外贸网站都卖什么手续搜索引擎网址有哪些
  • 做网站地图的步骤经典软文
  • 做分析图地图网站手机搜索引擎排名
  • 宁波网站优化体验推广赚钱软件
  • 全民消防平台小程序seo技巧与技术
  • 加盟网站合作西安seo诊断
  • 域名 做网站和邮箱seo培训机构哪家好
  • 电子商务网站提供的主要功能有整合营销策略有哪些
  • 江苏省宿迁市建设局网站首页软文广告的案例
  • hype做网站动效网站seo基本流程
  • 无代码开发小程序seo研究协会网
  • 提供完善政府网站建设seo专业培训技术
  • 昆山seo网站优化软件最快的新闻发布平台
  • 即时设计网站网站怎么优化排名靠前
  • 网站用户体现好坏上海企业推广
  • 郑州营销型网站制作策划合肥网站优化
  • 河南汉狮做网站的公司宣传广告怎么做吸引人
  • 瑶海区网站建设广州seo教程
  • 长春火车站24小时人工客服电话如何进行app推广
  • wordpress重新生成文章更新宁波seo教程
  • 建站宝盒自助建站系统怎么提高seo关键词排名
  • 宁波网站建设报价多少淘宝指数查询官网
  • 做网站必须用域名吗推广的渠道和方法有哪些
  • 网页传奇版本跟我学seo从入门到精通
  • 网站开发用到的虚拟机有哪些网络舆情监测系统
  • 交友小程序开发专业seo推广
  • 做代购网站有哪些深圳网络营销