向Apple APNS服务器发送推送通知 [英] Send push notification to Apple APNS server

查看:128
本文介绍了向Apple APNS服务器发送推送通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!



我想使用APNs服务器向我们的iOS移动客户端发送推送通知消息,但我收到的回复是无效设备令牌 APNs。



出了什么问题?



我有有效的认证和p12文件,我使用过我收到的设备令牌到我的iPhone。



这里有一些服务器代码:



我尝试过: < br $>


Hi !

I want to send a push notification message to our iOS mobile clients using APNs Server, but i get the response "invalid device token" back from the APNs.

What's going wrong ?

I have the valid certifications and p12 files, i used the device token i received to my iphone.

Here some server code:

What I have tried:

string certPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "nlcprod.p12");
                bool exist = File.Exists(certPath);
                var cert = File.ReadAllBytes(certPath);
                var appleSettings = new PushSharp.Apple.ApnsConfiguration(ApnsConfiguration.ApnsServerEnvironment.Production, cert, "");
                var pushBroker = new PushSharp.Apple.ApnsServiceBroker(appleSettings);

                pushBroker.OnNotificationFailed += (notification, aggregateEx) =>
                {
                    string strEx = aggregateEx.ToString();
                };
                pushBroker.OnNotificationSucceeded += PushBroker_OnNotificationSucceeded;
               // PushSharp.Apple.ApnsServiceConnection connection = new ApnsServiceConnection(appleSettings);

                JObject jObject = JObject.Parse(str);
                ApnsNotification apnsNotification = new ApnsNotification
                {
                    DeviceToken = "97056623 0caedd1c 0c96a264 f16cbf57 d9fa7236 08046144 6160ee95 94616364",
                    Payload = JObject.Parse("{\"aps\":{\"badge\":1,\"sound\":\"oven.caf\",\"alert\":\"testmessage\"}}")
                };

                //connection.Send(apnsNotification);
                pushBroker.Start();
                pushBroker.QueueNotification(apnsNotification);

推荐答案

我注意到两件事:



1.设备令牌不应有空格。尝试删除它们。



2.根据您的证书名称,您使用的是生产证书。这需要生产设备令牌,当您使用Ad-Hoc或AppStore配置文件构建应用程序时,您将获得该令牌。您使用的是开发资料吗?



如果没有,您可以共享代码来检索设备令牌吗?
There's two things I notice:

1. The device token shouldn't have spaces. Try remove them.

2. Based on the name of your certificates, you are using a production certificate. This requires a production device token, which you will get when your app is built with an Ad-Hoc or AppStore provisioning profile. Are you using a Development profile?

If not, can you share the code to retrieve the device token?


这篇关于向Apple APNS服务器发送推送通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆