【问题标题】:Xamarin.Forms - Toasts(Banners) - Alerts - in iOS and Android in BackgroundXamarin.Forms - Toasts(Banners) - 警报 - 在 iOS 和 Android 中在后台
【发布时间】:2016-05-01 17:19:29
【问题描述】:

我尝试在后台显示 toasts(banners) 通知。

我检查了后台获取和推送通知。当应用程序在前台时,我也收到了推送通知。

但是当我的应用在后台时 - 我只看到如何更改我的徽章计数 - 但我看不到通知

这是我的代码:

public override bool FinishedLaunching (UIApplication app, NSDictionary options)
        {

            global::Xamarin.Forms.Forms.Init ();
            LoadApplication (new App ());


            if (UIDevice.CurrentDevice.CheckSystemVersion (8, 0)) {
                var pushSettings = UIUserNotificationSettings.GetSettingsForTypes (
                    UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound,
                    new NSSet ());

                UIApplication.SharedApplication.RegisterUserNotificationSettings (pushSettings);
                UIApplication.SharedApplication.RegisterForRemoteNotifications ();
            } else {
                UIRemoteNotificationType notificationTypes = UIRemoteNotificationType.Alert | UIRemoteNotificationType.Badge | UIRemoteNotificationType.Sound;
                UIApplication.SharedApplication.RegisterForRemoteNotificationTypes (notificationTypes);
            }
            return base.FinishedLaunching (app, options);
        }

public override void ReceivedRemoteNotification(UIApplication application, NSDictionary userInfo)
        {

            NSDictionary dic = userInfo.ObjectForKey(new NSString("aps")) as NSDictionary;
            var test = (dic[new NSString("test")] as NSString).ToString();
            var alert = new UIAlertView ("Test title", "This is message", null, "Ok", "Button");
            alert.Clicked += (object sender, UIButtonEventArgs e) => {Console.WriteLine(e.ButtonIndex);};
            alert.Show ();
        }

所以我怎么说 - 在前台一切都很好,但在后台我只看到新的徽章数量。

我也找到了这个插件:

https://components.xamarin.com/view/alert-center

但我想了解如何在没有插件的情况下编写它。

谢谢。

【问题讨论】:

    标签: xamarin xamarin.ios xamarin.android xamarin.forms


    【解决方案1】:

    好的,我解决了!

    对于会遇到同样问题的开发者:

    我只是不将 aps json 中的 ALERT 对象发送到 ios。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-24
      • 2017-09-16
      • 2019-12-23
      • 1970-01-01
      • 2016-08-08
      • 1970-01-01
      相关资源
      最近更新 更多