特定消息使Push Sharp ApplePushService停止工作

本文关键字:Sharp ApplePushService 停止工作 Push 消息 | 更新日期: 2023-09-27 17:51:15

我正在使用push sharp实现推送通知,我有2种类型的消息,我正在发送推荐喜欢和NewFollower,我可以发送推荐喜欢的消息尽可能多,一切都很好,但发送单个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);
        }

NewFollower消息创建:

 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);
        }

第一个工作,第二个静默终止推送服务…

任何想法?

特定消息使Push Sharp ApplePushService停止工作

终于解决了…

问题在于生成的json字符串的长度。似乎最大值是255个字符。再高一点,它就会无声地失败…

小心。

Amit