Question

I am implementing push notifications using push sharp and I have 2 types of messages I am sending RecomendationLiked and NewFollower, I can send RecomendationLiked messages as much as I want and everything works fine but sending a single NewFollower message simpley causes the service to stop responding with no exception, or any of the events called. This happens both in Production and in Development environment

Here is the service creation logic:

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

RecomendationLiked message creation:

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 message creation:

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

The first one works, the second kills the push service silently...

Any ideas?

Was it helpful?

Solution

Solved it finally...

The issue is with the length of the json string that is generated. it seems that the maximum is 255 chars. anything higher and it fails silently...

beware.

Amit

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top