标签: pushsharp

如何在Xamarin表单中使用推送通知

我有一个使用Xamarin.Forms的应用程序,目标是IOS,Android和WP 8.

我的应用程序中需要推送通知功能.

我看过pushsharp演示,看起来很有希望.但我见过的所有代码都是针对每个平台单独完成的.

我希望它可以在App.cs中的某个Xamarin.Forms项目中完成,这样我就不需要重复注册设备的代码,并处理如何处理推送通知.

任何帮助将不胜感激.欢迎提供示例代码或教程参考.

编辑:我是根据Idot的回答实现的.这是我的答案的链接.

c# push-notification xamarin pushsharp xamarin.forms

55
推荐指数
2
解决办法
6万
查看次数

PushSharp APNS生产:提供给包的凭据无法识别(开发工作正常)

我的应用程序刚刚在App Store上销售,但我的生产设备(从App Store安装了应用程序的设备)都没有获得推送通知.当我尝试向生产设备发送推送通知时,我收到此错误:

"The credentials supplied to the package were not recognized" 
(System.ComponentModel.Win32Exception)
Run Code Online (Sandbox Code Playgroud)

内部抛出此异常并陷入无限循环:

在此输入图像描述

它被抛出ApplePushChannel.cs文件的第539行:

    try
{
    stream.AuthenticateAsClient(this.appleSettings.Host, this.certificates, 
        System.Security.Authentication.SslProtocols.Ssl3, false);
    //stream.AuthenticateAsClient(this.appleSettings.Host);
}
catch (System.Security.Authentication.AuthenticationException ex)
{
    throw new ConnectionFailureException("SSL Stream Failed to Authenticate as Client", ex);
}
Run Code Online (Sandbox Code Playgroud)

这是Visual Studio输出中应用程序的输出:

...
A first chance exception of type 'System.ComponentModel.Win32Exception' occurred in System.dll
A first chance exception of type 'System.ObjectDisposedException' occurred in System.dll
A first chance exception of type 'System.ComponentModel.Win32Exception' occurred in System.dll
A first chance exception of type 'System.ObjectDisposedException' …
Run Code Online (Sandbox Code Playgroud)

ssl production-environment apple-push-notifications pushsharp

29
推荐指数
1
解决办法
2万
查看次数

最大发送尝试次数

我正在使用PushSharp v2.0.4.我有一个推送通知服务(即Windows服务),每分钟发送一次通知.服务负载非常小.最多,每次运行我会发送四个通知.

当我的服务启动时,它运行正常大约2小时后才开始看到以下消息:

2013-06-04 07:59:01.0857|Error|Failure: PushSharp.Apple.ApplePushService -> 
The maximum number of Send attempts to send the notification was reached! -> {"aps":{"badge":2}}
Run Code Online (Sandbox Code Playgroud)

一旦出现此消息,似乎PushSharp无法轻易地通过它.在我重新启动服务之前,我会继续看到此消息.

我应该提一下,当这个错误发生时,我确实看到一些随机的已发送消息通过.例如:

2013-06-04 07:54:04.3982|Info|Sent: PushSharp.Apple.ApplePushService -> {"aps":{"badge":2}}
Run Code Online (Sandbox Code Playgroud)

我正在使用其默认配置运行PushSharp.

有关导致失败的原因的任何想法?

.net c# apple-push-notifications pushsharp

25
推荐指数
1
解决办法
2212
查看次数

使用PushSharp推送通知 - 基础知识

我需要将通知推送到我的应用安装的数万个iOS设备.我正在尝试使用PushSharp,但我在这里缺少一些基本概念.起初我尝试在Windows服务中实际运行它,但无法使其工作 - 从_push.QueueNotification()调用获取空引用错误.然后我完成了所记录的示例代码所做的工作并且它有效:

    PushService _push = new PushService();

    _push.Events.OnNotificationSendFailure += new ChannelEvents.NotificationSendFailureDelegate(Events_OnNotificationSendFailure);
    _push.Events.OnNotificationSent += new ChannelEvents.NotificationSentDelegate(Events_OnNotificationSent);

    var cert = File.ReadAllBytes(HttpContext.Current.Server.MapPath("..pathtokeyfile.p12"));

    _push.StartApplePushService(new ApplePushChannelSettings(false, cert, "certpwd"));

    AppleNotification notification = NotificationFactory.Apple()
                                                        .ForDeviceToken(deviceToken)
                                                        .WithAlert(message)
                                                        .WithSound("default")
                                                        .WithBadge(badge);
    _push.QueueNotification(notification);

    _push.StopAllServices(true);
Run Code Online (Sandbox Code Playgroud)

问题#1:这很好用,我看到iPhone上的通知弹出.但是,由于它被称为推送服务,我认为它的行为就像一个服务 - 意思是,我实例化它并在Windows服务中调用_push.StartApplePushService().我想实际排队我的通知,我可以在前端做这个(管理员应用程序,让我们说):

        PushService push = new PushService();

        AppleNotification notification = NotificationFactory.Apple()
                                                            .ForDeviceToken(deviceToken)
                                                            .WithAlert(message)
                                                            .WithSound("default")
                                                            .WithBadge(badge);
        push.QueueNotification(notification);
Run Code Online (Sandbox Code Playgroud)

显然(就像我已经说过的那样),它没有用 - 最后一行不断抛出空引用异常.

我很难找到任何其他类型的文档来展示如何以服务/客户端方式设置它(而不是一次调用所有内容).是否有可能或者我错过了应该如何利用PushSharp的观点?

问题2:此外,我似乎无法找到一种方法同时定位多个设备令牌,而无需循环遍历它们并一次排队一个通知.这是唯一的方法还是我在这里错过了什么?

提前致谢.

.net c# push-notification apple-push-notifications pushsharp

14
推荐指数
1
解决办法
2万
查看次数

PushSharp Apple - 收到的消息是意外的或格式错误

我使用的是PushSharp 2.1.2版.该应用程序是.NET 4.5.1(虽然我也尝试过针对.NET 4.5和.NET 4)

我正在尝试但没有成功通过沙盒Apple APNS发送推送消息.

我使用相同的证书并使用与我的PushSharp应用程序相同的设备ID,使用Ray Wenderlich演练中提供的PHP脚本成功发送消息.

我已通过从钥匙链中导出已完成的证书p12进行测试.导出已完成的证书和密钥.导出私钥.也可以通过这里使用的方法.当我将证书和密钥结合起来用于PHP脚本时,我没有任何问题.

我已将p12证书导入到我测试过的机器上 - 似乎没有任何区别.

我已经尝试在将apple推送服务注册到推送代理时更改IsProduction标志.设置为生产时没有错误(即使这是沙盒证书),但在这种情况下它显然也无法通过设备.

我的所有消息都不会通过,所有消息都会得到如下所示的服务异常:

System.Security.Authentication.AuthenticationException: A call to SSPI failed, see inner exception. ---> System.ComponentModel.Win32Exception: The message received was unexpected or badly formatted
 --- End of inner exception stack trace ---
at System.Net.Security.SslState.StartSendAuthResetSignal(ProtocolToken message, AsyncProtocolRequest asyncRequest, Exception exception)
at System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest)
at …
Run Code Online (Sandbox Code Playgroud)

c# apple-push-notifications pushsharp

12
推荐指数
1
解决办法
1万
查看次数

PushSharp无法识别APN生产证书

我开发了一个iOS应用程序,它接收推送通知.我正在使用PushSharp从.NET环境发送它们.开发过程中一切都很美妙,推送成功发送:

var push = new PushBroker();
var appleCert = File.ReadAllBytes(@"Utils\Cert.Development.p12");
push.RegisterAppleService(new ApplePushChannelSettings(false, appleCert, "*******"));
push.QueueNotification(new AppleNotification()
    .ForDeviceToken(token)
    .WithContentAvailable(1)
);
push.StopAllServices();
Run Code Online (Sandbox Code Playgroud)

现在,该应用已获批准,它位于AppStore.我已经生成了正确的生产证书:

var push = new PushBroker();
var appleCert = File.ReadAllBytes(@"Utils\Cert.Production.p12");
push.RegisterAppleService(new ApplePushChannelSettings(true, appleCert, "*******"));
push.QueueNotification(new AppleNotification()
    .ForDeviceToken(token)
    .WithContentAvailable(1)
);
push.StopAllServices();
Run Code Online (Sandbox Code Playgroud)

但是当我尝试从PushSharp发送推送时,它会抛出以下异常:

You have selected the Production server, yet your Certificate does not appear to be the Production certificate! Please check to ensure you have the correct certificate!
Run Code Online (Sandbox Code Playgroud)

我很确定我已经完成了所有步骤.我已经下载了与应用程序中设置的配置文件绑定的生产证书以进行发布.打开它并导出.p12.

我也确定我不是偶然使用开发版,因为如果我使用最后一个证书设置PushSharp进行开发,则会抛出以下错误:

You have selected the Development/Sandbox (Not production) server, yet your Certificate …
Run Code Online (Sandbox Code Playgroud)

certificate apple-push-notifications ios pushsharp

12
推荐指数
2
解决办法
9794
查看次数

PushSharp发送passkit push时无效的DeviceToken长度

我尝试在Apple passkit相关项目中使用PushSharp.

我目前的问题是关于passkit推送.

当我尝试创建我的通知时,它说

device tokent length无效(确切的异常消息:无效的DeviceToken长度.

var notif = new ApnsNotification(token, payload);
Run Code Online (Sandbox Code Playgroud)

当我注册一个新的passkit优惠券时,它的令牌长度是32.对我来说似乎没问题.

应该是什么问题?PushSharp是否支持passkit?正如我所见,有些人使用它,但我找不到任何关于它的官方信息.

请注意,我知道PushSharp使用它发送普通推送消息,它已经工作多年没有任何问题.我的问题是与passkit相关的推动.

非常感谢!

编辑

在Baris Akar的建议改变代码之后,问题得到解决,但另一个问题出现了:

Apple Notification Failed: ID=1, Code=ConnectionError

2016-11-18 11:07:22.de.[INFO]停止:等待任务2016-11-18 11:07:22.de.[INFO]等待所有任务1 2016-11-18 11:07:22.de.[INFO] APNS-Client [1]:发送批次ID = 1,Count = 1 2016-11-18 11:07:22.de.[INFO] APNS-Client [1]:已发送批处理,等待可能的响应... Apple Notification Failed:ID = 1,Code = ConnectionError 2016-11-18 11:07:22.de.[INFO]所有任务完成2016-11-18 11:07:22.de.[INFO]通过时所有2016-11-18 11:07:22.de.[INFO] Broker IsCompleted 2016-11-18 11:07:22.de.[DEBUG]经纪人任务结束2016-11-18 11:07:22.de.[INFO]停止:完成等待任务2016-11-18 11:07:22.de.[INFO] APNS-Client [1]:批量读取= 1,重置批量计时器...

c# apple-push-notifications pushsharp passkit

12
推荐指数
1
解决办法
591
查看次数

使用PushSharp的正确方法是什么?

我使用PushSharp为几个应用程序发送通知.PushSharp非常棒,它真正简化了推送服务的工作,我想知道使用它的正确方法是什么?我没有找到关于这方面的例子/解释.

现在,当我收到要发送的消息时,我......

  1. 创建一个PushSharp对象
  2. 为所有设备执行PushService.QueueNotification()
  3. 执行PushService.StopAllServices以发送所有排队的消息
  4. 退出方法(并终止PushService对象).

我应该这样工作,还是保持这个PushService对象存活并在需要时调用它的方法?

我应该如何使用PushService对象来获取未注册的设备ID?有一个专门的实例?

任何建议将不胜感激.

pushsharp

9
推荐指数
1
解决办法
5870
查看次数

Pushsharp支持Apple推送通知身份验证密钥

pushsharp是否支持使用Apple推送通知身份验证密钥(永不过期)而不是使用证书来发送APN 的新Apple方法?有没有办法和pushsharp一起使用它?如果没有,是否还有其他C#库来支持它?

c# apple-push-notifications pushsharp

8
推荐指数
1
解决办法
646
查看次数

PushSharp不发送通知

我有一个简单的代码:

PushBroker pushBroker = new PushBroker();
string path = HttpContext.Current.Server.MapPath("~/" + AppSettings.CertificatePath);
var appleCert = File.ReadAllBytes(path);        
pushBroker.RegisterAppleService(
           new ApplePushChannelSettings(AppSettings.IsProductionPushNotificationServer,
                                        appleCert,
                                        AppSettings.CertificatePassword));

var notification = new AppleNotification().ForDeviceToken(deviceToken.TrimStart('<').TrimEnd('>'))
                                          .WithBadge(unviewedInvitationCount);

pushBroker.QueueNotification(notification);
Run Code Online (Sandbox Code Playgroud)

我尝试分别使用Sandbox和Production服务器的开发和生产sertificates.但什么都没发生.客户端能够获得推送通知.怎么了?提前致谢.

更新:

我订阅了这些活动.

OnNotificationFailed告诉我有关此错误的信息:

{APNS NotificationFailureException -> 5 : Invalid token size -> {"aps":{"badge":1}}}
Run Code Online (Sandbox Code Playgroud)

如果我将设备令牌包装到<...>中,我会收到另一个错误:

{APNS NotificationFailureException -> 8 : Invalid token -> {"aps":{"badge":1}}}
Run Code Online (Sandbox Code Playgroud)

c# push-notification apple-push-notifications pushsharp

7
推荐指数
1
解决办法
6604
查看次数