HomeiOS Developmentswift - FCM Sending background notification to iOS, however iOS not receiving...

swift – FCM Sending background notification to iOS, however iOS not receiving it


I have been attempting to implement a background notification to ship to iOS utilizing FCM and Firebase Console.

I’ve obtained the next JS working in FCM

const capabilities = require("firebase-functions");
const admin = require("firebase-admin");

admin.initializeApp();

exports.sendSilentPushNotification = capabilities.https.onRequest(async (req, res) => {
  const fcmToken = "epYalsbfm0VBnt_XF41Y8d:APA91bHu_Tn9gm05yn1Ho5q00bmaXc4RybJcsZuYZUawr7amc2AGNbrbid4CHoYJAsgH1mQ0-f4RHSQybSB8XcWbTI-d7v7XpU9U2dbfnVKVjnES2Ii834SevAq5fODCN1SUod1c_836";

  const payload = {
    "information": {
      "story_id": "story_12345",
    },
  };

  const choices = {
    "aps": {
      "content-available": 1,
    },
  };

  strive {
    const response = await admin.messaging().sendToDevice(fcmToken, payload, choices);
    console.log("Despatched silent push notification:", response);
    res.standing(200).ship("Silent push notification despatched efficiently");
  } catch (error) {
    console.error("Error sending silent push notification:", error);
    res.standing(500).ship("Didn't ship silent push notification");
  }
});

And it is telling me the message is shipped efficiently. Nonetheless, i would count on console to print ”acquired distant notification w/ person information” based mostly on this

    
    func software(_ software: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
        print("Obtained distant notification with userInfo: (userInfo)")

        if let aps = userInfo["aps"] as? [String: AnyObject] {
            print("APS key present in userInfo: (aps)")
            if let contentAvailable = aps["content-available"] as? Int, contentAvailable == 1 {
                print("Content material-available key has worth 1, processing journal entry")
                processJournalEntry()
                completionHandler(.newData)
            } else {
                print("Content material-available key not discovered or has a distinct worth")
                completionHandler(.noData)
            }
        } else {
            print("APS key not present in userInfo")
            completionHandler(.noData)
        }
    }

And that is not occurring

  • I’ve tried altering the payload fairly a number of instances, but when i embody APS or APNS within the dictionary i get an error telling me solely information or notification are accepted
  • Tried including FireBaseAppDelegateProxyEnabled Bool No to my information.plist

Neither appear to work

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments