protected void startApp()
{
pusher.RegisterAppleService(new ApplePushChannelSettings(File.ReadAllBytes(CertificatePath), CertificatePassword));
pusher.OnDeviceSubscriptionChanged += pusher_OnDeviceSubscriptionChanged;
pusher.OnDeviceSubscriptionExpired += pusher_OnDeviceSubscriptionExpired;
pusher.OnNotificationSent += pusher_OnNotificationSent;
pusher.OnNotificationFailed += pusher_OnNotificationFailed;
}
static void pusher_OnNotificationFailed(object sender, INotification notification, Exception error)
{
var n = (AppleNotification)notification;
//error.Message ...获取推送出错的信息
Log.Error("推送出错的信息", error);
}
static void pusher_OnNotificationSent(object sender, INotification notification)
{
//消息推送成功后
var n = (AppleNotification)notification;
//n.Payload.Alert.Body 获取推送的消息内容...
Log.Error("推送内容"+n.Payload.Alert.Body);
}
static void pusher_OnDeviceSubscriptionExpired(object sender, string expiredSubscriptionId, DateTime expirationDateUtc, INotification notification)
{
// 从数据库删除过期的expiredSubscriptionId
}
static void pusher_OnDeviceSubscriptionChanged(object sender, string oldSubscriptionId, string newSubscriptionId, INotification notification)
{
// 把数据库中的oldSubscriptionId更新为newSubscriptionId
}
pusher.QueueNotification(new AppleNotification().ForDeviceToken(TokenID) .WithAlert("推送的内容").WithBadge(1).WithSound("default"));// 从数据库或者其他等地方获取设备的TokenID,每个iphone一个TokenID