From 44e14d1ed617c55a0b420516357d41fc824d31ce Mon Sep 17 00:00:00 2001 From: mx1700 Date: Wed, 17 Jul 2019 00:03:04 +0800 Subject: [PATCH] =?UTF-8?q?android=20=E6=8E=A5=E5=85=A5=20firebase?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- android/app/build.gradle | 23 +++++++++++++++---- .../java/com/timepill/MainApplication.java | 6 ++++- android/build.gradle | 9 +++++--- android/settings.gradle | 2 ++ index.js | 6 +++++ ios/Timepill.xcodeproj/project.pbxproj | 20 +++++++++++++++- package-lock.json | 14 +++++++++++ package.json | 1 + .../notification/notificationList.js | 2 +- src/page/NotificationHistoryPage.js | 1 + src/page/NotificationPage.js | 10 +++++--- src/page/UserInfoEditPage.js | 5 ++++ 12 files changed, 86 insertions(+), 13 deletions(-) diff --git a/android/app/build.gradle b/android/app/build.gradle index b59b036..c4bda0c 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -1,4 +1,6 @@ apply plugin: "com.android.application" +apply plugin: "io.fabric" + import com.android.build.OutputFile @@ -107,10 +109,10 @@ android { minSdkVersion rootProject.ext.minSdkVersion targetSdkVersion rootProject.ext.targetSdkVersion missingDimensionStrategy "RNN.reactNativeVersion", "reactNative57_5" - versionCode 21 - versionName "2.0.1" + versionCode 22 + versionName "2.0.2" vectorDrawables.useSupportLibrary = true - + multiDexEnabled true ndk { //根据需要 自行选择添加的对应cpu类型的.so库。 abiFilters 'armeabi', 'armeabi-v7a', 'arm64-v8a' @@ -166,12 +168,15 @@ android { dependencies { + implementation project(':react-native-firebase') implementation project(':react-native-smart-xgpush') implementation project(':rn-fetch-blob') implementation project(':react-native-image-crop-picker') implementation project(':react-native-image-resizer') - implementation project(':react-native-device-info') + implementation (project(':react-native-device-info')){ + exclude group: 'com.google.android.gms' + } implementation project(':react-native-vector-icons') implementation project(':@react-native-community_async-storage') implementation project(':react-native-navigation') @@ -185,6 +190,16 @@ dependencies { implementation 'com.tencent.wup:wup:1.0.0.E-Release' implementation 'com.tencent.mid:mid:4.0.7-Release' implementation 'com.tencent.xinge:mipush:4.3.2-xiaomi-release' + + // Firebase dependencies + implementation "com.google.android.gms:play-services-base:16.1.0" + implementation "com.google.firebase:firebase-core:16.0.9" + implementation('com.crashlytics.sdk.android:crashlytics:2.9.9@aar') { + transitive = true + } + + apply plugin: 'com.google.gms.google-services' + } // Run this once to be able to run the application with BUCK diff --git a/android/app/src/main/java/com/timepill/MainApplication.java b/android/app/src/main/java/com/timepill/MainApplication.java index cdfb905..cd827f6 100644 --- a/android/app/src/main/java/com/timepill/MainApplication.java +++ b/android/app/src/main/java/com/timepill/MainApplication.java @@ -3,6 +3,8 @@ package com.timepill; import android.app.Application; import com.facebook.react.ReactApplication; +import io.invertase.firebase.RNFirebasePackage; +import io.invertase.firebase.fabric.crashlytics.RNFirebaseCrashlyticsPackage; import com.rain.day.XGPushPackage; import com.RNFetchBlob.RNFetchBlobPackage; import com.reactnative.ivpusic.imagepicker.PickerPackage; @@ -50,7 +52,9 @@ public class MainApplication extends NavigationApplication { new VectorIconsPackage(), new AsyncStoragePackage(), new PickerPackage(), - new XGPushPackage() + new XGPushPackage(), + new RNFirebasePackage(), + new RNFirebaseCrashlyticsPackage() ); } diff --git a/android/build.gradle b/android/build.gradle index 20b032c..9d3eec6 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -21,10 +21,12 @@ buildscript { mavenLocal() mavenCentral() jcenter() + maven { url 'https://maven.fabric.io/public' } } dependencies { classpath 'com.android.tools.build:gradle:3.3.1' - + classpath 'com.google.gms:google-services:4.2.0' + classpath 'io.fabric.tools:gradle:1.28.1' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } @@ -33,13 +35,14 @@ buildscript { allprojects { repositories { google() - mavenCentral() + mavenCentral() mavenLocal() jcenter() maven { // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm url "$rootDir/../node_modules/react-native/android" } - maven { url 'https://jitpack.io' } + maven { url 'https://jitpack.io' } + maven { url 'https://maven.fabric.io/public' } } } diff --git a/android/settings.gradle b/android/settings.gradle index e71b56a..65ec225 100644 --- a/android/settings.gradle +++ b/android/settings.gradle @@ -1,4 +1,6 @@ rootProject.name = 'Timepill' +include ':react-native-firebase' +project(':react-native-firebase').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-firebase/android') include ':app' include ':react-native-smart-xgpush' diff --git a/index.js b/index.js index 17fa06b..ca2911c 100644 --- a/index.js +++ b/index.js @@ -14,6 +14,8 @@ import PageList from './src/page/_list'; import BottomNav from './src/nav/bottomNav'; import Push from './src/util/push'; +import firebase from 'react-native-firebase'; + // for debug console.disableYellowBox = true; @@ -96,6 +98,8 @@ Navigation.events().registerAppLaunchedListener(async () => { } try { + //todo:当服务器不可用时,可能会卡在这里很长时间 + //之前的做法是异步更新数据,在下一次打开 app 时从本地读取 await Api.syncSplash(); } catch (err) {} @@ -118,5 +122,7 @@ Navigation.events().registerAppLaunchedListener(async () => { Push.init((msg) => { console.log("push init: " + msg); }) + + firebase.crashlytics().log('Test Message!'); }); diff --git a/ios/Timepill.xcodeproj/project.pbxproj b/ios/Timepill.xcodeproj/project.pbxproj index affb72b..59f7a19 100644 --- a/ios/Timepill.xcodeproj/project.pbxproj +++ b/ios/Timepill.xcodeproj/project.pbxproj @@ -5,7 +5,6 @@ }; objectVersion = 46; objects = { - /* Begin PBXBuildFile section */ 00C302E51ABCBA2D00DB3ED1 /* libRCTActionSheet.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 00C302AC1ABCB8CE00DB3ED1 /* libRCTActionSheet.a */; }; 00C302E71ABCBA2D00DB3ED1 /* libRCTGeolocation.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 00C302BA1ABCB90400DB3ED1 /* libRCTGeolocation.a */; }; @@ -70,6 +69,7 @@ ED297163215061F000B7C4FE /* JavaScriptCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = ED297162215061F000B7C4FE /* JavaScriptCore.framework */; }; ED2971652150620600B7C4FE /* JavaScriptCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = ED2971642150620600B7C4FE /* JavaScriptCore.framework */; }; F343A722A8DB46C79081F2A0 /* Entypo.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 81F0243DD71F467A964CAD89 /* Entypo.ttf */; }; + 0776D8FF93DB448E92CCCCAB /* libRNFirebase.a in Frameworks */ = {isa = PBXBuildFile; fileRef = C138A37CA72349BF80C6081A /* libRNFirebase.a */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -498,6 +498,8 @@ ED297162215061F000B7C4FE /* JavaScriptCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = JavaScriptCore.framework; path = System/Library/Frameworks/JavaScriptCore.framework; sourceTree = SDKROOT; }; ED2971642150620600B7C4FE /* JavaScriptCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = JavaScriptCore.framework; path = Platforms/AppleTVOS.platform/Developer/SDKs/AppleTVOS12.0.sdk/System/Library/Frameworks/JavaScriptCore.framework; sourceTree = DEVELOPER_DIR; }; FE0D7FAFEDE44E168687B4B2 /* RNCAsyncStorage.xcodeproj */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = "wrapper.pb-project"; name = RNCAsyncStorage.xcodeproj; path = "../node_modules/@react-native-community/async-storage/ios/RNCAsyncStorage.xcodeproj"; sourceTree = ""; }; + 578B633145B7404F91B43B90 /* RNFirebase.xcodeproj */ = {isa = PBXFileReference; name = "RNFirebase.xcodeproj"; path = "../node_modules/react-native-firebase/ios/RNFirebase.xcodeproj"; sourceTree = ""; fileEncoding = undefined; lastKnownFileType = wrapper.pb-project; explicitFileType = undefined; includeInIndex = 0; }; + C138A37CA72349BF80C6081A /* libRNFirebase.a */ = {isa = PBXFileReference; name = "libRNFirebase.a"; path = "libRNFirebase.a"; sourceTree = ""; fileEncoding = undefined; lastKnownFileType = archive.ar; explicitFileType = undefined; includeInIndex = 0; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -541,6 +543,7 @@ 4156314F2297CFBE009EB583 /* QBImagePicker.framework in Frameworks */, 35DCFF50947D4FCBBF5A8921 /* libRNFetchBlob.a in Frameworks */, 7497C6D0D64344B197447DC7 /* libRCTXGPushModule.a in Frameworks */, + 0776D8FF93DB448E92CCCCAB /* libRNFirebase.a in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -828,6 +831,7 @@ BDBA91D5680B4ACA83A7844B /* imageCropPicker.xcodeproj */, 99151F1A82BD48E0B5416458 /* RNFetchBlob.xcodeproj */, 461950EE4FD949249DD2937B /* RCTXGPushModule.xcodeproj */, + 578B633145B7404F91B43B90 /* RNFirebase.xcodeproj */, ); name = Libraries; sourceTree = ""; @@ -1599,6 +1603,7 @@ "$(SRCROOT)/../node_modules/react-native-image-crop-picker/ios/**", "$(SRCROOT)/../node_modules/rn-fetch-blob/ios/**", "$(SRCROOT)/../node_modules/react-native-smart-xgpush/ios/RCTXGPushModule", + "$(SRCROOT)/../node_modules/react-native-firebase/ios/RNFirebase/**", ); INFOPLIST_FILE = TimepillTests/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 9.0; @@ -1614,6 +1619,7 @@ "\"$(SRCROOT)/$(TARGET_NAME)\"", "\"$(SRCROOT)/$(TARGET_NAME)\"", "\"$(SRCROOT)/$(TARGET_NAME)\"", + "\"$(SRCROOT)/$(TARGET_NAME)\"", ); OTHER_LDFLAGS = ( "-ObjC", @@ -1640,6 +1646,7 @@ "$(SRCROOT)/../node_modules/react-native-image-crop-picker/ios/**", "$(SRCROOT)/../node_modules/rn-fetch-blob/ios/**", "$(SRCROOT)/../node_modules/react-native-smart-xgpush/ios/RCTXGPushModule", + "$(SRCROOT)/../node_modules/react-native-firebase/ios/RNFirebase/**", ); INFOPLIST_FILE = TimepillTests/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 9.0; @@ -1655,6 +1662,7 @@ "\"$(SRCROOT)/$(TARGET_NAME)\"", "\"$(SRCROOT)/$(TARGET_NAME)\"", "\"$(SRCROOT)/$(TARGET_NAME)\"", + "\"$(SRCROOT)/$(TARGET_NAME)\"", ); OTHER_LDFLAGS = ( "-ObjC", @@ -1683,6 +1691,7 @@ "$(SRCROOT)/../node_modules/react-native-image-crop-picker/ios/**", "$(SRCROOT)/../node_modules/rn-fetch-blob/ios/**", "$(SRCROOT)/../node_modules/react-native-smart-xgpush/ios/RCTXGPushModule", + "$(SRCROOT)/../node_modules/react-native-firebase/ios/RNFirebase/**", ); INFOPLIST_FILE = Timepill/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; @@ -1713,6 +1722,7 @@ "$(SRCROOT)/../node_modules/react-native-image-crop-picker/ios/**", "$(SRCROOT)/../node_modules/rn-fetch-blob/ios/**", "$(SRCROOT)/../node_modules/react-native-smart-xgpush/ios/RCTXGPushModule", + "$(SRCROOT)/../node_modules/react-native-firebase/ios/RNFirebase/**", ); INFOPLIST_FILE = Timepill/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; @@ -1748,6 +1758,7 @@ "$(SRCROOT)/../node_modules/react-native-image-crop-picker/ios/**", "$(SRCROOT)/../node_modules/rn-fetch-blob/ios/**", "$(SRCROOT)/../node_modules/react-native-smart-xgpush/ios/RCTXGPushModule", + "$(SRCROOT)/../node_modules/react-native-firebase/ios/RNFirebase/**", ); INFOPLIST_FILE = "Timepill-tvOS/Info.plist"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; @@ -1762,6 +1773,7 @@ "\"$(SRCROOT)/$(TARGET_NAME)\"", "\"$(SRCROOT)/$(TARGET_NAME)\"", "\"$(SRCROOT)/$(TARGET_NAME)\"", + "\"$(SRCROOT)/$(TARGET_NAME)\"", ); OTHER_LDFLAGS = ( "-ObjC", @@ -1796,6 +1808,7 @@ "$(SRCROOT)/../node_modules/react-native-image-crop-picker/ios/**", "$(SRCROOT)/../node_modules/rn-fetch-blob/ios/**", "$(SRCROOT)/../node_modules/react-native-smart-xgpush/ios/RCTXGPushModule", + "$(SRCROOT)/../node_modules/react-native-firebase/ios/RNFirebase/**", ); INFOPLIST_FILE = "Timepill-tvOS/Info.plist"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; @@ -1810,6 +1823,7 @@ "\"$(SRCROOT)/$(TARGET_NAME)\"", "\"$(SRCROOT)/$(TARGET_NAME)\"", "\"$(SRCROOT)/$(TARGET_NAME)\"", + "\"$(SRCROOT)/$(TARGET_NAME)\"", ); OTHER_LDFLAGS = ( "-ObjC", @@ -1843,6 +1857,7 @@ "$(SRCROOT)/../node_modules/react-native-image-crop-picker/ios/**", "$(SRCROOT)/../node_modules/rn-fetch-blob/ios/**", "$(SRCROOT)/../node_modules/react-native-smart-xgpush/ios/RCTXGPushModule", + "$(SRCROOT)/../node_modules/react-native-firebase/ios/RNFirebase/**", ); INFOPLIST_FILE = "Timepill-tvOSTests/Info.plist"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; @@ -1857,6 +1872,7 @@ "\"$(SRCROOT)/$(TARGET_NAME)\"", "\"$(SRCROOT)/$(TARGET_NAME)\"", "\"$(SRCROOT)/$(TARGET_NAME)\"", + "\"$(SRCROOT)/$(TARGET_NAME)\"", ); OTHER_LDFLAGS = ( "-ObjC", @@ -1890,6 +1906,7 @@ "$(SRCROOT)/../node_modules/react-native-image-crop-picker/ios/**", "$(SRCROOT)/../node_modules/rn-fetch-blob/ios/**", "$(SRCROOT)/../node_modules/react-native-smart-xgpush/ios/RCTXGPushModule", + "$(SRCROOT)/../node_modules/react-native-firebase/ios/RNFirebase/**", ); INFOPLIST_FILE = "Timepill-tvOSTests/Info.plist"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; @@ -1904,6 +1921,7 @@ "\"$(SRCROOT)/$(TARGET_NAME)\"", "\"$(SRCROOT)/$(TARGET_NAME)\"", "\"$(SRCROOT)/$(TARGET_NAME)\"", + "\"$(SRCROOT)/$(TARGET_NAME)\"", ); OTHER_LDFLAGS = ( "-ObjC", diff --git a/package-lock.json b/package-lock.json index 8a1e1d0..bb7c69a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10237,6 +10237,11 @@ } } }, + "opencollective-postinstall": { + "version": "2.0.2", + "resolved": "https://registry.npm.taobao.org/opencollective-postinstall/download/opencollective-postinstall-2.0.2.tgz", + "integrity": "sha1-Vlfxvt5ptuM6RZObBh61PTxsOok=" + }, "opn": { "version": "3.0.3", "resolved": "http://registry.npm.taobao.org/opn/download/opn-3.0.3.tgz", @@ -10864,6 +10869,15 @@ "prop-types": "^15.5.8" } }, + "react-native-firebase": { + "version": "5.5.5", + "resolved": "https://registry.npm.taobao.org/react-native-firebase/download/react-native-firebase-5.5.5.tgz", + "integrity": "sha1-1cfgLrbqVlD567sjws15b4PnykU=", + "requires": { + "opencollective-postinstall": "^2.0.0", + "prop-types": "^15.7.2" + } + }, "react-native-image-crop-picker": { "version": "0.24.0", "resolved": "https://registry.npm.taobao.org/react-native-image-crop-picker/download/react-native-image-crop-picker-0.24.0.tgz", diff --git a/package.json b/package.json index 33ee982..88f27bf 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,7 @@ "react-native-datepicker": "^1.7.2", "react-native-device-info": "^1.6.1", "react-native-elements": "^0.19.0", + "react-native-firebase": "^5.5.5", "react-native-image-crop-picker": "^0.24.0", "react-native-image-pan-zoom": "^2.1.11", "react-native-image-progress": "^1.1.1", diff --git a/src/component/notification/notificationList.js b/src/component/notification/notificationList.js index 5db4564..340e6f8 100644 --- a/src/component/notification/notificationList.js +++ b/src/component/notification/notificationList.js @@ -171,7 +171,7 @@ export default class NotificationList extends Component { }); if(this.props.isSetRead) { - //this._setRead(msg); + this._setRead(msg); } } diff --git a/src/page/NotificationHistoryPage.js b/src/page/NotificationHistoryPage.js index 31c80fb..b4bbf20 100644 --- a/src/page/NotificationHistoryPage.js +++ b/src/page/NotificationHistoryPage.js @@ -1,6 +1,7 @@ import React, {Component} from 'react'; import {Platform, StyleSheet, Text, View} from 'react-native'; import {Navigation} from 'react-native-navigation'; +import firebase from 'react-native-firebase'; import Color from '../style/color'; import {Icon} from '../style/icon'; diff --git a/src/page/NotificationPage.js b/src/page/NotificationPage.js index 9d332f1..bc9b85f 100644 --- a/src/page/NotificationPage.js +++ b/src/page/NotificationPage.js @@ -12,6 +12,7 @@ import Api from "../util/api"; import Event from "../util/event"; import Notification from "../component/notification/notification"; import NotificationList from "../component/notification/notificationList"; +import firebase from 'react-native-firebase'; const LOOP_TIME_SHORT = 30 * 1000; const LOOP_TIME_LONG = 60 * 1000; @@ -141,9 +142,12 @@ export default class NotificationPage extends Component { console.log('Push.setAccount ' + alias + ' ', success); }); - // Crashlytics.setUserName(user.name); - // Crashlytics.setUserEmail(user.email); - // Crashlytics.setUserIdentifier(user.id.toString()); + console.log(user, user.email); + + firebase.crashlytics().setUserIdentifier(user.id.toString()); + firebase.crashlytics().setUserName(user.name); + //todo:现在用户信息里没有 email + //firebase.crashlytics().setUserEmail(user.email); } diff --git a/src/page/UserInfoEditPage.js b/src/page/UserInfoEditPage.js index 7d0d20b..2ac1f88 100644 --- a/src/page/UserInfoEditPage.js +++ b/src/page/UserInfoEditPage.js @@ -33,6 +33,11 @@ export default class UserInfoEditPage extends Component { static options(passProps) { return { + topBar: { + title: { + text: '修改个人信息' + } + }, statusBar: { backgroundColor: 'white', style: 'dark'