簡體   English   中英

從Android進行Azure通知中心注冊

[英]Azure Notification Hub Registration from Android

當我閱讀個人用戶通過我的Android應用發送的電子郵件時,我嘗試向其發送帶有“已讀電子郵件”文本的推送通知。

我通過SendGrid API發送電子郵件,並且已設置一個Azure Function webhook終結點,該終結點在讀取電子郵件時會被調用。

我可以將Notification Hub注冊ID和GCM令牌附加到電子郵件中,並通過Webhook傳遞回給我。

有了GCM令牌,我知道要將通知發送到的設備/個人,我現在面臨的挑戰是如何調用Azure Notification Hub來針對單個用戶?

當前,Azure Function僅支持將Notification Hub與模板綁定,這給我帶來了又一個挑戰,如何使用安裝從Android設備注冊Azure Notification Hub?

我自己還沒有嘗試過,但是我認為這是您需要的:

有關安裝模型的更多信息,請參考注冊管理文章。

@Nikita G.總體上正確引導。

我想附加實施級別的知識。

每個用戶都可以通過Notification Hub中的tag進行管理,因為用戶可以使用多個設備。 Azure Notification Hub標記系統適合在這種情況下發送推送。 因此,您可以附加一個類似於user:34939的標簽來標識用戶(而不是標識設備)。

因此,您應該認為您的要求是識別device或識別user 無論哪種情況,都不必將GCM令牌附加到電子郵件鏈接。 僅標記值(用戶標識)足以標識用戶,或者僅集線器注冊標識足以標識設備。 集線器注冊ID有助於管理注冊的設備,而不考慮APNS或GCM令牌。

關於模板,是的。 注冊期間需要模板。

僅供參考,標簽有120個字符長度限制。 https://stackoverflow.com/a/21199385/361100

NotificationHub中的tagExpression是動態的。 有關更多詳細信息,請參見為Azure功能配置通知標記 此外,Azure功能現在支持向GCM注冊發送通知。 您需要在“綁定到GCM”上設置“通知平台”。

這是用於將WNS推送通知發送到作為queueTrigger出現的動態標簽的示例:

function.json

{
  "bindings": [
   {
     "name": "myQueueItem",
      "type": "queueTrigger",
      "direction": "in",
      "queueName": "test-queue",
      "connection": "AzureWebJobsDashboard"
    },
    {
       "type": "notificationHub",
       "name": "notification",
       "hubName": "youthubname",
       "connection": "NOTIFICATIONHUB_AppSettingName",
       "direction": "out",
       "tagExpression": "{userIdTag}",
       "platform": "wns"
     }
   ],
   "disabled": false
}

C#QueueTrigger:

using System;

public static void Run(PushToTag myQueueItem, TraceWriter log, out string    notification)
{
    log.Info($"C# Queue trigger function processed: {myQueueItem.UserIdTag}");
    notification = "<toast><visual><binding template=\"ToastText01\"><text  id=\"1\">Test message</text></binding></visual></toast>";
}

public class PushToTag
{
     public string UserIdTag { get; set; }
     public string UserName { get; set; }
}

樣本隊列數據

{"UserIdTag":"tag1" , "UserName":"joe"}

注意:tag1是客戶端注冊的標簽

您可以通過在Notification Platform中選擇GCM來發送GCM通知。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM