Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/tfs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在互动通知ios的Push Sharp库中的APNS有效负载中添加类别_C#_Ios_Objective C_Apple Push Notifications_Pushsharp - Fatal编程技术网

C# 如何在互动通知ios的Push Sharp库中的APNS有效负载中添加类别

C# 如何在互动通知ios的Push Sharp库中的APNS有效负载中添加类别,c#,ios,objective-c,apple-push-notifications,pushsharp,C#,Ios,Objective C,Apple Push Notifications,Pushsharp,我正在使用库在ios中发送推送通知,它工作正常,但现在我想使用交互式通知,需要在APNS有效负载中添加“类别”。但我找不到任何方法。 请告诉我怎么做 谢谢。自PushSharp版本3以来,您必须自行构建有效负载。 我使用下面的代码来生成有效负载。它使用Newtonsoft.Json生成Json负载,包括“类别”: // // @(#) APNsDeviceToken.cs // // Project: usis Push Notification Router // System:

我正在使用库在ios中发送推送通知,它工作正常,但现在我想使用交互式通知,需要在APNS有效负载中添加“类别”。但我找不到任何方法。 请告诉我怎么做


谢谢。

自PushSharp版本3以来,您必须自行构建有效负载。 我使用下面的代码来生成有效负载。它使用Newtonsoft.Json生成Json负载,包括“类别”:

//
//  @(#) APNsDeviceToken.cs
//
//  Project:    usis Push Notification Router
//  System:     Microsoft Visual Studio 2015
//  Author:     Udo Schäfer

using System.Diagnostics.CodeAnalysis;
using Newtonsoft.Json;

namespace usis.PushNotification
{
    //  ----------------------
    //  APNsNotification class
    //  ----------------------

    /// <summary>
    /// Represents a notification that can be send to a device.
    /// </summary>

    public class APNsNotification
    {
        #region constants

        //  ---------------------
        //  DefaultSound constant
        //  ---------------------

        /// <summary>
        /// The name of the default sound file.
        /// </summary>

        public const string DefaultSound = "sound.caf";

        #endregion constants

        #region properties

        //  --------------
        //  Alert property
        //  --------------

        /// <summary>
        /// Gets or sets the alert message to display to the user.
        /// </summary>
        /// <value>
        /// The alert message to display to the user.
        /// </value>

        [JsonProperty(PropertyName = "alert", NullValueHandling = NullValueHandling.Ignore)]
        public string Alert { get; set; }

        //  --------------
        //  Badge property
        //  --------------

        /// <summary>
        /// Gets or sets the number to badge the app icon with.
        /// </summary>
        /// <value>
        /// The number to badge the app icon with.
        /// </value>

        [JsonProperty(PropertyName = "badge", NullValueHandling = NullValueHandling.Ignore)]
        public int? Badge { get; set; }

        //  --------------
        //  Sound property
        //  --------------

        /// <summary>
        /// Gets or sets the sound to play.
        /// </summary>
        /// <value>
        /// The sound to play.
        /// </value>

        [JsonProperty(PropertyName = "sound", NullValueHandling = NullValueHandling.Ignore)]
        public string Sound { get; set; }

        //  -------------------------
        //  ContentAvailable property
        //  -------------------------

        /// <summary>
        /// Gets or sets a value indicating whether new content is available.
        /// </summary>
        /// <value>
        ///   <c>true</c> if new content is available; otherwise, <c>false</c>.
        /// </value>

        [JsonProperty(PropertyName = "content-available", NullValueHandling = NullValueHandling.Ignore)]
        public bool ContentAvailable { get; set; }

        //  -----------------
        //  Category property
        //  -----------------

        /// <summary>
        /// Gets or sets a string value that represents the notification category.
        /// </summary>
        /// <value>
        /// A string value that represents the <c>identifier</c> property of the
        /// <c>UIMutableUserNotificationCategory</c> object you created to define custom actions.
        /// </value>

        [JsonProperty(PropertyName = "category", NullValueHandling = NullValueHandling.Ignore)]
        public string Category { get; set; }

        #endregion properties

        #region JsonWrapper class

        //  -----------------
        //  JsonWrapper class
        //  -----------------

        private class JsonWrapper
        {
            #region construction

            //  ------------
            //  construction
            //  ------------

            public JsonWrapper(APNsNotification aps) { Aps = aps; }

            #endregion construction

            #region properties

            //  ------------
            //  Aps property
            //  ------------

            [SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
            [JsonProperty(PropertyName = "aps")]
            public APNsNotification Aps { get; private set; }

            #endregion properties
        }

        #endregion JsonWrapper class

        #region overrides

        //  ---------------
        //  ToString method
        //  ---------------

        /// <summary>
        /// Returns a <see cref="string" /> that represents this instance.
        /// </summary>
        /// <returns>
        /// A <see cref="string" /> that represents this instance.
        /// </returns>

        public override string ToString()
        {
            return JsonConvert.SerializeObject(new JsonWrapper(this));
        }

        #endregion overrides
    }
}

// eof "APNsDeviceToken.cs"
//
//@(#)APNsDeviceToken.cs
//
//项目:usis推送通知路由器
//系统:Microsoft Visual Studio 2015
//作者:Udo Schäfer
使用System.Diagnostics.CodeAnalysis;
使用Newtonsoft.Json;
名称空间usis.PushNotification
{
//  ----------------------
//呼吸暂停类
//  ----------------------
/// 
///表示可以发送到设备的通知。
/// 
公共类窒息
{
#区域常数
//  ---------------------
//默认声音常数
//  ---------------------
/// 
///默认声音文件的名称。
/// 
public const string DefaultSound=“sound.caf”;
#端区常数
#区域属性
//  --------------
//警报属性
//  --------------
/// 
///获取或设置要显示给用户的警报消息。
/// 
/// 
///要向用户显示的警报消息。
/// 
[JsonProperty(PropertyName=“alert”,NullValueHandling=NullValueHandling.Ignore)]
公共字符串警报{get;set;}
//  --------------
//徽章属性
//  --------------
/// 
///获取或设置用于标记应用图标的编号。
/// 
/// 
///用于标记应用程序图标的编号。
/// 
[JsonProperty(PropertyName=“badge”,NullValueHandling=NullValueHandling.Ignore)]
公共int?徽章{get;set;}
//  --------------
//声音特性
//  --------------
/// 
///获取或设置要播放的声音。
/// 
/// 
///播放的声音。
/// 
[JsonProperty(PropertyName=“sound”,NullValueHandling=NullValueHandling.Ignore)]
公共字符串声音{get;set;}
//  -------------------------
//内容可用属性
//  -------------------------
/// 
///获取或设置一个值,该值指示新内容是否可用。
/// 
/// 
///如果新内容可用,则为true;否则为false。
/// 
[JsonProperty(PropertyName=“内容可用”,NullValueHandling=NullValueHandling.Ignore)]
公共bool ContentAvailable{get;set;}
//  -----------------
//类别属性
//  -----------------
/// 
///获取或设置表示通知类别的字符串值。
/// 
/// 
///表示的标识符属性的字符串值
///为定义自定义操作而创建的UIMutableUserNotificationCategory对象。
/// 
[JsonProperty(PropertyName=“category”,NullValueHandling=NullValueHandling.Ignore)]
公共字符串类别{get;set;}
#端域属性
#区域JsonWrapper类
//  -----------------
//JsonWrapper类
//  -----------------
私有类JsonWrapper
{
#区域建设
//  ------------
//建筑
//  ------------
公共JsonWrapper(APNsNotification aps){aps=aps;}
#端域构造
#区域属性
//  ------------
//Aps属性
//  ------------
[SuppressMessage(“Microsoft.Performance”、“CA1811:AvoidUncalledPrivateCode”)]
[JsonProperty(PropertyName=“aps”)]
公共apnsonification Aps{get;private set;}
#端域属性
}
#endregion JsonWrapper类
#区域覆盖
//  ---------------
//ToString方法
//  ---------------
/// 
///返回表示此实例的。
/// 
/// 
///表示此实例的。
/// 
公共重写字符串ToString()
{
返回JsonConvert.SerializeObject(新的JsonWrapper(this));
}
#端域覆盖
}
}
//eof“APNsDeviceToken.cs”

给我一些反馈,看看代码是否有用。

谢谢回复。我们已经在pushsharp图书馆自己做了这件事。这个答案应该对其他人有帮助。