0

我正在使用 push sharp 实现推送通知,我有 2 种类型的消息我正在发送 RecomendationLiked 和 NewFollower,我可以尽可能多地发送 RecomendationLiked 消息,一切正常,但发送单个 NewFollower 消息会导致服务停止响应也不例外,或者调用任何事件。这发生在生产环境和开发环境中

这是服务创建逻辑:

private void InitApplePushService()
        {
            try
            {

                string appDataPath = HttpContext.Current.Server.MapPath("~/app_data");
                //***** Development Server *****//
                string file = Path.Combine(appDataPath, "PushSharp.PushCert.Development.p12");
                var appleCert = File.ReadAllBytes(file);                  
                _applePushService = new ApplePushService(new ApplePushChannelSettings(false, appleCert, "XXX"));

                _applePushService.OnChannelCreated += OnChannelCreated;
                _applePushService.OnChannelDestroyed += OnChannelDestroyed;
                _applePushService.OnChannelException += OnChannelException;
                _applePushService.OnDeviceSubscriptionChanged += OnDeciveSubscriptionChanged;
                _applePushService.OnDeviceSubscriptionExpired += OnDeviceSubscriptionExpired;
                _applePushService.OnNotificationFailed += OnNorificationFailed;
                _applePushService.OnNotificationRequeue += OnNotificationQueued;
                _applePushService.OnNotificationSent += OnNOtificationSend;
                _applePushService.OnServiceException += OnServiceException;
                Trace.TraceInformation("ApplePushService initialized succesfully");
            }
            catch (Exception e)
            {
                Trace.TraceError("Error initializing ApplePushService : " + e);
                throw;
            }
        }

推荐喜欢的消息创建:

private void SendRecomendationLikedMessageToAppleDevice(User likingUser, Recomendation recomendation)
        {
            var notification = new AppleNotification();
            notification.DeviceToken = recomendation.User.PushNotificationID;               
            notification.Payload.Alert.LocalizedKey = "NewLikeNotification";
            notification.Payload.Alert.LocalizedArgs = new List<object> { likingUser.NickName };
            notification.Payload.Sound = "default";
            notification.Payload.AddCustom("LikingUser", likingUser.NickName);
            notification.Payload.AddCustom("AlertType", "RecomendationLiked");
            notification.Payload.AddCustom("ID", likingUser.ID);
            notification.Payload.AddCustom("ImageUrl", likingUser.ImageUrl);
             _applePushService.QueueNotification(notification);
        }

NewFollow 消息创建:

 private void SendNewFollowingUserMessageToAppleDevice(User followingUser, User followedUser)
        {
            var notification = new AppleNotification();
            notification.DeviceToken = followedUser.PushNotificationID;
            notification.Payload.Alert.LocalizedKey = "NewFollowingUserNotification";
            notification.Payload.Alert.LocalizedArgs = new List<object> { followingUser.NickName };
            notification.Payload.Sound = "default";
            notification.Payload.AddCustom("followingUser", followingUser.NickName);
            notification.Payload.AddCustom("AlertType", "NewFollowingUser");
            notification.Payload.AddCustom("ID", followingUser.ID);
            notification.Payload.AddCustom("ImageUrl", followingUser.ImageUrl);
            Trace.TraceInformation("Trying to send notifications: "+ notification);
            _applePushService.QueueNotification(notification);
            //_pushService.QueueNotification(notification);
        }

第一个工作,第二个默默地杀死推送服务......

有任何想法吗?

4

1 回答 1

0

终于解决了...

问题在于生成的 json 字符串的长度。似乎最大值是 255 个字符。任何更高的东西,它都会默默地失败......

谨防。

阿米特

于 2014-05-22T13:26:23.083 回答