flutter - 从颤振发送一个信号通知
问题描述
我有一个用 Unity 创建的 android 应用程序,我可以从 OneSignal 网站和我的 php 网站成功地向这个应用程序发送通知。现在我想从颤振应用程序(android)发送通知。我尝试了用于颤振示例的 onesignal sdk,但它将通知发送到颤振应用程序而不是 Unity 应用程序。我不知道我错在哪里:
Future<void> initPlatformState() async {
if (!mounted) return;
var settings = {
OSiOSSettings.autoPrompt: false,
OSiOSSettings.promptBeforeOpeningPushUrl: true
};
// NOTE: Replace with your own app ID from https://www.onesignal.com
await OneSignal.shared
.init("9a98990f-40fa-455e-adda-ccd474594f41", iOSSettings: settings);
OneSignal.shared
.setInFocusDisplayType(OSNotificationDisplayType.notification);
bool requiresConsent = await OneSignal.shared.requiresUserPrivacyConsent();
this.setState(() {
_enableConsentButton = requiresConsent;
});
}
void _handleSendNotification() async {
var status = await OneSignal.shared.getPermissionSubscriptionState();
var playerId = status.subscriptionStatus.userId;
var imgUrlString =
"https://vaars.000webhostapp.com/MrNutella/logonutella.png";
var notification = OSCreateNotification(
playerIds: [playerId],
content: "this is a test from OneSignal's Flutter SDK",
heading: "Test Notification",
iosAttachments: {"id1": imgUrlString},
bigPicture: imgUrlString,
buttons: [
OSActionButton(text: "test1", id: "id1"),
OSActionButton(text: "test2", id: "id2")
]);
var response = await OneSignal.shared.postNotification(notification);
this.setState(() {
_debugLabelString = "Sent notification with response: $response";
});
}
解决方案
听起来您正在寻找P2P(用户-用户)通知。您将需要一种从 Flutter 应用程序获取目标应用程序 (Unity) 的播放器 ID 的方法。
推荐阅读
- java - 在没有 forceRegenerate 的情况下让 maven jaxb2 插件正常工作的问题
- android - Flutter 默认颜色值
- php - 如何使用 Laravel Fortify 创建身份验证锁屏?
- symfony - Symfony 和 FullCalendar,如何从数据库发送数据
- node.js - 如何使用与 Firebase 函数相同的端口设置 Telegram Webhook?
- javascript - 在 javascript 中执行 curl 请求
- java - 在 Netbeans 上编译:“线程“AWT-EventQueue-0”中的异常 java.lang.RuntimeException:无法编译的源代码 - 表达式的非法开始”
- amazon-web-services - 更改现有 AWS 资源上的 KMS 加密密钥
- java - 当我尝试登录我的应用程序时出现 401 未经授权的错误(jwt + spring boot + angular 应用程序)
- swift - 有什么方法可以获取 ITLibMediaItem 的物理文件?