2015-01-15 47 views
0

我的應用程序很容易在推送通知中接收少於256字節,但對於iOS 8,它能夠在推送通知中接收2K有效負載,我無法接收該消息。不接收推送通知大於256字節iOS 8

在我使用Asp.net及以下服務器端是我的有效載荷:

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

我使用iPhone 5S與iOS 8.1進行測試。

在iOS端我使用下面的代碼

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)]; 
} 
+0

你是如何發送推?也許發送服務器限制推送到256字節,因爲這是前8限制 – Paulw11

+0

我不確定發送服務器的限制設置,但我已經創建有效載荷小於256和更大,然後256並且都發送平穩但設備上未收到大於256的數據。 –

+0

服務器可能有代碼將有效負載修剪爲256(或者默默丟棄它 - 我不確定你在設備上獲得什麼) – Paulw11

回答

0

請確保在iOS的8有遠程通知註冊了一些變化。

例:

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

請檢查您是否使用這種方法還是不行。

+0

是Nishant謝謝你的回答,但我用上面的代碼,我會更新我的問題。 –

1

我的iPhone有同樣的問題,運行8.3的iOS。只能接收高達256字節的有效載荷數據。

導致問題的原因是我用來推送通知的php腳本(我在互聯網上找到的東西並沒有自己寫的東西)有一個bug。當它存儲有效載荷數據的長度時,它只使用一個字節(所以最大尺寸不能大於255)。我想我使用了來自raywanderlich關於APNS(這是爲iOS 6編寫的)的教程的簡單推送腳本。

這沒有奏效: 。 chr(0)。 chr(32)。包('H *',$ deviceToken [$ i])。 chr(0)。 chr(strlen($ payload))。 $有效載荷;

這很好用: 。包('n',32)。包('H *',$ deviceToken [$ i])。 pack('n',strlen($ payload))。 $有效載荷;

因此,在我的情況下發生的是,$ payload包含379個字符的數據,strlen返回379,但將其存儲在一個字節中,因此結果包裝爲256並變爲123(379-256)。我的腳本將有效載荷發送給APNS,但是當消息長度與實際內容不符時,​​它看起來像APNS不會將它推送到設備。

因此,請檢查您如何計算有效負載的長度以及如何將其存儲在消息中。

祝你好運/ Jocke