如何使用Onesignal创建向用户发送自定义消息

时间:2020-01-13 07:11:13

标签: flutter onesignal

我尝试了下面的代码来在单击按钮时向用户发送消息。为此,我遵循了onesignal文档。但是我想撰写自定义消息并发送。

 new OneSignalButton("Post Notification",_handleSendNotification, !_enableConsentButton)

Handling function
    void _handleSendNotification() async {
    var status = await OneSignal.shared.getPermissionSubscriptionState();

    var playerId = status.subscriptionStatus.userId;

    var imgUrlString =
        "http://cdn1-www.dogtime.com/assets/uploads/gallery/30-impossibly-cute-puppies/impossibly-cute-puppy-2.jpg";

    var notification = OSCreateNotification(
        playerIds: [playerId],
        content: "This is the message", // 
        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";
    });
  }

我的意图是创建一个文本框和一个按钮。单击按钮后,用户在文本框中输入的内容应以通知的形式发送。 请帮忙。

0 个答案:

没有答案