1

My application is easily receiving less then 256 bytes in Push Notifications but as for iOS 8 it is capable of receiving 2K payload in Push Notifications, I am unable to receive that.

On server side i am using Asp.net and Following is my payload:

{"aps":{"alert":"ASD SAD SA DAS DSDSADSAD E36DCB20B9497BB75BE6BF0C47718C73E8D80A6B734F296BD768DC5C4DB261BCE36DCB20B9497BB75BE6BF0C47718C73E8D80Assdds","id":"5","type":"n","sound":"default","category":"1"}}

I am using iPhone 5S with iOS 8.1 for testing.

On iOS side i am using the below code

UIApplication *application = [UIApplication sharedApplication];
if ([application respondsToSelector:@selector(registerUserNotificationSettings:)])
{
    UIUserNotificationType userNotificationTypes = (UIUserNotificationTypeAlert |
                                                    UIUserNotificationTypeBadge |
                                                    UIUserNotificationTypeSound);
    UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:userNotificationTypes categories:nil];
    [application registerUserNotificationSettings:settings];
    [application registerForRemoteNotifications];
}
else
{
    // Register for Push Notifications before iOS 8
    [application registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge |
                                                     UIRemoteNotificationTypeAlert |
                                                     UIRemoteNotificationTypeSound)];
}
Shahid Aslam
  • 2,585
  • 3
  • 24
  • 31
  • How are you sending the push? Perhaps the sending server is limiting the push to 256 bytes as that was the pre-8 limit – Paulw11 Jan 15 '15 at 10:23
  • I am not sure for the sending server limit settings, but i have created the payload for less then 256 and greater then 256 and both send smoothly but not received larger then 256 on device. – Shahid Aslam Jan 15 '15 at 10:28
  • The server could have code that trims the payload to 256 (or silently discards it - I am not sure what you are getting on the device) – Paulw11 Jan 15 '15 at 10:29
  • Please check http://stackoverflow.com/questions/25909568/ios-8-enabled-device-not-receiving-push-notifications-after-code-update – Girijesh Kumar Jan 15 '15 at 12:56

2 Answers2

1

I had the same problem with my iPhone, running 8.3 of iOS. Could only receive payload data up to 256 bytes.

The cause to the problem was that the php script (something I found on internet and didn't write myself) that I used to push the notification has a bug in it. When it store the length of payload data, it only uses one byte (so maximum size can never be greater than 255). I think I used the simple push script that comes from raywanderlich's tutorial about APNS (which was written for iOS 6).

This didn't work: . chr(0) . chr(32) . pack('H*', $deviceToken[ $i ] ) . chr(0) . chr(strlen($payload)) . $payload;

This works great: . pack( 'n', 32 ) . pack('H*', $deviceToken[ $i ] ) . pack( 'n', strlen($payload)) . $payload;

So what happens in my case is that $payload contains 379 characters of data, strlen returns 379 but stores it in one byte so the result wraps around 256 and becomes 123 (379-256). My scripts sends the payload to APNS but it looks like APNS doesn't push it out to the device when message length doesn't correspond with the actual content.

So check how you calculate the length of the payload and how you store it in the message.

Good luck /Jocke

Jocke
  • 41
  • 3
0

Please ensure that in iOS 8 there are some changes in Remote notification Registration.

Ex :

    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)
{
    [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
    [[UIApplication sharedApplication] registerForRemoteNotifications];
}
else
{
    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:
     (UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert)];
}

Please check whether you are using this way or not.

Nishant Tyagi
  • 9,893
  • 3
  • 40
  • 61