从Azure Notification Hub推送通知(Xamarin.iOS)

时间:2017-11-15 07:14:13

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

我尝试过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 Notification Hub的iOS 11.0推送通知?
  4. 注意:我正在使用

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

1 个答案:

答案 0 :(得分:0)

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

  

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

  

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

enter image description here