个推只收到透传消息,收不到消息通知APNs

按照个推的文档一步一步坐下来,测试的时候,透传消息也能收到,就是收不到消息通知。对了好多遍文档,出错的原因要么就在证书配置,要么就在代码上。但证书也设置正确了,代码也全部对过没有问题。消息通知是通过苹果的APNs进行推送的,说明肯定是xcode的某个步骤出了问题,后来转念想想,试试用个推自带的例子配置试试,结果终于发现问题。xcode的build setting的设置,在个推的官方文档中提示的并不清晰,通过把code sign设置成自己的才终于收到消息通知了。好久没有碰过ios,感觉自己变成小白了。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
APNS(Apple Push Notification Service)是苹果公司提供的一种送服务,在移动应用开发中广泛应用。下面介绍如何使用C#实现APNS消息送。 首先,需要获取APNS送证书。具体步骤如下: 1. 登录苹果开发者中心,进入Certificates, Identifiers & Profiles页面。 2. 选择Identifiers选项卡,然后选择App IDs选项,找到你要送的App ID。 3. 点击Edit按钮,然后勾选Push Notifications选项,保存。 4. 选择Certificates选项卡,点击左下角的“+”按钮,选择“Apple Push Notification service SSL (Sandbox & Production)”选项,按照提示生成证书。 5. 下载证书并安装到电脑中。 接下来,使用第三方库完成APNS消息送。常用的库有apns-sharp、PushSharp等。这里以PushSharp为例。 1. 安装PushSharp库。可以通过NuGet安装,也可以从GitHub上下载源码编译。 2. 创建送服务对象。代码如下: ``` ApnsConfiguration config = new ApnsConfiguration(ApnsConfiguration.ApnsServerEnvironment.Production, "your_certificate_path", "your_certificate_password"); ApnsService service = new ApnsService(config); ``` 其中,第一个参数是环境类型,可以选择生产环境或者测试环境;第二个参数是证书路径;第三个参数是证书密码。 3. 创建消息对象。代码如下: ``` ApnsNotification notification = new ApnsNotification(DEVICE_TOKEN, new ApnsPayload("Hello, world!")); ``` 其中,第一个参数是设备的token;第二个参数是消息的内容。 4. 发送消息。代码如下: ``` service.QueueNotification(notification); service.Stop(); ``` 其中,QueueNotification方法用于将消息加入发送队列;Stop方法用于停止送服务。 完整代码示例: ``` using PushSharp; using PushSharp.Apple; using System; namespace APNSDemo { class Program { static void Main(string[] args) { ApnsConfiguration config = new ApnsConfiguration(ApnsConfiguration.ApnsServerEnvironment.Production, "your_certificate_path", "your_certificate_password"); ApnsService service = new ApnsService(config); string DEVICE_TOKEN = "your_device_token"; ApnsNotification notification = new ApnsNotification(DEVICE_TOKEN, new ApnsPayload("Hello, world!")); service.QueueNotification(notification); service.Stop(); Console.WriteLine("Push notification sent."); Console.ReadLine(); } } } ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值