Voor een project ben ik bezig om een iphone pushnotification provider te bouwen. Daarvoor gebruik ik de APNS-Sharp library. De website, waarvandaan de push notificaties verzonden kunnen worden, is gemaakt in VB.NET
Push notification zelf heb ik gelukkig werkende, maar er worden een aantal events geraised in APNS, die ik graag zou willen afhandelen, iets wat we maar niet lukt. Nu moet ik zeggen dat ik nauwelijks werk met events en threading en dat mijn c# skills misschien net iets tekort schieten. Hopelijk dat een medetweaker me kan helpen om dit probleem op te lossen...
Originele code (console app)
Mijn implementatie daarvan
De vraag is dus, hoe ik bijvoorbeeld het "onconnected" event handlen in Private Shared Sub service_Connected ? En hoe zit dat met "service.Error += new NotificationService.OnError(service_Error);" ?
Push notification zelf heb ik gelukkig werkende, maar er worden een aantal events geraised in APNS, die ik graag zou willen afhandelen, iets wat we maar niet lukt. Nu moet ik zeggen dat ik nauwelijks werk met events en threading en dat mijn c# skills misschien net iets tekort schieten. Hopelijk dat een medetweaker me kan helpen om dit probleem op te lossen...
Originele code (console app)
C#:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
| using JdSoft.Apple.Apns.Notifications; namespace JdSoft.Apple.Apns.Test { class Program { [STAThread] static void Main(string[] args) { NotificationService service = new NotificationService(sandbox, p12Filename, p12FilePassword, 1); service.Error += new NotificationService.OnError(service_Error); service.Connecting += new NotificationService.OnConnecting(service_Connecting); service.Connected += new NotificationService.OnConnected(service_Connected); for (int i = 1; i <= count; i++) { Notification alertNotification = new Notification(testDeviceToken); if (service.QueueNotification(alertNotification)) Console.WriteLine("Notification Queued!"); else Console.WriteLine("Notification Failed to be Queued!"); //Sleep in between each message if (i < count) { Console.WriteLine("Sleeping " + sleepBetweenNotifications + " milliseconds before next Notification..."); System.Threading.Thread.Sleep(sleepBetweenNotifications); } } service.Close(); service.Dispose(); Console.ReadLine(); } /* paar eventhandlers weggehaald */ static void service_Disconnected(object sender) { Console.WriteLine("Disconnected..."); } static void service_Connected(object sender) { Console.WriteLine("Connected..."); } static void service_Error(object sender, Exception ex) { Console.WriteLine(string.Format("Error: {0}", ex.Message)); } } } |
Mijn implementatie daarvan
Visual Basic .NET:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
| Imports JdSoft.Apple.Apns.Notifications Public Class modManagerPushNotification Private Sub btnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSave.Click RunStuff() End Sub Public WithEvents service As NotificationService Sub RunStuff() service = New NotificationService(sandbox, p12Filename, p12FilePassword, 1) AddHandler service.Connected, AddressOf service_Connected 'werkt niet Dim alertNotification As New Notification(testDeviceToken) If service.QueueNotification(alertNotification) Then Console.WriteLine("Notification Queued!") Else Console.WriteLine("Notification Failed to be Queued!") End If service.Close() service.Dispose() End Sub 'werkt niet Private Shared Sub service_Connected(ByVal sender As Object) HttpContext.Current.Response.Write("Wroah...") End Sub 'werkt niet Private Shared Sub service_Connecting(ByVal sender As Object) Handles service.Connecting HttpContext.Current.Response.Write("Connecting...") End Sub '(etcetera) End Class |
De vraag is dus, hoe ik bijvoorbeeld het "onconnected" event handlen in Private Shared Sub service_Connected ? En hoe zit dat met "service.Error += new NotificationService.OnError(service_Error);" ?
[ Voor 164% gewijzigd door Verwijderd op 21-06-2011 14:09 ]