onesignal 不订阅设备反应原生

问题描述

我目前正在尝试将 onesignal 安装到我的 expo react 本机项目中。我确实按照文档将 sdk 安装到我的项目中,但它没有订阅我的真实设备,也没有将某些内容记录到控制台中。我使用 expo 裸工作流,我还设法安装了 react-native-onesignal。这是我所做的

在我的android/app/build.gradle

buildscript {
repositories {
    gradlePluginPortal()
}
dependencies {
    classpath 'gradle.plugin.com.onesignal:onesignal-gradle-plugin:[0.12.10,0.99.99]'
}
}

apply plugin: 'com.onesignal.androidsdk.onesignal-gradle-plugin'
apply plugin: "com.android.application"
apply plugin: 'com.google.gms.google-services'
...

这里是我的 index.js

的完整代码
import { registerRootComponent } from 'expo'
import Onesignal from 'react-native-onesignal'
import App from './App';

//Onesignal Init Code
Onesignal.setLogLevel(6,0);
Onesignal.setAppId("24309fcb-e76a-4e7e-a410-c14e80446363");
//END Onesignal Init Code

//Prompt for push on iOS
Onesignal.promptForPushNotificationsWithUserResponse(response => {
console.log("Prompt response:",response);
});

//Method for handling notifications received while app in foreground
Onesignal.setNotificationWillShowInForegroundHandler(notificationReceivedEvent => {
console.log("Onesignal: notification will show in foreground:",notificationReceivedEvent);
let notification = notificationReceivedEvent.getNotification();
console.log("notification: ",notification);
const data = notification.additionalData
console.log("additionalData: ",data);
// Complete with null means don't show a notification.
notificationReceivedEvent.complete(notification);
});

//Method for handling notifications opened
Onesignal.setNotificationopenedHandler(notification => {
console.log("Onesignal: notification opened:",notification);
});
// registerRootComponent calls AppRegistry.registerComponent('main',() => App);
// It also ensures that whether you load the app in the Expo client or in a native build,// the environment is set up appropriately
// LogBox.ignoreLogs(['Remote debugger']);
registerRootComponent(App);

我不知道为什么它不起作用,或者我可能遗漏了什么。感谢帮助

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)