在 PowerApps 中发送推送通知Send a push notification in PowerApps

推送通知用于移动应用中的使用者和业务情形,主要用来与应用用户进行交互,并帮助他们优先处理关键任务。Push notifications are used in mobile apps for consumer and business scenarios primarily to engage app users and help them prioritize key tasks. 在 PowerApps 中,可以使用 PowerApps 通知连接器发送通知。In PowerApps, you can send notifications by using the PowerApps Notification connector. 可以将原生推送通知发送到在 PowerApps 中创建的任何应用。You can send native push notifications to any app that you create in PowerApps. 我们计划在今后支持更多通知类型。We plan to add more notification types in the future.

推送通知外观示例

如果出现以下任意情况,请向应用添加推送通知:Add a push notification to your app if:

  • 用户需要立即了解相关信息。Your users need to know information immediately.
  • 用户必须使用应用在预加载的上下文中完成重要任务。Your users must complete important tasks by using your app, in a preloaded context.
  • 希望按特定时间间隔与用户进行交互,或需要用户在特定情况下进入应用。You want to engage your users on a specific interval, or you need users to enter the app in a specific context.

注意:每个用户必须在 PowerApps Mobile 中打开过一次应用,或在 Dynamics 365 中从 AppSource 获取过应用,才能接收推送通知。Note: To receive push notifications, each user must have opened the app in PowerApps Mobile once or gotten the app from AppSource in Dynamics 365.

开始之前Before you start

在拥有参与者权限的应用中,添加 PowerApps 通知连接。In an app for which you have the Contributor permission, add a PowerApps Notification connection. 如果尚未生成应用,可以通过模板快速创建一个,默认拥有所需的权限。If you don't already have an app, you can quickly create one from a template, and you'll have the required permission by default. 上面提及的教程和本教程均使用根据用例管理模板生成的应用。That tutorial and this one use an app based on the Case Management template.

通过流发送通知Send a notification from a flow

注意:如果通过流触发推送通知,那么目前一次只能向一个用户或安全组发送通知。Note: If you trigger a push notification from a flow, you can send the notification to only one user or security group at a time currently.

  1. Microsoft Flow 中,创建一个触发器,指定何时发送推送通知。In Microsoft Flow, create a trigger that specifies when the push notification is sent.

    例如,建议在记录被添加到 Common Data Service 中的“用例”实体时发送通知。For example, you might want to send a notification when a record is added to the Case entity in the Common Data Service.

    创建包含 Common Data Service 触发器的流的屏幕截图

  2. 使用“PowerApps 通知”连接器创建流操作,再输入要向其发送通知的应用的应用 ID。Create an action for the flow by using the PowerApps Notification connector, and enter the App ID of the app to which you want to send notifications.

    还可以重命名连接,以反映具体方案。You can also rename the connection to reflect your scenario.

    创建用于接收这些推送通知的 PowerApps 连接的屏幕截图

  3. (可选)在用户点击推送通知后应用打开时,将参数传递给应用。(optional) Pass parameters to the app when it opens (after the user taps the push notification).

    此示例为选定联系人传递“用例 ID”和“初始所有者”字段。In our example, we pass along the Case ID and Initial Owner fields for the selected contact.

    将可选参数传递到推送通知的屏幕截图

通过应用发送通知Send a notification from an app

可以将推送通知从一个应用发送到另一个应用,也可以发送到同一个应用。You can send a push notification from one app to another or to the same app.

  1. PowerApps 中,转到要向其发送推送通知的应用。In PowerApps, go to the app to which you want to send push notifications.
  2. 在“详细信息”选项卡上,复制此应用的“应用 ID”。On the Details tab, copy the App ID of that app.

    获取应用 ID

  3. 在“连接”选项卡上,创建与 PowerApps 通知连接器的连接,并粘贴上一步中复制的应用 ID。On the Connections tab, create a connection to the PowerApps Notification connector, and paste in the app ID from the previous step.

    创建连接

  4. 将连接添加到触发器应用。Add the connection to the trigger app.

    此示例使用相同的应用作为触发器应用。In our example, we use the same app as the trigger app. 如果用户重新分配用例,也会触发向新的用例所有者发送推送通知。The user who reassigns the case also triggers a push notification to the new case owner.

    添加连接

  5. 通过推送通知连接,调用 SendPushNotification 方法。From the push notification connection, call the SendPushNotification method.

    此示例使用窗体中的 OnSuccess 属性触发此通知。In our example, we trigger this notification by using the OnSuccess property in a form.

    PowerApps 公式

在用户点击通知时加载特定页和上下文Load a specific page and context when a user taps the notification

传递参数Pass parameters

推送通知可以向应用传递特定参数。Your push notification can pass specific parameters to the app. 例如,若要读取 CaseID 值,请使用 Param("CaseID")。For example, to read the CaseID value, use Param("CaseID"). 若要快速识别此参数,请在应用中添加“标签”控件。To quickly identify this parameter, add a Label control to your app. 将此控件的 Text 属性设置为 Param("CaseID")。Set the Text property of that control to Param("CaseID"). 如果用户从“所有应用”列表打开应用,此值为空。If the user opens the app from the All apps list, the value is empty. 如果用户从设备上的其他位置打开应用,此值就会填充有 CaseID 值。If the user opens the app from another location on the device, the value is populated with the CaseID value.

设置起始页Set the start page

例如,可以将应用设置为打开后显示“用例详情”页:You can set your app to open, for example, the Case details page as soon as the app opens:

  1. 添加“计时器”控件,并将 OnTimerEnd 属性设置为以下公式:Add a Timer control, and set its OnTimerEnd property to this formula:
    Navigate(EditCase, ScreenTransition.None)Navigate(EditCase, ScreenTransition.None)
  2. (可选)将 Visible 属性设置为 false,隐藏“计时器”控件。(optional) Hide the Timer control by setting its Visible property to false.
  3. 将屏幕的 OnVisible 属性设置为 Timer.Start()。Set the OnVisible property of the screen to Timer.Start().

提示:最好在应用中为通知创建专属首页:Tip: It's a good idea to create a unique first page in the app for the notification:

  1. 创建应用尚未打开的空页,添加“文本输入”控件,并设置 timer.Duration 值。Create an empty page that your app doesn't already open, add a Text Input control, and set its timer.Duration value.
  2. 创建应用时,将计时器设置为非零值。When you create the app, set the timer to a non-zero value. 如果已准备好发布应用,请将值设置为 0,以立即触发计时器。When you're ready to publish the app, set the value to 0 to immediately trigger the timer.

语法Syntax

名称Name 说明Description
SendPushNotificationSendPushNotification 向通知连接设置中指定的应用发送推送通知。Sends a push notification to the app that's specified in the connection settings for the notification.

参数Parameters

名称Name 类型Type 说明Description
recipientsrecipients 字符串数组(必需)String array, required 列出了:A list of:
  • 用户或安全组的电子邮件地址Email addresses for users or security groups
  • Azure Active Directory 中用户或安全组的对象 IDObject IDs for users or security groups in Azure Active Directory
messagemessage 字符串(必需)String, required 推送通知的消息正文。The message body of the push notification.
openAppopenApp 布尔值(可选)Boolean, optional 是否在用户点击推送通知时打开应用。Whether to open the app when the user taps the push notification.
paramsparams 参数(可选)Parameters, optional 与通知一同传递的键值参数。Key-value parameters to pass with the notification. 可以在应用中进一步处理这些参数,以打开特定页并加载特定状态上下文。These can be further processed in the app to open a specific page and load a specific state.

示例公式Sample formulas

发送基本通知。Send a basic notification.

PowerAppsNotification.SendPushNotification(
{
  recipients: [""f60ccf6f-7579-4f92-967c-2920473c966b", 72f988bf-86f1-41af-91ab-2d7cd011db47],
  message: "A new case was assigned to you."
 }
)

发送可打开应用并传递特定参数的通知。Send a notification that opens an app and passes along specific parameters.

PowerAppsNotification.SendPushNotification(
{
  recipients:["email1@contoso.com", "email2@contoso.com"],
  message:"message in the notif toast",
  params:Table({key:"notificationKey", value:"The value for notificationKey"}),
  openApp:true
 }
)

已知的限制Known limitations

  • 通知暂不显示在适用于 Windows Phone 的 PowerApps Mobile 上。Currently, notifications aren't displayed on PowerApps Mobile for Windows Phone.
  • 我们暂无法为仅在 Web 浏览器中运行应用的用户提供推送通知。Currently, we don't provide push notifications for users who run apps only in a web browser.
  • 通知显示常规 PowerApps 图标,而不是特定应用图标。Notifications show the generic PowerApps icon instead of a specific app icon.
  • 使用 Microsoft Flow 时,一次只能向一个接收人发送推送通知。When you use Microsoft Flow, you can send a push notification to only one recipient at a time.

有关参考信息,请参阅 PowerApps 通知参考For reference information, see PowerApps Notification reference.