【问题标题】:Acumatica mobile push notification without using Business Event不使用 Business Event 的 Acumatica 移动推送通知
【发布时间】:2020-04-06 19:12:35
【问题描述】:

如何在不使用 Business Event 的情况下发送移动推送通知?

【问题讨论】:

    标签: c# acumatica acumatica-kb


    【解决方案1】:

    当用户点击通知时,可以在不使用Business Events 的情况下发送mobile push notification 以在移动应用程序中打开屏幕。

    下面的例子描述了方法:

    using System;
    using System.Collections;
    using System.Linq;
    using System.Threading;
    using CommonServiceLocator;
    using PX.Api.Mobile.PushNotifications;
    using PX.Common;
    using PX.Data;
    using PX.Objects.SO;
    
    namespace PX.PushNotificatioinSample.Ext
    {
        public class SOOrderEntryPXExt : PXGraphExtension<SOOrderEntry>
        {
            public PXAction<SOOrder> ViewOnMobileApp;
            [PXUIField(DisplayName = Messages.ViewActionDisplayName, 
                       MapEnableRights = PXCacheRights.Select, MapViewRights = PXCacheRights.Select)]
            [PXButton(SpecialType = PXSpecialButtonType.Default)]
            public virtual IEnumerable viewOnMobileApp(PXAdapter adapter)
            {
                if (Base.Document.Cache.GetStatus(Base.Document.Current) == PXEntryStatus.Inserted ||
                    Base.Document.Cache.GetStatus(Base.Document.Current) == PXEntryStatus.InsertedDeleted) { return adapter.Get(); }
    
                //Get instance of PushNotification service
                var pushNotificationSender = ServiceLocator.Current.GetInstance<IPushNotificationSender>();
    
                //Users to whom message will be sent
                var userIds = new[] { PXAccess.GetUserID() };
    
                //Check if User is using Acumatica Mobile App
                var activeTokens = pushNotificationSender.CountActiveTokens(userIds);
                if (activeTokens == 0)
                {
                    throw new PXException(Messages.NoDeviceError);
                }
    
                string sOrderNbr = Base.Document.Current.OrderNbr;
                string sScreenID = Base.Accessinfo.ScreenID.Replace(".", "");
                Guid noteID = Base.Document.Current.NoteID.Value;
    
                PXLongOperation.StartOperation(Base, () =>
                {
                    try
                    {
                        pushNotificationSender.SendNotificationAsync(
                                            userIds: userIds,
                                            // Push Notification Title
                                            title: Messages.PushNotificationTitle,
                                            // Push Notification Message Body
                                            text: $"{ Messages.PushNotificationMessageBody } { sOrderNbr }.",
                                            // Link to Screen to open upon tap with Sales Order data associated to NoteID
                                            link: (sScreenID, noteID),
                                            cancellation: CancellationToken.None);
                    }
                    catch (AggregateException ex)
                    {
                        var message = string.Join(";", ex.InnerExceptions.Select(c => c.Message));
                        throw new InvalidOperationException(message);
                    }
                });
    
                return adapter.Get();
            }
        }
    
        [PXLocalizable]
        public static class Messages
        {
            public const string ViewActionDisplayName = "View On Mobile App";
            public const string NoDeviceError = "You need to set up the Acumatica mobile app.";
            public const string PushNotificationTitle = "View Sales Order";
            public const string PushNotificationMessageBody = "Tap to view Sales Order # ";
        }
    }
    

    【讨论】:

    • 出于什么目的,您鼓励使用标有 [PXInternalUseOnlyAttribute] 的接口?此属性意味着 Acumatica 可以在任何版本(主要或次要)中更改或删除它,并且不会在发行说明中注意到它,因为它不会是重大更改。
    猜你喜欢
    • 1970-01-01
    • 2021-09-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-22
    • 2019-10-13
    相关资源
    最近更新 更多