Browse Source

换成极光。准备

wennjie 5 years ago
parent
commit
46eba332c1

+ 1 - 0
huiliaoAPP/android/app/build.gradle

@@ -149,6 +149,7 @@ android {
 }
 
 dependencies {
+    compile project(':react-native-push-notification')
     compile project(':react-native-sound')
     compile project(':react-native-audio')
     implementation(project(':react-native-camera')) {

+ 2 - 0
huiliaoAPP/android/app/src/main/java/com/huiliaoapp/MainApplication.java

@@ -3,6 +3,7 @@ package com.huiliaoapp;
 import android.app.Application;
 
 import com.facebook.react.ReactApplication;
+import com.dieam.reactnativepushnotification.ReactNativePushNotificationPackage;
 import com.zmxv.RNSound.RNSoundPackage;
 import com.rnim.rn.audio.ReactNativeAudioPackage;
 import org.reactnative.camera.RNCameraPackage;
@@ -29,6 +30,7 @@ public class MainApplication extends Application implements ReactApplication {
     protected List<ReactPackage> getPackages() {
       return Arrays.<ReactPackage>asList(
           new MainReactPackage(),
+            new ReactNativePushNotificationPackage(),
             new RNSoundPackage(),
             new ReactNativeAudioPackage(),
             new RNCameraPackage(),

+ 2 - 0
huiliaoAPP/android/settings.gradle

@@ -1,4 +1,6 @@
 rootProject.name = 'huiliaoAPP'
+include ':react-native-push-notification'
+project(':react-native-push-notification').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-push-notification/android')
 include ':react-native-sound'
 project(':react-native-sound').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-sound/android')
 include ':react-native-audio'

+ 28 - 0
huiliaoAPP/ios/huiliaoAPP/AppDelegate.m

@@ -9,6 +9,7 @@
 
 #import <React/RCTBundleURLProvider.h>
 #import <React/RCTRootView.h>
+#import <React/RCTPushNotificationManager.h>
 
 @implementation AppDelegate
 
@@ -32,4 +33,31 @@
   return YES;
 }
 
+// Required to register for notifications
+- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
+{
+  [RCTPushNotificationManager didRegisterUserNotificationSettings:notificationSettings];
+}
+// Required for the register event.
+- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
+{
+  [RCTPushNotificationManager didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
+}
+// Required for the notification event. You must call the completion handler after handling the remote notification.
+- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
+fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
+{
+  [RCTPushNotificationManager didReceiveRemoteNotification:userInfo fetchCompletionHandler:completionHandler];
+}
+// Required for the registrationError event.
+- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
+{
+  [RCTPushNotificationManager didFailToRegisterForRemoteNotificationsWithError:error];
+}
+// Required for the localNotification event.
+- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
+{
+  [RCTPushNotificationManager didReceiveLocalNotification:notification];
+}
+
 @end

+ 2 - 0
huiliaoAPP/package.json

@@ -10,6 +10,7 @@
   "dependencies": {
     "ac-qrcode": "^1.0.1",
     "antd-mobile-rn": "^2.2.1",
+    "leancloud-installation": "^2.0.1",
     "leancloud-realtime": "^4.2.0",
     "leancloud-realtime-plugin-typed-messages": "^3.0.1",
     "leancloud-storage": "^3.10.0",
@@ -24,6 +25,7 @@
     "react-native-filesystem": "^0.1.0",
     "react-native-image-crop-picker": "^0.21.1",
     "react-native-keyboard-aware-scroll-view": "^0.7.0",
+    "react-native-push-notification": "^3.1.1",
     "react-native-qrcode": "^0.2.7",
     "react-native-sound": "^0.10.9",
     "react-native-swipeout": "^2.3.6",

+ 22 - 3
huiliaoAPP/src/pages/Welcome/index.js

@@ -1,8 +1,10 @@
 import React,{Component} from 'react';
 
-import {View,Text} from 'react-native';
+import {View,Text,PushNotificationIOS} from 'react-native';
+
+import LeanCloudAPI from '../../leancloud';
+
 
-import LeanCloudAPI from '../../leancloud'
 
 //中间跳转页 。。。
 
@@ -29,7 +31,24 @@ class Welcome extends Component {
             navigation.navigate({ routeName })
         },2000)
     }
-
+    componentDidMount() {
+        // Subscribe to register event of PushNotificationIOS.
+        PushNotificationIOS.addEventListener('register', this._onRegister);
+        // Request permissions and deviceToken
+        PushNotificationIOS.requestPermissions();
+    }
+    _onRegister(deviceToken) {
+        alert(deviceToken)
+        // LeancloudInstallation.getCurrent()
+        //   .then(installation =>
+        //     // Set new deviceToken and save.
+        //     installation.save({
+        //       deviceToken: deviceToken,
+        //       apnsTopic: 'com.example',
+        //       deviceType: 'ios',
+        //     })
+        //   )
+      }
     render(){
         return(
             <View style={{flex:1,justifyContent:"center",alignItems:"center"}}>

+ 15 - 1
huiliaoAPP/yarn.lock

@@ -4107,6 +4107,10 @@ jsprim@^1.2.2:
     json-schema "0.2.3"
     verror "1.10.0"
 
+jstz@^1.0.7:
+  version "1.0.11"
+  resolved "http://registry.npm.taobao.org/jstz/download/jstz-1.0.11.tgz#70e83e55c9621bfa706cdc8aa73f2a03931de7d9"
+
 jwa@^1.1.5:
   version "1.1.6"
   resolved "https://registry.yarnpkg.com/jwa/-/jwa-1.1.6.tgz#87240e76c9808dbde18783cf2264ef4929ee50e6"
@@ -4166,6 +4170,12 @@ lcid@^1.0.0:
   dependencies:
     invert-kv "^1.0.0"
 
+leancloud-installation@^2.0.1:
+  version "2.0.1"
+  resolved "http://registry.npm.taobao.org/leancloud-installation/download/leancloud-installation-2.0.1.tgz#824bd7893b2abbf3427f837470e9a9a436b6e12a"
+  dependencies:
+    jstz "^1.0.7"
+
 leancloud-realtime-plugin-live-query@^1.1.1:
   version "1.1.1"
   resolved "https://registry.yarnpkg.com/leancloud-realtime-plugin-live-query/-/leancloud-realtime-plugin-live-query-1.1.1.tgz#8f553fa3ff54a13a1a280f62dfe82330c0b2f2d4"
@@ -4191,7 +4201,7 @@ leancloud-realtime@^4.2.0:
 
 leancloud-storage@^3.10.0:
   version "3.10.0"
-  resolved "https://registry.yarnpkg.com/leancloud-storage/-/leancloud-storage-3.10.0.tgz#6922ad6f12477a1a23bc114cc328c510873b9260"
+  resolved "http://registry.npm.taobao.org/leancloud-storage/download/leancloud-storage-3.10.0.tgz#6922ad6f12477a1a23bc114cc328c510873b9260"
   dependencies:
     debug "^3.1.0"
     es6-promise "4.2.3"
@@ -5643,6 +5653,10 @@ react-native-menu@^0.23.0:
     prop-types "^15.5.10"
     react-timer-mixin "^0.13.3"
 
+react-native-push-notification@^3.1.1:
+  version "3.1.1"
+  resolved "http://registry.npm.taobao.org/react-native-push-notification/download/react-native-push-notification-3.1.1.tgz#99ce426e78e95788c298f73750cc4e68db04d7ab"
+
 react-native-qrcode@^0.2.7:
   version "0.2.7"
   resolved "https://registry.yarnpkg.com/react-native-qrcode/-/react-native-qrcode-0.2.7.tgz#d103166fb1a5b53643e8bf7b88c0672e689ac4f8"