Ad

Not Recieving Push Notifications On My IPhone, But Firebase Functions Says Its Delivered Succesfully?

I want firebase to send push notifications when users get a new message, and it used to work but due to some bugs with FCM token not being saved to new users , i had to change some code. However right now its saving the proper FCM token to new users that have signed up.

However, when a user now gets a message, no notifications are showing up... I checked my logs on firebase functions, and it says that messages are being delivered successful (hence why i think its a error in my code).

This is the way i get users FCM token in AppDelegate:

func application(_ application: UIApplication, 
didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) 
  {
       InstanceID.instanceID().instanceID { (result, error) in
        if let error = error {
            print("Error fetching remote instange ID: \(error)")
        } else if let result = result {
            print("Remote instance ID token: \(result.token)")
            self.tokenOfUser = result.token

        }
    }
  }

This is how i retrieve the token when user signs up, in SignUpViewController:

  var deviceToken : String?
  var delegate = UIApplication.shared.delegate as! AppDelegate
  self.deviceToken = delegate.tokenOfUser

  //and in saving the user profile i add this: 
  ["fcmToken": deviceToken]

And this is my notification code in FeedViewController

This is the first viewcontroller users go to after signing up.

override func viewDidLoad() {
    super.viewDidLoad()
    registerForRemoteNotifications()
  }


func registerForRemoteNotifications() {
    Messaging.messaging().delegate = self
    if #available(iOS 10.0, *) {

        // For iOS 10 display notification (sent via APNS)
        UNUserNotificationCenter.current().delegate = self
        let authOptions: UNAuthorizationOptions = [.alert, .badge, 
        .sound]

        UNUserNotificationCenter.current().requestAuthorization(
            options: authOptions,
            completionHandler: {_, _ in })
    } else {

        let settings: UIUserNotificationSettings =
            UIUserNotificationSettings(types: [.alert, .badge, 
            .sound], categories: nil)

    UIApplication.shared.registerUserNotificationSettings(settings)

    }

    UIApplication.shared.registerForRemoteNotifications()


     }

func messaging(_ messaging: Messaging, didReceiveRegistrationToken 
fcmToken: String) {



    print("Firebase registration token: \(fcmToken)")
    //UserDefaults.standard.set(fcmToken, forKey: "fcmToken")



}

I know that its nothing wrong with the functions, as it used to deliver notifications perfect (so the functions has worked before)

I want the Cloud Functions to send push notifcations, to my Device (with help from FCM Token stored in my Database).

Ad

Answer

Found out the issue. I had FirebaseAppDelegateProxyEnabled set to NO.

I changed the FirebaseAppDelegateProxyEnabled to YES , and now it works fine!

Ad
source: stackoverflow.com
Ad