iT邦幫忙

1

APNs錯誤詢問

foreach(var row in data.rows)
{

var url = string.Format("https://{0}:{1}/3/device/{2}", apnsHost, APNS_API_PORT, row.token); 
using (var request = new HttpRequestMessage(HttpMethod.Post, url))
{
    accessToken = tools.CreateToken(p8CertInfo,certDetail.send_key);
    request.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", accessToken);
    request.Headers.TryAddWithoutValidation("apns-push-type", "alert");
    request.Headers.TryAddWithoutValidation("apns-id", Guid.NewGuid().ToString("D"));
    request.Headers.TryAddWithoutValidation("apns-expiration", Convert.ToString(0));
    request.Headers.TryAddWithoutValidation("apns-priority", Convert.ToString(10));
    request.Headers.TryAddWithoutValidation("apns-topic", p8CertInfo.bundle_id);

    request.Content = new ByteArrayContent(payload);
    request.Version = HttpVersion.Version20;

    try
    {
        using (var httpResponseMessage = _client.SendAsync(request).GetAwaiter().GetResult())
        {
            string statusCode = httpResponseMessage.StatusCode.ToString(); 
            if (httpResponseMessage.IsSuccessStatusCode)
            {
 ...
            }
            else
            {
...
            }
        }
    }
    catch (Exception ex)
    {

    }

}

}

想請問 一開始發送都是正常的,但後續就會開始出現status Code : 429 , reason : TooManyProviderTokenUpdates
google之後本以為是token失效,但已在每次發送前都重新產生新的token,時戳應該是不會失效的才對
想問問程式碼是否有哪裡需要調整ˊˋ?

看更多先前的討論...收起先前的討論...
cshalove iT邦新手 4 級 ‧ 2020-05-27 15:20:17 檢舉
status Code : 429 , reason : TooManyProviderTokenUpdates
這一段錯誤應該是
The provider’s authentication token is being updated too often. Update the authentication token no more than once every 20 minutes.

authentication token 更換太頻繁導致錯誤
ice bear iT邦新手 4 級 ‧ 2020-05-27 15:26:13 檢舉
HI大大你好
我試過不更新token,錯誤依舊QQ
cshalove iT邦新手 4 級 ‧ 2020-05-27 15:35:59 檢舉
照文件說,等20分鐘後 重新產一個auth token 在發送看看囉,若是不行我也沒辦法,哈哈,現在都沒再用APNs發送推播
不然就改用 APNs憑證方式發送,不要用APNs金鑰 (測試期間)
正式上線後再改用APNs金鑰

憑證缺點就是每年都要更新,金鑰則不用
ice bear iT邦新手 4 級 ‧ 2020-05-27 17:46:25 檢舉
大大你好!! 後來發現真的小於20分鐘會更新一次,時間固定20分鐘後才重新產生token便沒有出現那個錯誤了,謝謝!!
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 個回答

2
海綿寶寶
iT邦大神 1 級 ‧ 2020-05-27 10:33:19

根據這篇的說法

原因:在短時間重覆大量發送推播至相同 deviceToken
解法(原文照抄):

If you have a way to check your code, verify that your device tokens being sent in the requests are unique.

Make sure your code does not have a repetition loop in there whch might be sending multiple requests to each device.

另外提一下
如果不是為了練功或特殊原因
建議使用 Google Firebase 發推播

ice bear iT邦新手 4 級 ‧ 2020-05-27 10:40:49 檢舉

HI 海綿寶寶 大大你好
這篇我也有查到,所以我有看了資料,我是隨機產生大量的資料,token用的是GUID()應該是不會有重複的device token,我預期應該會收到BadDeviceToken,因為token確實是無效的
紀錄的Log大致如下,token是沒有重複的
https://ithelp.ithome.com.tw/upload/images/20200527/20120596tVYbb2pSBe.png

確實有特殊原因非用APNs不可...ˊˋ

我要發表回答

立即登入回答