Exemplo n.º 1
0
        private void ShowNotification(string title, string message)
        {
            //var alert = new UIAlertView(title ?? "Title", message ?? "Message", null, "Cancel", "OK");
            //alert.Show();

            InvokeOnMainThread(() => {
                if (UIDevice.CurrentDevice.CheckSystemVersion(10, 0))
                {
                    var content = new UNMutableNotificationContent {
                        Title    = title,
                        Subtitle = message,
                        Sound    = UNNotificationSound.Default,
                        Badge    = 0
                    };
                    NSObject objTrue = new NSNumber(true);
                    NSString key     = new NSString("shouldAlwaysAlertWhileAppIsForeground");
                    content.SetValueForKey(objTrue, key);
                    key = new NSString("shouldAddToNotificationsList");
                    content.SetValueForKey(objTrue, key);

                    var trigger = UNTimeIntervalNotificationTrigger.CreateTrigger(2, false);
                    var request = UNNotificationRequest.FromIdentifier(genericNotification, content, trigger);

                    UNUserNotificationCenter.Current.AddNotificationRequest(request, (err) => {
                        if (err != null)
                        {
                            Console.WriteLine("Error: " + err.LocalizedDescription);
                        }
                    });
                }
            });
        }