通知未显示在React Native应用中

时间:2019-03-03 13:36:03

标签: react-native push-notification

我不知道为什么通知未显示在我的应用中。我使用了react native推送通知包。

版本:
“ react-native-push-notification”:“ ^ 3.1.2”, “ react-native”:“ 0.55.2”,

build.gradle

ext {
    googlePlayServicesVersion = "+"
    firebaseVersion =  "+"
    buildToolsVersion = "26.1.0"
    minSdkVersion = 16
    compileSdkVersion = 26
    targetSdkVersion = 23
    supportLibVersion = "26.1.0"
 }

settings.gradle

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-push-notification'

MainApplication.java

import android.app.Application;

import com.facebook.react.ReactApplication;
import com.dieam.reactnativepushnotification.ReactNativePushNotificationPackage;
import com.lugg.ReactNativeConfig.ReactNativeConfigPackage;
 ...

import java.util.Arrays;
import java.util.List;

public class MainApplication extends Application implements ReactApplication {

  private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
    @Override
    public boolean getUseDeveloperSupport() {
      return BuildConfig.DEBUG;
    }

    @Override
    protected List<ReactPackage> getPackages() {
      return Arrays.<ReactPackage>asList(
          new MainReactPackage(),
            new ReactNativePushNotificationPackage(),
            new ReactNativeConfigPackage(),
            new LottiePackage(),
            new VectorIconsPackage(),
            new RNGestureHandlerPackage()
      );
    }

     ...
}

添加到.js文件(在顶部):

import PushNotification  from 'react-native-push-notification';
PushNotification.configure({
           onRegister: function (token) {
                console.log(token);
            },
            onNotification: (notification) => {
                console.log('NOTIFICATION:', JSON.stringify(notification));
            },
            permissions: {   
                alert: true,
                badge: true,
                sound: true,
            },
            popInitialNotification: true,
            requestPermissions: true
        });

功能:

 add = () => {
    PushNotification.localNotification({
    message: "My Notification Message"
    })
  } 

我想这可能与android版本设置有关。谁能帮我?

0 个答案:

没有答案