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

Posted

技术标签:

【中文标题】特定消息使 Push Sharp ApplePushService 停止工作【英文标题】:Specific message makes Push Sharp ApplePushService stop working 【发布时间】:2014-03-20 18:19:47 【问题描述】:

我正在使用 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);
        

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

第一个有效,第二个静默杀死推送服务......

有什么想法吗?

【问题讨论】:

【参考方案1】:

终于解决了……

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

小心。

阿米特

【讨论】:

以上是关于特定消息使 Push Sharp ApplePushService 停止工作的主要内容,如果未能解决你的问题,请参考以下文章

使用 Push-Sharp 库将 Json 发送到 APNS

Push sharp - 已达到最大发送尝试次数

Push sharp call back 成功但没有收到通知?

如何为Android GCM(Pushnotification)集成Push sharp?

如何使用适用于 Android 的 Push sharp 库一次发送多个推送通知?

如何在 windows phone 8 中使用 push Sharp 发送带有参数的磁贴通知