那些资源


一、三个例子

iReading

Bilibili-React-Native

ZhiHuDaily-React-Native

二、IM 例子

1. React Native Socket.io Example

2. A simple messaging app with React Native and Socket.io

3. 极光Aurora IMUI

4. 一个基于 react-native + mobx + socket.io + node 的仿微信 JS-Wechat

三、业内良心

Goto: React Native Community【相对权威】

Goto: react-native-open-project 【工程】

Goto: Useful-Open-Source-React-Native 【控件】

Goto: react-native-starter-kit      【网页+RN】

Goto: 30-days-of-react-native    【30个demo】

Goto: aws-samples/aws-mobile-react-native-starter 【serverless】

Goto: https://github.com/wangdicoder【可用方案】

四、国外良心

Ref: https://github.com/jondot/awesome-react-native 【UI,App资源极为丰富】

五、运行例子

运行ZhiHuDaily报错,以及处理办法。

可能出现的错误,可惜没彻底解决:

(1) 先用Android Studio打开工程,否则直接npm install会报错。

(2) Gradle 'app' project refresh failed.

Error:Unsupported method: BaseConfig.getApplicationIdSuffix().
The version of Gradle you connect to does not support that method.
To resolve the problem you can change/upgrade the target version of Gradle you connect to.
Alternatively, you can ignore this exception and read other information from the model. Consult IDE log for more details (Help | Show Log)

(3) 在ZhiHuDaily-React-Native/android/gradle/wrapper/gradle-wrapper.properties中升级到4.1。

distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip

From: Unsupported method: BaseConfig.getApplicationIdSuffix()

  • Open build.gradle and change the gradle version to the recommended version:
    classpath 'com.android.tools.build:gradle:1.3.0' to
    classpath 'com.android.tools.build:gradle:2.3.2'
  • Hit 'Try Again'
  • In the messages box it'll say 'Fix Gradle Wrapper and re-import project' Click that, since the minimum gradle version is 3.3
  • A new error will popup and say The SDK Build Tools revision (23.0.1) is too low for project ':app'. Minimum required is 25.0.0 - Hit Update Build Tools version and sync project
  • A window may popup that says Android Gradle Plugin Update recommended, just update from there.

Now the project should be runnable now on any of your android virtual devices.

 

(4) 继续报错

gradle project sync failed. basic functionality will not work properly android studio

Goto: Android Studio 3.0.1 Error: Gradle project sync failed. Basic functionality (e.g. editing, debugging) will not work properly

让我们从AWS登录开始


登录: aws-samples/aws-mobile-react-native-starter 【serverless】

--> 侧边栏 --> 按钮列表、路由

台湾哥们的好文,收之:使用 REACT NATIVE 與 AMAZON COGNITO 實作 GOOGLE & FACEBOOK 登入的功能

一、React or React Native

Adding authentication to your React or React Native app is as easy as wrapping your app's main component with our withAuthenticator higher order component.

AWS Amplify will provide you customizable UI for common use cases such as user registration and login.

import { withAuthenticator } from 'aws-amplify-react-native';

export default withAuthenticator(App);

二、React Native apps with [AWS Amplify]

Ref: 官方开发指导

  • 一些概念

CLI support: AWS 命令行界面

AWS Mobile Hub: 创建AWS资源、相关用户、安全机制等

awsmobile-cli: It provides utilities for managing your backend, without visiting AWS Mobile Hub console.

  • 用户登录

As an example, in you React Native app, you can use a Higher-Order Components to provide a sign-in/sign-out experience for your app simply by wrapping your app’s main component:

export default withAuthenticator(App);

一行代码搞定登录前端。

  • 用户检测

Monitoring your users’ interaction with your app.

AWS Amplify provides analytics, push notifications and targeted messaging capabilities out-of-the-box.

Analytics.record('albumVisit', { genre: 'jazz', artist: 'Miles Davis' });
  • 动手实践

详见:Create an app

参见:[RN] 01 - Init: Try a little bit of React Native

(1) 打开Access keys,然后 “Create New Access Key”。

(2) 手动配置后端

官方代码中应该有实例: aws-amplify/packages/aws-amplify-react-native/

RN for AWS AUTH


官方的不够良心,这个才是真爱:Expo - React Native Authentication with Expo, AWS Amplify, & Cognito

对应的代码:dabit3/expo-user-authentication

一、安装

代码需安装:
npm install aws-amplify
npm install react-navigation

【五星级教程笔记】

 

二、AWS Mobile Hub *

Ref: react-community/create-react-native-app

小心Ubuntu的yarn带来的歧义: ERROR: There are no scenarios; must have at least one.#2821

create-react-native-app RNExpoAuthProject

cd RNExpoAuthProject/

sudo npm i -g awsmobile-cli

awsmobile init  #相关后端配置 
Please tell us about your project:
? Where is your project's source directory: .
? Where is your project's distribution directory that stores build artifacts: build
? What is your project's build command: npm run-script build
? What is your project's start command for local test run: npm run-script start ? What awsmobile project name would you like to use: RNExpoAuthProject Successfully created AWS Mobile Hub project: RNExpoAuthProject retrieving the latest backend awsmobile project information
awsmobile project's details logged at:
awsmobilejs/#current-backend-info/backend-details.json
awsmobile project's specifications logged at:
awsmobilejs/#current-backend-info/mobile-hub-project.yml
awsmobile project's access information logged at:
awsmobilejs/#current-backend-info/aws-exports.js
awsmobile project's access information copied to:
aws-exports.js
contents in #current-backend-info/ is synchronized with the latest in the aws cloud Executing yarn add aws-amplify ...
ERROR: [Errno 2] No such file or directory: 'add'
yarn add aws-amplify returned 1 Executing yarn add aws-amplify-react-native ...
ERROR: [Errno 2] No such file or directory: 'add'
yarn add aws-amplify-react-native returned 1 Success! your project is now initialized with awsmobilejs awsmobilejs/.awsmobile
is the workspace of awsmobile-cli, please do not modify its contents awsmobilejs/#current-backend-info
contains information of the backend awsmobile project from the last
synchronization with the cloud awsmobilejs/backend
is where you develop the codebase of the backend awsmobile project awsmobile console
opens the web console of the backend awsmobile project awsmobile run
pushes the latest development of the backend awsmobile project to the cloud,
and runs the frontend application locally awsmobile publish
pushes the latest development of the backend awsmobile project to the cloud,
and publishes the frontend application to aws S3 for hosting Happy coding with awsmobile!

配置日志记录

后台效果:有了新添加的项目 RNExpoAuthProject 。

三、添加登录模块

awsmobile user-signin add
awsmobile user-signin enable
awsmobile push

后台呈现效果:后端添加了User Sign-in

Cognito也出现了一个自动生成的User Pool:

$ npm install aws-amplify 添加Amplify模块

  "dependencies": {
"aws-amplify": "^0.4.1",
"expo": "^27.0.1",
"react": "16.3.1",
"react-native": "~0.55.2"
}

四、登录界面实现

运行 npm run android 的前提是首先打开模拟器,也就是需要先搭建好基本的android代码,让模拟器跑起来。

【就是给expo代码添加原生代码,貌似没啥必要,在此只是记录下】

lolo@lolo-UX303UB$ react-native init RNExpoAuthProject
prompt: Directory RNExpoAuthProject already exists. Continue?: (no) yes
This will walk you through creating a new React Native project in /media/unsw/CloudStorage/Linux-pan/ExtendedTmpSpace/Android-Workplace/android-and-ml/React-Native/demo-auth/RNExpoAuthProject
Cannot parse yarn version: 0.10
Installing react-native...
Consider installing yarn to make this faster: https://yarnpkg.com
npm WARN react-native@0.55.4 requires a peer of react@16.3.1 but none is installed. You must install peer dependencies yourself.
npm WARN eslint-plugin-react-native@3.2.1 requires a peer of eslint@^3.17.0 || ^4.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.4 (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.4: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"}) + react-native@0.55.4
added 15 packages, removed 598 packages, updated 13 packages and moved 1 package in 46.424s
Setting up new React Native app in /media/unsw/CloudStorage/Linux-pan/ExtendedTmpSpace/Android-Workplace/android-and-ml/React-Native/demo-auth/RNExpoAuthProject
Cannot parse yarn version: 0.10
Installing React...
npm WARN eslint-plugin-react-native@3.2.1 requires a peer of eslint@^3.17.0 || ^4.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.4 (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.4: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"}) + react@16.3.1
added 1 package in 4.464s
Installing Jest...
npm WARN eslint-plugin-react-native@3.2.1 requires a peer of eslint@^3.17.0 || ^4.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.4 (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.4: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"}) + babel-preset-react-native@4.0.0
+ babel-jest@23.0.0
+ react-test-renderer@16.3.1
+ jest@23.0.0
added 279 packages and updated 1 package in 12.787s
To run your app on iOS:
cd /media/unsw/CloudStorage/Linux-pan/ExtendedTmpSpace/Android-Workplace/android-and-ml/React-Native/demo-auth/RNExpoAuthProject
react-native run-ios
- or -
Open ios/RNExpoAuthProject.xcodeproj in Xcode
Hit the Run button
To run your app on Android:
cd /media/unsw/CloudStorage/Linux-pan/ExtendedTmpSpace/Android-Workplace/android-and-ml/React-Native/demo-auth/RNExpoAuthProject
Have an Android emulator running (quickest way to get started), or a device connected
react-native run-android

有区别么?看上去貌似是一样的效果。

npm run android

Once you've set these up, you can launch your app on an Android Virtual Device by running npm run android.

react-native run-android

GO TO your project’s folder and initiate react-native run-android  command and your project will be automatically run into Real Android Device.

五、代码示范

  • 申请注册 

  • 注册验证

  • 样式代码

六、效果预览

更新后的app.js在 22:44/29:27

进一步了解 AWS Mobile Hub


Ref: Authentication 【React Native Training 五星级资源】

Ref: AWS Mobile Hub 【React Native Training 五星级资源】

本篇内容为以下的四篇学习笔记:

  • 1. AWSMobile CLI - Getting Started
  • 2. Adding Analytics to a React Native Application
  • 3. Expo - React Native Authentication with Expo, AWS Amplify, & Cognito【之前已阅】
  • 4. Adding Analytics to an Expo Project
  • 5. React Native iOS Push Notifications with AWS & Amazon Pinpoint
 
 

一、 AWSMobile CLI 自动配置

AWSMobile CLI 与3类似,就是自动配置后端:
【这里没有提及密钥】
 

二、IAM

(1) 添加用户到组。

(2) 添加一个组,这个组需要给予适当的权限,比如admin。

(3) 然后获得两个key,运行awsmobile configure时有用到。

【这里有提及密钥】

三、amazon-cognito-identify-js

还是自动化配置后端那一套。

貌似是与Amplify取得联系。

react-native link amazon-cognito-identify-js

加载app到模拟器。

npm start              # kick off the package
react-native run-ios

四、两个疑问?

secretAccessKey怎么一会儿需要,一会儿又不需要?

[RN] 03 - Resource Collection & AWS Auth的更多相关文章

  1. Java基础知识强化之集合框架笔记03:Collection集合的功能概述

    1. Collection功能概述:Collection是集合的顶层接口,它子体系有重复的,有唯一性,有有序的,无序的. (1)添加功能 boolean add(Object obj):添加一个元素 ...

  2. [转]iOS hacking resource collection

    Link:http://www.securitylearn.net/tag/apple-ios-hacking-slides/ A collection of iOS research present ...

  3. [Full-stack] 跨平台大框架 - RN

    前言 React-Redux的大全栈代码复用理论有点意思,给出一个具体的例子:[React] 15 - Redux: practice IM 因为与react内容天然地部分重合,故这里将重点放在了对c ...

  4. REST Representational state transfer REST Resource Naming Guide Never use CRUD function names in URIs

    怎样用通俗的语言解释什么叫 REST,以及什么是 RESTful? - 知乎  https://www.zhihu.com/question/28557115 大家都知道"古代"网 ...

  5. AWS S3 对象存储服务

    虽然亚马逊云非常牛逼,虽然亚马逊云财大气粗,虽然亚马逊用的人也非常多,可是这个文档我简直无法接受,特别是客服,令人发指的回复速度,瞬间让人无语,可是毕竟牛逼.忍了,躺一次坑而已 1.图片上传 1.1 ...

  6. 将SSRF升级为RCE(AWS环境)

    原文:https://generaleg0x01.com/2019/03/10/escalating-ssrf-to-rce/ 查找域名范围: 在枚举客户端的子域名时.找到了子域名[docs] 打开这 ...

  7. AWS EKS 添加IAM用户角色

    作者:SRE运维博客 博客地址: https://www.cnsre.cn/ 文章地址:https://www.cnsre.cn/posts/211203931498/ 相关话题:https://ww ...

  8. AWS的SysOps认证考试样题解析

    刚考过了AWS的developer认证,顺手做了一下SysOps的样题.以下是题目和答案. When working with Amazon RDS, by default AWS is respon ...

  9. AWS S3 CLI的权限bug

    使用AWS CLI在S3上创建了一个bucket,上传文件的时候报以下错误: A client error (AccessDenied) occurred when calling the Creat ...

随机推荐

  1. 负数在计算机中的表示 Byte-128

    本文转载: http://blog.csdn.net/njuitjf/article/details/4585247 原码:将一个整数,转换成二进制,就是其原码.如单字节的5的原码为:0000 010 ...

  2. 【机器学习】 Matlab 2015a 自带机器学习算法汇总

    MATLAB机器学习没看到啥教程,只有一系列函数,只好记录下: MATLAB每个机器学习方法都有很多种方式实现,并可进行高级配置(比如训练决策树时设置的各种参数) ,这里由于篇幅的限制,不再详细描述. ...

  3. Android训练课程(Android Training) - 添加活动栏(使用action bar)

    2014-10-28 张云飞VIR 翻译自:https://developer.android.com/training/basics/actionbar/index.html 添加活动栏(Addin ...

  4. UI设计,使用 线框图(页面示意图或页面布局图)

    在进行页面框架设计的时候,尝试画个 线框图(页面示意图或页面布局图)吧.

  5. 【oneday_onepage】——The Secret Of Steve<2>

    Sales + Customers = Nothing Broken is the formula for corporate cyanide. Most big companies that die ...

  6. IDEA 修改文件编码

    Intellij Idea 修改 properties 文件编码 现象:idea 默认的properties文件是GBK,当有中文时,不同的客户端配置的编码不同时,可能产生中文乱码. 解决:修改pro ...

  7. Struts2,Spring,Hibernate框架的优缺点

    Struts2,Spring,Hibernate框架的优缺点 Struts2框架(MVC框架)的优点如下:         1)  实现了MVC模式,层次结构清晰,使程序员只需关注业务逻辑的实现:   ...

  8. 9、Qt 事件处理机制

    原文地址:http://mobile.51cto.com/symbian-272812.htm 在Qt中,事件被封装成一个个对象,所有的事件均继承自抽象类QEvent. 接下来依次谈谈Qt中有谁来产生 ...

  9. 磁盘映射: between 宿主机 and 客户机

    一.虚拟机映射到宿主机     在虚拟机关机的状态下,双击右侧设备栏里硬盘,在弹出的窗口中单击“实用程序“,选择“映射”.打开映射虚拟磁盘的窗口,其中的“卷”就是你希望映射虚拟机中的哪个分区到主机,如 ...

  10. Ilya Sutskever

    中文名:伊利亚 莎士科尔 早期: 加拿大多伦多大学,Hinton实验室,2005年至2012年 博士后: 斯坦福大学,Andrew实验室,2012年11月到2012年12月 工作: 谷歌,2013年3 ...