首页 > 解决方案 > 从颤振发送一个信号通知

问题描述

我有一个用 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";
    });
  }

标签: flutterpush-notificationonesignal

解决方案


听起来您正在寻找P2P(用户-用户)通知。您将需要一种从 Flutter 应用程序获取目标应用程序 (Unity) 的播放器 ID 的方法。


推荐阅读