openhab-cloud
openhab-cloud copied to clipboard
Firebase Notification for iOS is not working
I have looked through openhabcloud code and also openhab-ios. One i think realise is that the openhab-ios rely on the following code in AppDelegate.swift to eventually register IOS device token into OpenHAB-Cloud's device DB. Problem is, the following code does not always get called for some bugs related to FCM SDK (search the internet) and it is the google's Messaging device token being registered which will break the apns2 module.
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
dump(deviceToken as NSData)
Messaging.messaging().apnsToken = deviceToken
}
Instead, i suggest to bypass apns2 module, and just let google-firebase to handle all the messages routing to IOS devices. Therefore, the following is a snippet changes that i propose in socket-io.js:
// If we found any android devices, send notification
if (fcmRegistrations.length > 0) {
firebase.sendNotification(fcmRegistrations, newNotification);
}
// If we found any ios devices, send notification
if (iosDeviceTokens.length > 0) {
**use this ** _firebase.sendNotification(iosDeviceTokens, newNotification);_
** remove this ** **sendIosNotifications(iosDeviceTokens, newNotification);**
}