본문 바로가기

.Net

[Open Source] PUSHSHARP 소개 (C#)

  • PUSHSHARP
     - PUSH 를 위한 C# 라이브러리 입니다.

 - https://github.com/Redth/PushSharp



  • PushSharp push객체 (공통)
     //Create our push services broker
     var push = new PushBroker();

 
 //Wire up the events for all the services that the broker registers
 push.OnNotificationSent += NotificationSent;
 push.OnChannelException += ChannelException;
 push.OnServiceException += ServiceException;
 push.OnNotificationFailed += NotificationFailed;
 push.OnDeviceSubscriptionExpired += DeviceSubscriptionExpired;
 push.OnDeviceSubscriptionChanged += DeviceSubscriptionChanged;
 push.OnChannelCreated += ChannelCreated;
 push.OnChannelDestroyed += ChannelDestroyed;


 

  • PushSharp.Google 사용 예제 입니다.
     push.RegisterGcmService(new GcmPushChannelSettings("YOUR Google API's Console API Access  API KEY for Server Apps HERE"));
     push.QueueNotification(new GcmNotification().ForDeviceRegistrationId("DEVICE REGISTRATION ID HERE")
                             .WithJson("{\"alert\":\"Hello World!\",\"badge\":7,\"sound\":\"sound.caf\"}"));

 


  •  PushSharp.Apple 사용 예제 입니다.
     var appleCert = File.ReadAllBytes(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "../../../Resources/PushSharp.Apns.Sandbox.p12"));
     push.RegisterAppleService(new ApplePushChannelSettings(appleCert, "CERTIFICATE PASSWORD HERE")); //Extension method
     push.QueueNotification(new AppleNotification()
                                  .ForDeviceToken("DEVICE TOKEN HERE")
                                  .WithAlert("Hello World!")
                                  .WithBadge(7)
                                  .WithSound("sound.caf"));