I have been trying to set up push notifications for an iOS app using the PushSharp library. I have already successfully implemented push notifications with PushSharp for the Android version of the same app, with very few issues. However, despite closely following the examples on the Xamarin website, plus various others around the web I have only been able to get as far as registering the device; no notifications are being received.
So far I have:
1) Generated all the appropriate certificates and provisioning profiles.
2) Implemented overrides to RegisteredForRemoteNotifications, FailedToRegisterForRemoteNotifications & ReceivedRemoteNotification in my iOS app to handle registration and receipt of push notifications.
3) Implemented a call to the Apple Push Notification Server in my notification server (a .NET REST API) along the following lines:
Dim push As PushSharp.PushBroker = New PushSharp.PushBroker()
AddHandler push.OnNotificationSent, AddressOf NotificationSent
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
Dim appleCert As Byte() = File.ReadAllBytes(HttpContext.Current.Server.MapPath("~/bin/External/APNS-Certificate-Development.p12"))
push.RegisterAppleService(New ApplePushChannelSettings(False, appleCert, ""))
push.QueueNotification(New AppleNotification() _
.ForDeviceToken() _
.WithAlert(notificationMessage) _
.WithBadge(1) _
.WithSound("sound.caf"))
push.StopAllServices()
4) Ensured port 2195 is open for outgoing connections on the notification server.
5) Attempted to send notifications to an iPhone 5S & an iPad, both of which had the app running in the foreground when the attempt was made.
When my iOS app starts up it successfully registers for push notifications and this value is stored with the notification server. However, when the notification server sends a notification request to the Apple server, nothing is received on the iOS device. No exceptions are thrown on the notification server so it seems like the request succeeded but no notification is ever received.
Does anyone have any idea what I could be doing wrong, or any suggestions for other things I can try to get this working?
Many thanks,
Pat