gpt4 book ai didi

flutter - 从 flutter 中发送一个信号通知

转载 作者:IT王子 更新时间:2023-10-29 07:02:38 27 4
gpt4 key购买 nike

我有一个使用 Unity 创建的 android 应用程序,我可以成功地从 OneSignal 网站和我的 php 网站向这个应用程序发送通知。现在我想从 flutter 应用程序 (android) 发送通知。我尝试了 onesignal sdk for flutter example 但它将通知发送到 flutter 应用程序而不是 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 (user-user)通知。您将需要一种方法从 Flutter 应用程序获取目标应用程序 (Unity) 的播放器 ID。

关于flutter - 从 flutter 中发送一个信号通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56827952/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com