0

我需要在iOS中的本地通知中顯示動作按鈕。我收到通知,但沒有任何操作按鈕。你能指導我做錯了什麼嗎? 這是我的代碼:Xamarin形成iOS本地通知按鈕

 var category = new UIMutableUserNotificationCategory(); 

     var okAction = new UIMutableUserNotificationAction 
     { 
      Identifier = "ok", 
      Destructive = false, 
      Title = "OK", 
      ActivationMode = UIUserNotificationActivationMode.Background, 
      AuthenticationRequired = false 
     }; 

     var delayAction = new UIMutableUserNotificationAction 
     { 
      Identifier = "delay", 
      Destructive = false, 
      Title = "Отложить", 
      ActivationMode = UIUserNotificationActivationMode.Background, 
      AuthenticationRequired = false 
     }; 

     var categoryIdentifier = "pills.category"; 
     category.Identifier = categoryIdentifier; 
     category.SetActions(new UIUserNotificationAction[] { delayAction, okAction }, UIUserNotificationActionContext.Minimal); 
     category.SetActions(new UIUserNotificationAction[] { delayAction, okAction }, UIUserNotificationActionContext.Default); 

     var categories = new NSSet(new NSObject[] {category}); 

     var notificationSettings = UIUserNotificationSettings.GetSettingsForTypes(
      UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound, categories 
     ); 
     UIApplication.SharedApplication.RegisterUserNotificationSettings(notificationSettings); 


     var next = new TimeSpan(start.Ticks); 

     var count = Math.Round(24.0/interval.TotalHours); 

     for (int i = 0; i < count; i++) 
     { 
      var notification = new UILocalNotification 
      { 
       AlertAction = title, 
       AlertBody = text, 
       SoundName = UILocalNotification.DefaultSoundName, 
       ApplicationIconBadgeNumber = 0, 
       FireDate = NSDate.FromTimeIntervalSinceNow(next.TotalSeconds), 
       RepeatInterval = NSCalendarUnit.Day, 
       Category = categoryIdentifier 
      }; 
      UIApplication.SharedApplication.ScheduleLocalNotification(notification); 

      next = next.Add(interval); 
     } 
    } 

P.S.我正在使用iOS 11模擬器。

回答

0

您需要向下滑動以查看按鈕。

下GIF演示如何Background操作和Lock Screen

enter image description here