私は PushSharp プロジェクトの wiki に従い、このコードを書いてデバイスに通知を送信します。
Imports PushSharp
Imports PushSharp.Android
Imports PushSharp.Core
Module Module1
Sub Main()
Console.WriteLine("Start notification : ")
Dim push As New PushBroker()
AddHandler push.OnDeviceSubscriptionExpired, AddressOf DeviceSubscriptionChanged
AddHandler push.OnChannelException, AddressOf ChannelException
AddHandler push.OnServiceException, AddressOf ServiceException
AddHandler push.OnNotificationFailed, AddressOf NotificationFailed
AddHandler push.OnDeviceSubscriptionExpired, AddressOf DeviceSubscriptionExpired
AddHandler push.OnDeviceSubscriptionChanged, AddressOf DeviceSubscriptionChanged
AddHandler push.OnChannelCreated, AddressOf ChannelCreated
AddHandler push.OnChannelDestroyed, AddressOf ChannelDestroyed
push.RegisterGcmService(New GcmPushChannelSettings("AIzaSyCcyNj2Q8bHJqJ-gFR6N3CFtM_VJpv9lIE"))
push.QueueNotification(New GcmNotification().ForDeviceRegistrationId("APA91bGPD7eT7_MEqnL5D23BxihL3-4JkpFGpKy_2A2MNIJHFyEqhSM0iFVMRortNg_394VjsXqyuP0vbPbTQcWL-3ab_4mp-rUn4ypfkntqXfgurBeXOc6M5j25ewuclXuhezhV5yULQzpiJWoOlhYFn28Yx8iJRTA5jup4lKYBo7uVObSsLzs").WithJson("{""alert"":""Hello World2!"",""badge"":6,""sound"":""sound.caf""}"))
Console.WriteLine("Waiting for Queue to Finish...")
'Stop and wait for the queues to drains
push.StopAllServices(True)
Console.WriteLine("Queue Finished, press return to exit...")
Console.ReadLine()
End Sub
Sub DeviceSubscriptionChanged(sender As Object, oldSubscriptionId As String, newSubscriptionId As String, notification As INotification)
'Currently this event will only ever happen for Android GCM
Console.WriteLine("Device Registration Changed: Old-> " & oldSubscriptionId & " New-> " & newSubscriptionId & " -> " & Convert.ToString(notification))
End Sub
Sub NotificationSent(sender As Object, notification As INotification)
Console.WriteLine("Sent: " & Convert.ToString(sender) & " -> " & Convert.ToString(notification))
End Sub
Sub NotificationFailed(sender As Object, notification As INotification, notificationFailureException As Exception)
Console.WriteLine("Failure: " & Convert.ToString(sender) & " -> " & Convert.ToString(notificationFailureException.Message) & " -> " & Convert.ToString(notification))
End Sub
Sub ChannelException(sender As Object, channel As IPushChannel, exception As Exception)
Console.WriteLine("Channel Exception: " & Convert.ToString(sender) & " -> " & Convert.ToString(exception))
End Sub
Sub ServiceException(sender As Object, exception As Exception)
Console.WriteLine("Channel Exception: " & Convert.ToString(sender) & " -> " & Convert.ToString(exception))
End Sub
Sub DeviceSubscriptionExpired(sender As Object, expiredDeviceSubscriptionId As String, timestamp As DateTime, notification As INotification)
Console.WriteLine("Device Subscription Expired: " & Convert.ToString(sender) & " -> " & expiredDeviceSubscriptionId)
End Sub
Sub ChannelDestroyed(sender As Object)
Console.WriteLine("Channel Destroyed for: " & Convert.ToString(sender))
End Sub
Sub ChannelCreated(sender As Object, pushChannel As IPushChannel)
Console.WriteLine("Channel Created for: " & Convert.ToString(sender))
End Sub
End Module
私は適切な API キーを持っており、phonegap プラグインで登録 ID を取得しています。通知を送信するために、小さな npm モジュールを使用して、API キーと登録 ID を既にテストしています。このコードをランチすると、何も追加されず (イベントの一致もありません)、電話に通知もありません。
このコードが本当に必要なのを助けてください。