【问题标题】:Push notifications from Azure Notification Hub (Xamarin.iOS)从 Azure 通知中心推送通知 (Xamarin.iOS)
【发布时间】:2018-04-28 07:49:37
【问题描述】:

我已经尝试过 Android 和 Windows 推送通知,一切正常。但是,在 iOS 端,有些问题。

我正在尝试使用这些教程向我的 Xamarin.iOS 应用添加推送通知

从 Azure 测试发送我得到“消息已成功发送,但没有匹配的目标。”

我已经按照原样执行了所有步骤,但是当我设置断点时,我总是得到“IsRegistered =false”:

AppDelegate.cs

private SBNotificationHub Hub { get; set; }
    public const string ConnectionString = "Endpoint=sb://...";
    public const string NotificationHubPath = "NotificationHubName...";


     public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
            {
                // Set our preferred notification settings for the app
                var pushSettings = UIUserNotificationSettings.GetSettingsForTypes(
                    UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound,
                    new NSSet());

                // Register for notifications
                UIApplication.SharedApplication.RegisterUserNotificationSettings(pushSettings);
                UIApplication.SharedApplication.RegisterForRemoteNotifications();
                bool IsRegistered = UIApplication.SharedApplication.IsRegisteredForRemoteNotifications;

                return true;
            }
public override void RegisteredForRemoteNotifications(UIApplication application, NSData deviceToken)
        {
            Hub = new SBNotificationHub(ConnectionString, NotificationHubPath);
            Hub.UnregisterAllAsync(deviceToken, (error) =>
            {
                if (error != null)
                {
                    // Error unregistering
                    return;
                }
                // Register this device with the notification hub
                Hub.RegisterNativeAsync(deviceToken, null, (registerError) =>
                {
                    if (registerError != null)
                    {
                        // Error registering
                    }
                });
            });
        }

        public override void ReceivedRemoteNotification(UIApplication application, NSDictionary userInfo)
        {
            if (null != userInfo && userInfo.ContainsKey(new NSString("aps")))
            {
                // Get the aps dictionary from the alert payload
                NSDictionary aps = userInfo.ObjectForKey(new NSString("aps")) as NSDictionary;
            }
        }

我的问题是;

  1. 为什么我没有注册?
  2. 我怎样才能知道我为什么不注册?
  3. Xamarin 是否支持来自 Azure 通知中心的 iOS 11.0 推送通知?

注意:我正在使用

  • Windows 10 上的 Visual Studio 2017(版本 15.4.0)
  • Mac OS High Siera 版本 10.13
  • Xcode 版本 9.0.1
  • VS for Mac Community 版本 7.2(内部版本 636)
  • 在 iPhone 5S、iPhone 6、iPhone 6S、iPhone 7、iPhone 8 - iOS11.0 上测试

【问题讨论】:

  • 显示RegisteredForRemoteNotifications方法中的代码。你在那里的通知中心注册了吗?
  • 我已在问题中添加了 RegisteredForRemoteNotifications 方法。
  • 你有没有使用断点查看结果是什么?很有可能永远不会向 Azure 进行注册。但是没有对错误做任何事情,所以你不会知道
  • 是的,我使用断点查看结果。 IsRegistered 始终为假。我再次检查了 Azure 中的 ConnectionString 和 NotificationHubName,并且与我项目中的字段相同。

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


【解决方案1】:

使用物理 iPhone 设备解决了这个问题。

“模拟器不执行推送通知。要从服务器推送,您必须拥有要推送到的设备以及该设备上的应用程序。”


“iPhone 模拟器无法接收推送通知或成功注册。”

【讨论】:

    猜你喜欢
    • 2017-06-05
    • 2017-08-29
    • 1970-01-01
    • 2019-08-25
    • 2015-12-11
    • 2021-08-03
    • 1970-01-01
    • 1970-01-01
    • 2016-12-11
    相关资源
    最近更新 更多