Xamarin.ios Xamarin IOS-UserInfo自定义数据字典始终为空

Xamarin.ios Xamarin IOS-UserInfo自定义数据字典始终为空,xamarin.ios,localnotification,userinfo,Xamarin.ios,Localnotification,Userinfo,下面的方法显示了如何创建通知。我在UserInfo字典中添加了一个新项 private UNNotificationRequest CreateNotification(Geofence geofence) { var content = new UNMutableNotificationContent(); content.Title = "title"; content.Subtitle = "subtitle&q

下面的方法显示了如何创建通知。我在
UserInfo
字典中添加了一个新项

private UNNotificationRequest CreateNotification(Geofence geofence)
{
        var content = new UNMutableNotificationContent();
        content.Title = "title";
        content.Subtitle = "subtitle";
        content.Body = "This is the message body of the notification.";
        content.Badge = 2;

        content.UserInfo.Append(new KeyValuePair<NSObject, NSObject>((NSString)"id", (NSString)"bla"));

        var trigger = UNTimeIntervalNotificationTrigger.CreateTrigger(1, false);

        var request = UNNotificationRequest.FromIdentifier("test1", content, trigger);
        return request;
}

UserInfo
字典始终为空。这是为什么?我如何解决这个问题?

您需要在switch语句中获取逻辑

public override void DidReceiveNotificationResponse(UNUserNotificationCenter center, UNNotificationResponse response, Action completionHandler)
    {   
        // Take action based on Action ID
        switch (response.ActionIdentifier)
        {
            case "reply":
                // Do something
                break;
            default:
                // Take action based on identifier
                if (response.IsDefaultAction)
                {
                    // Handle default action...
                    var item = response.Notification.Request.Content.UserInfo;
                }
                else if (response.IsDismissAction)
                {
                    // Handle dismiss action
                }
                break;
        }

        // Inform caller it has been handled
        completionHandler();
    }
更新 您似乎以错误的方式添加了用户信息。检查以下代码

content.UserInfo = NSDictionary.FromObjectAndKey(new KeyValuePair<NSObject, NSObject>((NSString)"id", (NSString)"bla"));
content.UserInfo=NSDictionary.FromObjectAndKey(新的KeyValuePair((NSString)“id”,(NSString)“bla”);

True,但它不会改变字典为空的事实。还是会?如果是,为什么。。
content.UserInfo = NSDictionary.FromObjectAndKey(new KeyValuePair<NSObject, NSObject>((NSString)"id", (NSString)"bla"));