Example #1
0
        static void Main(string[] args)
        {
            /* IOS push example */
            var     path    = "path of .p12 file";
            IOSPush iosPush = new IOSPush(ApnsServerEnvironment.Production /*ApnsServerEnvironment.Sandbox in case of development*/, path, "Password of p12 file");

            var json = "{\"ID\":\"121\",\"Name\":\"Shyam\",\"notificationActions\":[{\"NotificationName\":\"Add to reminder\",\"NotificationActionEntityValues\":[{\"NotificationEntityName\":\"Title\",\"NotificationEntityValue\":\"Test\"},{\"NotificationEntityName\":\"DateTime\",\"NotificationEntityValue\":\"Pqr-28-2016 8:00:00\"}]},{\"NotificationName\":\"Add to calendar\",\"NotificationActionEntityValues\":[{\"NotificationEntityName\":\"Title\",\"NotificationEntityValue\":\"Title\"},{\"NotificationEntityName\":\"Location\",\"NotificationEntityValue\":\"Location\"},{\"NotificationEntityName\":\"All day\",\"NotificationEntityValue\":\"N\"},{\"NotificationEntityName\":\"Start DateTime\",\"NotificationEntityValue\":\"Oct-30-2016 8:00:00\"},{\"NotificationEntityName\":\"End DateTime\",\"NotificationEntityValue\":\"Oct-30-2016 17:00:00\"},{\"NotificationEntityName\":\"Alert\",\"NotificationEntityValue\":\"None\"},{\"NotificationEntityName\":\"Show As\",\"NotificationEntityValue\":\"None\"},{\"NotificationEntityName\":\"Note\",\"NotificationEntityValue\":\"Some notes here\"}]}]}";

            //Regular push notification: 4KB (4096 bytes) based on HTTP/2-based APNs provider API
            iosPush.SendWithJSon("device token", "Test push send by Shyam Agarwal", json, new Action <Result>(x => {
                Console.WriteLine(x.status);
            }));

            //Regular push notification: 2KB (2048 bytes) based on Legacy APNs binary interface
            iosPush.Send("device token", "Test push send by Shyam Agarwal", "ID=121;Name=Shyam");

            /* Android push example*/
            AndroidPush androidPush = new AndroidPush("GCM Sender ID", "API key");

            var json1 = "{\"notificationName\":\"Name\",\"notificationSubject\":\"Notification Test by AK \",\"notificationBody\":\"Body\",\"sendToUsers\":\"[email protected]\",\"notificationTypeID\":1,\"notificationActions\":[{\"NotificationName\":\"Add to reminder\",\"NotificationActionEntityValues\":[{\"NotificationEntityName\":\"Title\",\"NotificationEntityValue\":\"Test\"},{\"NotificationEntityName\":\"DateTime\",\"NotificationEntityValue\":\"Dec/28/2016 15:00:00\"}]},{\"NotificationName\":\"Add to calendar\",\"NotificationActionEntityValues\":[{\"NotificationEntityName\":\"Title\",\"NotificationEntityValue\":\"Title\"},{\"NotificationEntityName\":\"Location\",\"NotificationEntityValue\":\"Location\"},{\"NotificationEntityName\":\"All day\",\"NotificationEntityValue\":\"N\"},{\"NotificationEntityName\":\"Start DateTime\",\"NotificationEntityValue\":\"Dec/28/2016 08:00:00\"},{\"NotificationEntityName\":\"End DateTime\",\"NotificationEntityValue\":\"Dec/10/2017 5:00:00 PM\"},{\"NotificationEntityName\":\"Alert\",\"NotificationEntityValue\":\"None\"},{\"NotificationEntityName\":\"Show As\",\"NotificationEntityValue\":\"\"},{\"NotificationEntityName\":\"Note\",\"NotificationEntityValue\":\"Some notes here\"}]}]}";

            androidPush.SendWithJSon("APA91bEfjIV0Bvdj11ta6HlRMJNsAcOG99uGm9vR1h61ZUf2SF4FxCkF7XLksCFgW_OEU-2H00DwHqrl2txEWSmfSDZaTsibste1Ff8X_6PEEbPnDIAeOQPtGPmLvVeU_Jj0nAPjPkc-", "PAGE 1", "Test push send by Shyam Agarwal", json1, new Action <Result>(x => {
                Console.WriteLine(x.status);
            }));
        }
Example #2
0
 static Push()
 {
     _pushListener.OnPushNotificationReceivedAction = notification =>
     {
         var pushEventArgs = new PushNotificationReceivedEventArgs
         {
             Title      = notification.Title,
             Message    = notification.Message,
             CustomData = notification.CustomData
         };
         PushNotificationReceived?.Invoke(null, pushEventArgs);
     };
     AndroidPush.SetListener(_pushListener);
 }
Example #3
0
        /// <summary>
        /// 告诉用户,订单配送中
        /// </summary>
        /// <param name="order"></param>
        public void PushUserSendingOrder(OrderInfo order)
        {
            var user        = UserInfoOper.Instance.GetById((int)order.userId);
            var deviceToken = user.deviceToken;

            if (user.deviceType == "ios")
            {
                IOSPush.PostOne(deviceToken, set.orderSendingTips, "TakeOrder", new Dictionary <string, string>());
            }
            else
            {
                AndroidPush.PostOne(deviceToken, set.orderSendingTips, "TakeOrder", new Dictionary <string, string>());
            }
        }
Example #4
0
        /// <summary>
        /// 告诉用户,订单送达了
        /// </summary>
        /// <param name="order"></param>
        public void PushUserOrderArrive(OrderInfo order)
        {
            var user        = UserInfoOper.Instance.GetById((int)order.userId);
            var deviceToken = user.deviceToken;
            var dict        = new Dictionary <string, string>();
            var orderId     = order.id.ToString();

            if (!string.IsNullOrEmpty(deviceToken))
            {
                if (user.deviceType == "ios")
                {
                    dict.Add("orderId", orderId.ToString());
                    IOSPush.PostOne(deviceToken, set.orderArrivelTips, "ArriveOrder", dict);
                }
                else
                {
                    dict.Add("arriveOrderId", orderId.ToString());
                    AndroidPush.PostOne(deviceToken, set.orderArrivelTips, "ArriveOrder", dict);
                }
            }
        }
Example #5
0
        /// <summary>
        /// 告诉用户,餐盒已经收到
        /// </summary>
        /// <param name="order"></param>
        public void PushUserRecovery(OrderInfo order)
        {
            var user = UserInfoOper.Instance.GetById((int)order.userId);

            user.userBalance += order.deposit;//押金退回余额
            UserInfoOper.Instance.Update(user);
            var deviceToken = user.deviceToken;
            var orderId     = order.id;
            var dict        = new Dictionary <string, string>();

            if (!string.IsNullOrEmpty(deviceToken))
            {
                if (user.deviceType == "ios")
                {
                    dict.Add("orderId", orderId.ToString());
                    IOSPush.PostOne(deviceToken, set.boxGetTips, "Recovery", dict);
                }
                else
                {
                    dict.Add("arriveOrderId", orderId.ToString());
                    AndroidPush.PostOne(deviceToken, set.boxGetTips, "Recovery", dict);
                }
            }
        }
Example #6
0
 /// <summary>
 /// If you are using the event for background push notifications
 /// and your activity has a launch mode such as singleTop, singleInstance or singleTask,
 /// need to call this method in your launcher OnNewIntent override method.
 /// </summary>
 /// <param name="activity">This activity.</param>
 /// <param name="intent">Intent from OnNewIntent().</param>
 public static void CheckLaunchedFromNotification(Activity activity, Intent intent)
 {
     AndroidPush.CheckLaunchedFromNotification(activity, intent);
 }
Example #7
0
 /// <summary>
 /// Call this before starting Push if you are using Firebase and want to use Firebase Analytics as well. If
 /// App Center detects Firebase, the default behavior is to disable it.
 /// </summary>
 public static void EnableFirebaseAnalytics()
 {
     AndroidPush.EnableFirebaseAnalytics(Application.Context);
 }
Example #8
0
 public static void SetSenderId(string senderId)
 {
     AndroidPush.SetSenderId(senderId);
 }
Example #9
0
        static Task PlatformSetEnabledAsync(bool enabled)
        {
            var future = AndroidPush.SetEnabled(enabled);

            return(Task.Run(() => future.Get()));
        }
Example #10
0
        static Task <bool> PlatformIsEnabledAsync()
        {
            var future = AndroidPush.IsEnabled();

            return(Task.Run(() => (bool)future.Get()));
        }