React Native踩坑记录

React Native踩坑记录

  • Linking模块
    • Android
      • AndroidManifest.xml
    • iOS
      • Info.plist
  • 端口被占用
    • Android
    • iOS

Linking模块

Linking 可以打开其他应用或者被其他应用打开。
canOpenURL(url:string)确定已安装的应用是否可以处理给定的 URL。
openURL(url:string)尝试使用任何已安装的应用打开给定的 URL。

Android

Linking.canOpenURL一直返回false是因为从Android 30开始,Google引入了对应用程序访问其他程序的限制。为了解决这个问题,需要在AndroidManifest.xml中添加一些配置。

AndroidManifest.xml

  1. <manifest>标签下:
<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES" />

上述配置可根据应用包名查找是否安装该应用。

  1. <application>标签下:
<intent-filter>
  <action android:name="android.intent.action.VIEW" />
  <category android:name="android.intent.category.DEFAULT" />
  <data android:scheme="http"/>
</intent-filter>
<intent-filter>
  <action android:name="android.intent.action.VIEW" />
  <category android:name="android.intent.category.DEFAULT" />
  <data android:scheme="https"/>
</intent-filter>

上述配置允许应用查询所有安装的应用程序以及处理http和https链接。

iOS

iOS9后引入了App白名单的策略,如果使用 canOpenURL方法,该方法所涉及到的 URL Schemes 必须在 Info.plist 中列为白名单。

Info.plist

以高德、百度地图为例:

<key>LSApplicationQueriesSchemes</key>
<array>
	<string>baidumap</string>
	<string>iosamap</string>
</array>

端口被占用

Android

运行时更改端口号为8081(默认)以外的任意端口即可,以下都以8088端口为例:

yarn android --port=8088 

iOS

运行时更改端口号后,

yarn ios --port=8088 

报如下错误:

Make sure you’re running a packager server or have included a .jsbundle file in your application bundle.

因为新端口号和项目默认8081端口号不一致,导致监听不了。
xcode打开工程(双击 project name/ios/.xcworkspace,注意 0.60 版本之后的主项目文件是.xcworkspace,不是.xcodeproj)。在xcode工程里全局搜索 8081 ,替换成8088 即可。

  • 6
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
React Native By Example by Richard Kho English | 24 Apr. 2017 | ASIN: B01M31KB4Q | 414 Pages | AZW3 | 4.46 MB Key Features Work on native APIs and UI Elements using React Native Get the best of both worlds: the power of native approach and the fluidity of JavaScript Create increasingly complex real-world applications and dive deeper into React Native Book Description React Native's ability to build performant mobile applications with JavaScript has resulted in its popularity amongst developers. Developers now have the luxury to create incredible mobile experiences that look and feel native to their platforms with the comfort of a well-known language and the popular React.js library. This book will show you how to build your own native mobile applications for the iOS and Android platforms while leveraging the finesse and simplicity of JavaScript and React. Throughout the book you will build three projects, each of increasing complexity. You will also link up with the third-party Facebook SDK, convert an app to support the Redux architecture, and learn the process involved in making your apps available for sale on the iOS App Store and Google Play. At the end of this book, you will have learned and implemented a wide breadth of core APIs and components found in the React Native framework that are necessary in creating great mobile experiences. What you will learn How to create mobile-performant iOS and Android apps using JavaScript and React The potential of each API and component, putting them into practice throughout the course of three projects The process of integrating the Facebook SDK to build an app that connects to third-party data Every step taken to implement Redux, a popular state management library, in your mobile apps The requirements for building and deploying your apps to market, with detailed instructions on how to release and beta test apps on both the Apple App Store and Google Play About the Author Richard Kho is a software engineer livin

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值