2016-04-14 33 views
0

Bir C# konsol uygulamasından göndermek için push bildirimleri almak için uğraşıyordum. Apple'ın geliştirme web sitesinden çalışan bir p12 sertifikam var ve ayrıca bildirimi göndermek istediğim cihaz için cihaz kodunu da aldım. Aşağıda, bildirimi denemek ve göndermek için kullanıyorum koddur. Ben% 100 çalışan android push bildirimleri göndermek için aynı konsol uygulamasını kullanarak PushSharp (2.2.1.0) eski bir sürümünü kullanıyorum.PushSharp ve C# kullanarak iOS cihazlarına Push bildirimleri gönderme # #

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Threading.Tasks; 
using PushSharp; 
using PushSharp.Android; 
using PushSharp.Apple; 
using PushSharp.Core; 
using System.Data; 
using System.Data.SqlClient; 
using System.IO; 
using System.Net.Sockets; 

namespace PushNotificationServiceTradeway 
{ 
class Program 
{ 


    static void Main(string[] args) 
    { 


     var push = new PushBroker(); 
     push.OnNotificationSent += NotificationSent; 
     push.OnChannelException += ChannelException; 
     push.OnServiceException += ServiceException; 
     push.OnNotificationFailed += NotificationFailed; 
     push.OnDeviceSubscriptionExpired += DeviceSubscriptionExpired; 
     push.OnDeviceSubscriptionChanged += DeviceSubscriptionChanged; 
     push.OnChannelCreated += ChannelCreated; 
     push.OnChannelDestroyed += ChannelDestroyed; 


     //Registering the Apple Service and sending an iOS Notification 
     var appleCert = File.ReadAllBytes("Certificate"); 
     push.RegisterAppleService(new ApplePushChannelSettings(appleCert, "")); 
     push.QueueNotification(new AppleNotification() 
            .ForDeviceToken("Phone_Token") 
            .WithAlert("Hello World!") 
            .WithBadge(7)); 

     push.StopAllServices(); 

    } 


    static void DeviceSubscriptionChanged(object sender, 
string oldSubscriptionId, string newSubscriptionId, INotification notification) 
    { 
     Console.WriteLine(notification); 
    } 

    //this even raised when a notification is successfully sent 
    static void NotificationSent(object sender, INotification notification) 
    { 
     Console.WriteLine(notification); 
    } 

    //this is raised when a notification is failed due to some reason 
    static void NotificationFailed(object sender, 
    INotification notification, Exception notificationFailureException) 
    { 
     Console.WriteLine(notificationFailureException); 
    } 

    //this is fired when there is exception is raised by the channel 
    static void ChannelException 
     (object sender, IPushChannel channel, Exception exception) 
    { 
     Console.WriteLine(exception); 
    } 

    //this is fired when there is exception is raised by the service 
    static void ServiceException(object sender, Exception exception) 
    { 
     Console.WriteLine(exception); 
    } 

    //this is raised when the particular device subscription is expired 
    static void DeviceSubscriptionExpired(object sender, 
    string expiredDeviceSubscriptionId, 
     DateTime timestamp, INotification notification) 
    { 
     Console.WriteLine(notification); 
    } 

    //this is raised when the channel is destroyed 
    static void ChannelDestroyed(object sender) 
    { 
     Console.WriteLine(sender); 
    } 

    //this is raised when the channel is created 
    static void ChannelCreated(object sender, IPushChannel pushChannel) 
    { 
     Console.WriteLine(pushChannel); 
    } 

} 
} 

Ama

System.Net.Sockets.SocketException (0x80004005) bir bağlantı girişimi başarısız oldu konsolunda aşağıdaki hata ile bir dakika sonra dışarı o kapatır bildirim ve saatleri göndermek için uygulamayı çalıştırdığınızda bacause bağlı taraf belirli bir süre sonra düzgün bir şekilde yanıt vermedi veya bağlı bir ana sistem, System.Net.Sockets.TcpClient..ctor adresinde 17.172.232.45:2196 yanıt veremediği için bağlantı kurulamadı (String ana bilgisayar adı, int32 bağlantı noktası) PushSharp.Ap adresinden Pushsharp.Apple.FeedbackService.Run (ApplePushChannelSetings, CancellationToken cancelToken) ple.ApplePushService. (ApplePushService) c_AnonStorey0.() m_1 (nesne durumu)

Bunun nasıl düzeltileceği/çözüleceğine dair herhangi bir yardım veya öneri takdir edilecektir.

+0

Üretime mi yoksa sanal alana mı gönderiyorsunuz? Pushsharp sürümünüz elmalar yeni sertifika isimleriyle uyumlu olmayabilir. – derpirscher

+0

Cevap derpirscher için teşekkürler. Evet İki kez kontrol ettim ve bir sanal alan sertifikası, ancak yeni sertifikaların eski pushsharp sürümleriyle uyumlu olup olmadığını görmek için biraz daha fazla araştırma yapın. – Greg4572

cevap

0

Düzeltme işlemini tamamladıktan sonra firmamdaki güvenlik duvarı ayarları Apple'ın push bildirim sunucularına erişimi engelliyordu.

+0

hey greg..can bu çalışma kodunu paylaşın lütfen .. bu çalışmayı başaramayacaksınız. – Lakshay

+0

@Lakshay Hey, neyse ki bu adresin ağımız tarafından engellendiği bir ağ hatasıydı. Bu kod düzgün çalışmalı, ancak hala çalışmayan sertifikalarla sorunu çözmedik. Çalışırsak, buradan gönderirim. – Greg4572