【问题标题】:Xamarin Forms IOS with Azure Notification HubXamarin Forms IOS 与 Azure 通知中心
【发布时间】:2020-06-01 02:52:33
【问题描述】:

我知道这个问题被问了多次。所以请耐心等待。

我正在尝试使用 Xamarin Forms 与我的 Android/iOS 客户端实现 Azure 通知中心。

对于 Android,一切正常,但对于 iOS,我没有收到任何通知。

这是我为 iOS 所做的清单

  1. 生成证书和配置文件
  2. 在 MacOS 上注册了证书
  3. 导出 p12 文件并导入 Azure Hub
  4. 我还在 Info.plist 中添加了权限(后台远程通知)
  5. Entitlements.plist 文件中没有更改
  6. 我能够从 APN 服务获取设备令牌
  7. 我可以在获得 Token 后注册到 Azure Hub

但我无法收到任何通知,也没有调用任何函数(DidRegisterUserNotificationSettings,WillPresentNotification,ReceivedRemoteNotification,DidRegisterUserNotificationSettings,FailedToRegisterForRemoteNotifications,DidReceiveRemoteNotification)

但是RegisteredForRemoteNotifications被调用了

我还测试了 devicetoken 是否删除了 '<> ',但没有成功。

可能是什么问题?

这是我的代码

 public override void RegisteredForRemoteNotifications(UIApplication application, NSData deviceToken)
        {
            GlobalVariables.Instance.PnsToken = deviceToken.Description
                                 .Replace("<", string.Empty)
                                 .Replace(">", string.Empty)
                                 .Replace(" ", string.Empty)
                                 .ToUpper();
            RegisteredForHub(application, deviceToken);
        }

        public void RegisteredForHub(UIApplication application, NSData deviceToken)
        {
            string pnsHandle = deviceToken.Description
                                 .Replace("<", string.Empty)
                                 .Replace(">", string.Empty)
                                 .Replace(" ", string.Empty)
                                 .ToUpper();
            _hub = new SBNotificationHub(Constant.ListenConnectionString, Constant.NotificationHubName);

            _hub.UnregisterNative((error) =>
            {
                if (error != null)
                {
                    Debug.WriteLine($"Unable to call unregister Native {error}");
                }
            });
            _hub.UnregisterTemplate("defaultTemplate",(error) =>
            {
                if (error != null)
                {
                    Debug.WriteLine($"Unable to call unregister Template {error}");
                }
            });
            // update registration with Azure Notification Hub
            _hub.UnregisterAll(deviceToken, (error) =>
            {
                if (error != null)
                {
                    Debug.WriteLine($"Unable to call unregister {error}");
                    return;
                }

                var tags = new NSSet(Constant.SubscribeTags);
                _hub.RegisterNative(pnsHandle, tags, (errorCallback) =>
                {
                    if (errorCallback != null)
                    {
                        Debug.WriteLine($"RegisterNativeAsync error: {errorCallback}");
                    }
                });
                var templateExpiration = DateTime.Now.AddDays(120)
                    .ToString(System.Globalization.CultureInfo.CreateSpecificCulture("en-US"));
                //_hub.RegisterTemplate(deviceToken, "defaultTemplate", Constant.ApnTemplateBody, templateExpiration,
                //    tags, (errorCallback) =>
                //    {
                //        if (errorCallback != null)
                //        {
                //            Debug.WriteLine($"RegisterTemplateAsync error: {errorCallback}");
                //        }
                //    });
            });

【问题讨论】:

    标签: azure xamarin.forms xamarin.ios apple-push-notifications


    【解决方案1】:

    经过大量的试验和错误以及在谷歌上搜索了这么多小时。我发现问题出在 Azure。

    我上传了正确的证书,但密码是一个字符,因此没有发送任何通知。

    如果用户为其证书文件输入了错误的密码,Azure 应提示用户输入 APN。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-08-16
      • 2017-02-22
      • 2017-05-23
      • 2017-03-01
      • 1970-01-01
      • 2018-04-30
      • 1970-01-01
      相关资源
      最近更新 更多