【问题标题】:azure notification issue: apns works while template not response天蓝色通知问题:apns 工作,而模板没有响应
【发布时间】:2018-09-20 22:28:28
【问题描述】:

按照本教程 "Add push notifications to your Xamarin.Forms app" 进行 Xamarin.Forms 开发。在 Azure 后端和 iOS 中插入通知代码后,通知模板发出但设备上没有警报。但是,APNS 的测试发送会在设备上显示警报。感谢任何建议。

这是我的 RegisteredForRemoteNotifications

public override void RegisteredForRemoteNotifications(UIApplication application, NSData deviceToken)
    {

        const string templateBodyAPNS = "{\"aps\":{\"alert\":\"$(message)\"}}";

        JObject templates = new JObject();
        templates["genericMessage"] = new JObject
        {
            {"body", templateBodyAPNS}
        };

        /*
        // Register for push with your mobile app
        Push push = TodoItemManager.DefaultManager.CurrentClient.GetPush();
        try
        {
            push.RegisterAsync(deviceToken, templates);
        }
        catch (System.Exception ex)
        {
            Debug.WriteLine(@"Register error: {0}", ex.Message);
        }
        */


        Hub = new SBNotificationHub(Constants.ConnectionString, Constants.NotificationHubName);

        Hub.UnregisterAllAsync(deviceToken, (error) => {
            if (error != null)
            {
                Console.WriteLine("Error calling Unregister: {0}", error.ToString());
                return;
            }

            NSSet tags = new NSSet(); // create tags if you want
            var expire = DateTime.Now.AddDays(90).ToString(); // set expire
            try
            {
                //register native notification
                Hub.RegisterNativeAsync(deviceToken, tags, (errorCallback) =>
                {
                    if (errorCallback != null)
                        Console.WriteLine("RegisterNativeAsync error: " + errorCallback.ToString());
                });

                //register template notification
                Hub.RegisterTemplateAsync(deviceToken, "add_newbook_notification", templateBodyAPNS, expire, tags, (errorCallback) => {
                    if (errorCallback != null)
                        Console.WriteLine("RegisterNativeAsync error: " + errorCallback.ToString());
                });
            }
            catch (System.Exception ex)
            {
                Debug.WriteLine(@"Register error: {0}", ex.Message);
            }
        });
    }

因为在一个客户端应用程序中可能有多个通知注册,理论上本地和模板通知注册都应该在这里成功。但是,我只收到 APNS,但没有收到模板。

【问题讨论】:

  • 以下是一些需要检查的常见错误配置: 确保您的通知中心名称(没有拼写错误)在每个位置都相同: 您从客户端注册的位置。您从后端发送通知的位置。您配置推送通知服务凭证的位置。另外,请参阅此文档:docs.microsoft.com/en-us/azure/notification-hubs/…,其中描述了“诊断通知中心中丢弃的通知”。您将找到更多诊断问题的选项。
  • 感谢@Swikiruti 的建议。实际上,我自己检查了那些文档,但在问这里之前没有任何想法。

标签: xamarin.forms apple-push-notifications azure-mobile-services azure-notificationhub


【解决方案1】:

Azure Messaging - RegisterTemplateAsync isn't working? 这个链接解决了我的问题。

注意

问题是我不清楚这个 ExpiryTemplate。我确实在那个文档上找到了任何文档,但显然,它是 DateTime 格式的 作为我们。

到期日期时间必须格式化为 en-us。否则,RegisterTemplateAsync 无法工作。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-09-21
    • 2019-09-28
    • 2021-03-11
    • 2015-09-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多