Example #1
0
        /// <summary>
        /// Push notification to client
        /// </summary>
        /// <param name="targetAudience">set the target audience</param>
        /// <param name="message">Message on notification</param>
        /// <param name="extraContent">Extra content on notification, will translate to json</param>
        /// <param name="androidPriority">High/Max : Will have banner in Android</param>
        /// <param name="androidAlertType">Indicator the notification method in Android</param>
        /// <param name="platform">indicate target platform</param>
        /// <returns>HttpResponse content</returns>
        public PushResult Push(string message, string title, Enum.Platform platform = Enum.Platform.iOSProductionAndAndroid, object targetAudience = null, Dictionary <string, object> extraContent = null
                               , Enum.AndroidPriority androidPriority   = Enum.AndroidPriority.PRIORITY_DEFAULT
                               , Enum.AndroidAlertType androidAlertType = Enum.AndroidAlertType.All)
        {
            PushResult pushResult = null;

            Jiguang.JPush.Model.PushPayload payload = new Jiguang.JPush.Model.PushPayload();
            try
            {
                if (targetAudience != null)
                {
                    payload.Audience = targetAudience;
                }
                bool isApnsProduction = false;
                if (platform == Enum.Platform.iOSProduction || platform == Enum.Platform.iOSProductionAndAndroid)
                {
                    isApnsProduction = true;
                }
                payload.Options = new Jiguang.JPush.Model.Options
                {
                    IsApnsProduction = isApnsProduction
                };
                payload.Notification = new Jiguang.JPush.Model.Notification();
                if (platform == Enum.Platform.Android)
                {
                    payload.Notification.Android = createAndroidNotification(message, title, androidPriority, extraContent, androidAlertType);
                }
                else if (platform == Enum.Platform.iOSDevelopment || platform == Enum.Platform.iOSProduction)
                {
                    payload.Notification.IOS = createIOSNotification(message, title, extraContent);
                }
                else if (platform == Enum.Platform.iOSDevelopmentAndAndroid || platform == Enum.Platform.iOSProductionAndAndroid)
                {
                    payload.Notification.IOS     = createIOSNotification(message, title, extraContent);
                    payload.Notification.Android = createAndroidNotification(message, title, androidPriority, extraContent, androidAlertType);
                }



                var result = jPushClient.SendPush(payload);
                pushResult = new PushResult(result.Content);
            }
            catch (Exception ex)
            {
                pushResult = new PushResult
                {
                    isSuccess = false,
                    errorMsg  = ex.Message
                };
            }

            return(pushResult);
        }
Example #2
0
 private Jiguang.JPush.Model.Android createSlientAndroidNotification(string message, string title, Enum.AndroidPriority priority, Dictionary <string, object> extraContent, Enum.AndroidAlertType alertType)
 {
     return(new Jiguang.JPush.Model.Android
     {
         Extras = extraContent,
         Priority = (int)priority,
         AlertType = (int)alertType,
         Alert = message,
         Title = title
     });
 }