public static Notification ios(string alert) { IosNotification iosNotification = new IosNotification().setAlert((object)alert); Notification notification = new Notification().setAlert(alert); notification.IosNotification = iosNotification; return(notification); }
public static Notification ios(String alert) { var iosNotification = new IosNotification().setAlert(alert); var notification = new Notification().setAlert(alert); notification.IosNotification = iosNotification; return(notification); }
// Events //this even raised when a notification is successfully sent public static void NotificationSucceeded(INotification notification) { MyWebEntryPoint mw = new MyWebEntryPoint(null); IosNotification iosNotif = (IosNotification)notification; PushNotificationWrapperEvents.ONNotificationSucceeded(iosNotif, mw, mw.getIMDB()); mw.CloseAllDBConnections(); }
public void testBadge_minus_2() { IosNotification ios = new IosNotification().incrBadge(-2); JObject json = new JObject(); json.Add("sound", JToken.FromObject("")); json.Add("badge", JToken.FromObject("-2")); Assert.AreEqual(json.ToString(Formatting.None), JsonConvert.SerializeObject(ios, jSetting)); }
public void testSound() { IosNotification ios = new IosNotification().setSound("sound"); JObject json = new JObject(); json.Add("sound", JToken.FromObject("sound")); json.Add("badge", JToken.FromObject("+1")); Assert.AreEqual(json.ToString(Formatting.None), JsonConvert.SerializeObject(ios, jSetting)); }
public static Notification ios_incr_badge(int badge) { var platformNotification = new IosNotification(); platformNotification.incrBadge(badge); var notificaiton = new Notification(); notificaiton.IosNotification = platformNotification; return(notificaiton); }
public static Notification ios_auto_badge() { IosNotification iosNotification = new IosNotification(); iosNotification.autoBadge(); Notification notification = new Notification().setAlert(""); notification.IosNotification = iosNotification; return(notification); }
public static Notification ios_set_badge(int badge) { IosNotification iosNotification = new IosNotification(); iosNotification.setBadge(badge); return(new Notification() { IosNotification = iosNotification }); }
public static Notification ios_auto_badge() { var platformNotification = new IosNotification(); platformNotification.autoBadge(); var notificaiton = new Notification().setAlert("");; notificaiton.IosNotification = platformNotification; return(notificaiton); }
/// <summary> /// 发送推送 /// </summary> /// <param name="alert">推送内容</param> /// <param name="MemberIds">推送到的用户用逗号分隔, 如果留空则为全部用户</param> /// <param name="MerId">商家ID</param> public void SendPush(string alert, string MemberIds, string eventStr, decimal MerId, string[] tag) { string[] sa = { "JPushAppKey", "JPushMasterSecret" }; Dictionary <string, string> MerConfig = BLL.StaticBLL.MerConfig(MerId, sa); JPushClient client = new JPushClient(MerConfig["JPushAppKey"], MerConfig["JPushMasterSecret"]); PushPayload pushPayload = new PushPayload(); pushPayload.platform = Platform.all(); var notification = new Notification().setAlert(alert); AndroidNotification androidNotification = new AndroidNotification(); IosNotification iosNotification = new IosNotification(); Options options = new Options(); options.apns_production = true; //生产环境的 pushPayload.options = options; androidNotification.AddExtra("eventStr", eventStr); iosNotification.AddExtra("eventStr", eventStr); notification.setAndroid(androidNotification); notification.setIos(iosNotification); if (MemberIds.Trim() != "") { //如果不为空,说明指定了MemberId string[] MemberArray = MemberIds.Split(','); pushPayload.audience = Audience.s_alias(MemberArray); //推送设备对象,表示一条推送可以被推送到那些设备,确认推送设备的对象,JPush提供了多种方式,比如:别名,标签,注册id,分群,广播等。 } else if (tag != null) { if (tag.Length > 0) { pushPayload.audience = Audience.s_tag(tag); //按照标签推送 } } else { pushPayload.audience = Audience.all();//推送设备对象,表示一条推送可以被推送到那些设备,确认推送设备的对象,JPush提供了多种方式,比如:别名,标签,注册id,分群,广播等。 } pushPayload.notification = notification; pushPayload.message = Message.content("msg") .AddExtras("DoEvent", "GetNewMsgNum()"); //如果不加一条自定义消息的话, android是不会触发监听事件的.但是IOS可以 var result = client.SendPush(pushPayload); }
public void testBadgeDisabled() { IosNotification ios = new IosNotification().disableBadge().setAlert("alert"); JObject json = new JObject(); json.Add("sound", JToken.FromObject("")); json.Add("alert", JToken.FromObject("alert")); Assert.AreEqual(json.ToString(Formatting.None), JsonConvert.SerializeObject(ios, jSetting)); }
/// <summary> /// IOS群发 /// </summary> /// <returns></returns> public static PushPayload PushObject_All_All_Aler_ios() { PushPayload pushPayload = new PushPayload(); pushPayload.platform = Platform.ios(); pushPayload.audience = Audience.all(); var notification = new IosNotification().setAlert(ALERT); pushPayload.notification = new Notification().setIos(notification); pushPayload.options.apns_production = true; return(pushPayload); }
private IosNotification createIosNotification() { //定制ios效果 IosNotification ios = new IosNotification(); ios.setSound("default"); //必须设置,否则无声音 ios.setContentAvailable(false); //非静默推送 //ios.setCategory();ios8才支持 ios.autoBadge(); //原有的badge基础上+1 //ios.incrBadge(5);原有的badge值加上你所设定值 return(ios); }
/// <summary> /// 推送到单个App IOS设备 /// </summary> /// <param name="registrationId"></param> /// <param name="MsgContent"></param> /// <returns></returns> public static PushPayload PushObject_IOSMsg(string registrationId, string MsgContent) { string[] register = registrationId.Split(','); PushPayload pushPayload = new PushPayload(); pushPayload.platform = Platform.ios(); pushPayload.audience = Audience.s_registrationId(register); var notification = new IosNotification().setAlert(MsgContent); pushPayload.notification = new Notification().setIos(notification); pushPayload.options.apns_production = true; return(pushPayload); }
private static IosNotification GetIosNotification( string content, Dictionary <string, string> keyValueParams) { var iosNotification = new IosNotification(); iosNotification.setAlert(content); foreach (var keyValueParam in keyValueParams) { iosNotification.AddExtra(keyValueParam.Key, keyValueParam.Value); } return(iosNotification); }
// //this is raised when a notification is failed due to some reason public static void NotificationFailed(INotification notification, String error) { MyWebEntryPoint mw = new MyWebEntryPoint(null); com.progamma.IDVariant ErrorMessage = new com.progamma.IDVariant(); ErrorMessage.set(new com.progamma.IDVariant(error)); IosNotification IosNotif = (IosNotification)notification; PushNotificationWrapperEvents.ONNotificationFailed(IosNotif, ErrorMessage, mw, mw.getIMDB()); mw.CloseAllDBConnections(); }
protected override void AddKeyContentAndExtras(PushPayload pushPayload) { pushPayload.notification = new Notification(); pushPayload.notification.setAlert(Content); var androidNotification = new AndroidNotification().AddExtra("key", Key); var iosNotification = new IosNotification().AddExtra("key", Key); if (!string.IsNullOrEmpty(Value)) { androidNotification.AddExtra("value", Value); iosNotification.AddExtra("value", Value); } pushPayload.notification.setAndroid(androidNotification).setIos(iosNotification); }
public void testExtra() { IosNotification ios = new IosNotification().AddExtra("key", "value").AddExtra("key2", true); JObject json = new JObject(); JObject extra = new JObject(); extra.Add("key", JToken.FromObject("value")); extra.Add("key2", JToken.FromObject(true)); json.Add("sound", JToken.FromObject("")); json.Add("badge", JToken.FromObject("+1")); json.Add("extras", extra); Assert.AreEqual(json.ToString(Formatting.None), JsonConvert.SerializeObject(ios, jSetting)); }
private PushPayload GetPushPayload(SnsRequest request) { PushPayload pushPayload = new PushPayload(); pushPayload.platform = Platform.all(); pushPayload.audience = Audience.all(); pushPayload.options.apns_production = JpushAppApn; //JpushAppApn //pushPayload.notification = new Notification().setAlert(request.PushMsg); AndroidNotification androidNotification = new AndroidNotification(); IosNotification iosNotification = new IosNotification(); androidNotification.setAlert(request.PushMsg); iosNotification.setAlert(request.PushMsg); if (request.PushExtras != null) { foreach (var item in request.PushExtras) { androidNotification.AddExtra(item.Key, item.Value); iosNotification.AddExtra(item.Key, item.Value); } } if ((int)request.PushType != 0) { androidNotification.AddExtra("type", (int)request.PushType); iosNotification.AddExtra("type", (int)request.PushType); } cn.jpush.api.push.mode.Notification noti = new cn.jpush.api.push.mode.Notification(); noti.setAndroid(androidNotification); noti.setIos(iosNotification); //pushPayload.notification = new Notification().setAndroid(noty1); //pushPayload.notification = new Notification().setIos(noty2); pushPayload.notification = noti; return(pushPayload); }
public async Task SendDataNotificationToAllDevicesAsync(string[] notificationIds, NotificationType type, string entity, string id = "") { var apnsMessage = new IosNotification { Aps = new DataNotificationFields { Type = type } }; var gcmMessage = new AndoridPayloadNotification { Data = new AndroidPayloadFields { Entity = EventsAndEntities.GetEntity(type), Event = EventsAndEntities.GetEvent(type), Id = id } }; await SendIosNotificationAsync(notificationIds, apnsMessage); await SendAndroidNotificationAsync(notificationIds, gcmMessage); }
/// <summary> /// 向用户推送一条消息 /// </summary> /// <param name="appid">平台表示ID</param> /// <param name="user_id">用户ID</param> /// <param name="title">标题</param> /// <param name="content">内容</param> public static void SendPush(string appid, string target, string title, string content, PushTarget pushTarget = PushTarget.User) { Audience audience = null; if (pushTarget == PushTarget.User) { audience = Audience.s_alias(new string[] { target.ToString() }); } else { audience = Audience.s_tag(new string[] { target.ToString() }); } #region 构造安卓消息模板 AndroidNotification androidNotification = new AndroidNotification(); androidNotification.setTitle(title); #endregion #region 构造IOS消息模板 IosNotification iosNotification = new IosNotification(); iosNotification.setBadge(1); #endregion PushPayload pushPayload = new PushPayload() { platform = GetPlaform(0), audience = audience }; var notification = new Notification().setAlert(content); notification.AndroidNotification = androidNotification; notification.IosNotification = iosNotification; pushPayload.notification = notification.Check(); //pushPayload.message = Message.content(content); SendPush(appid, pushPayload); }
private void TimingJush(object o) { if (_j_time == null) { _j_time = new JushTiming_DAL(); } if (payload == null) { payload = new PushPayload(); } list = _j_time.PushTiming(); if (list.Count > 0) { foreach (var item in list) { long MessageID = 0; int ErrorCode = 0; switch (item.SendPlatform) { case 1: payload.platform = Platform.android(); break; case 2: payload.platform = Platform.ios(); break; case 3: payload.platform = Platform.android_ios(); break; default: break; } switch (item.SendAudience) { case 0: payload.audience = Audience.all(); break; case 1: string[] tagArray = item.AudienceName.Split(','); payload.audience = Audience.s_tag(tagArray); break; case 2: payload.audience = Audience.s_alias(item.AudienceName); break; case 3: payload.audience = Audience.s_registrationId(item.AudienceName); break; default: break; } string strJosn = item.Extras == null ? "" : item.Extras; if (strJosn.Length > 0) { data = strJosn.JsonToDocuments(); if (data.Count > 0) { android = new AndroidNotification(); ios = new IosNotification(); foreach (var tt in data) { android.AddExtra(tt.Key, tt.Value.ToString()); ios.AddExtra(tt.Key, tt.Value.ToString()); } } payload.notification = new Notification().setAlert(item.Content).setAndroid(android).setIos(ios); } else { payload.notification = new Notification().setAlert(item.Content); } try { var result = client.SendPush(payload); //由于统计数据并非非是即时的,所以等待一小段时间再执行下面的获取结果方法 System.Threading.Thread.Sleep(5000); MessageID = Convert.ToInt64(result.msg_id); //记录日志 Config.PushLogAPP("APP定时发送", "所有", item.Content); } catch (Jpush.api.common.APIRequestException ee) { MessageID = ee.MsgId; ErrorCode = ee.ErrorCode; string.Format("\r\n>>>APP定时发送 推送异常:{0},time:{1}", ee.Message, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") ).WriteLog("ERROR"); } _j_time.PushTimingUpdateStatu(MessageID, ErrorCode, item.Id); android = null; ios = null; } } }
public Notification setIos(IosNotification ios) { this.IosNotification = ios; return(this); }