ios – Back4App push notifications by way of Parse Dashboard not working

0
13
ios – Back4App push notifications by way of Parse Dashboard not working


I’ve an Android app that makes use of Back4App as a backend and am at the moment porting it to iOS. I’ve been battling sending push notifications to the iOS app by way of the Parse Dashboard (or by way of my Parse backend normally).

In my Android app I applied push notifications following the Back4App guides by utilizing Firebase Cloud Messaging, which labored completely out of the field. I applied Firebase, registered for push notifications, and saved the GCMSenderId and deviceToken in my Parse Set up and registered Firebase within the Android Push Notifications server settings on Back4App and may ship push notifications with none issues.

For the iOS model I attempted emulating this. I created the APN .p8 key file, uploaded it to Firebase, applied Firebase in my App Delegate, registered for push notifications, added push notification capabilities within the App settings, saved the GCMSenderId and the deviceToken in my Parse Set up, and in addition uploaded the APN file to the iOS Push Notifications server settings on Back4App.

With this setup, I can:

  • ship a push notification from Firebase Cloud Messaging on to my Android gadget with a given deviceToken
  • ship a push notification from Firebase Cloud Messaging on to my iOS gadget with a given deviceToken
  • ship a push notification from ParseDashboard to my Android gadget (e.g. based mostly on the subscribed channel in Set up)
  • cannot ship a push notification from ParseDashboard to my iOS gadget

Whereas the push notifications are being despatched (in response to ParseDashboard), they don’t seem to be getting delivered to my iOS gadget. I wish to ship the pushes by way of Parse in order that I can use the identical channel-based distribution system that’s already in place with the Android app.

I figured that this is a matter someplace inside my Back4App backend, so I attempted setting the “manufacturing” worth within the APN Auth key a part of the Back4App iOS push settings to true and false, however each methods don’t work.

How can I repair this?

I began iOS programming just lately and have been utilizing SwiftUI for the app to this point, so I’m fairly unfamiliar with the App Delegate lifecycle occasions, however was in a position to make it work up till this level. Here’s what I’m at the moment utilizing which works within the situations listed above:

class AppDelegate: NSObject, UIApplicationDelegate {
    let gcmMessageIDKey = "gcm.message_id"

    func utility(_ utility: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
        FirebaseApp.configure()

        Messaging.messaging().delegate = self

        if #accessible(iOS 10.0, *) {
          // For iOS 10 show notification (despatched by way of APNS)
          UNUserNotificationCenter.present().delegate = self

          let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
          UNUserNotificationCenter.present().requestAuthorization(
            choices: authOptions,
            completionHandler: {_, _ in })
        } else {
          let settings: UIUserNotificationSettings =
          UIUserNotificationSettings(sorts: [.alert, .badge, .sound], classes: nil)
          utility.registerUserNotificationSettings(settings)
        }

        utility.registerForRemoteNotifications()
        return true
    }

    func utility(_ utility: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any],
                     fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {

      if let messageID = userInfo[gcmMessageIDKey] {
        print("Message ID: (messageID)")
      }

      print(userInfo)

      completionHandler(UIBackgroundFetchResult.newData)
    }
    
}

@accessible(iOS 10, *)
extension AppDelegate : UNUserNotificationCenterDelegate {

  // Obtain displayed notifications for iOS 10 gadgets.
  func userNotificationCenter(_ heart: UNUserNotificationCenter,
                              willPresent notification: UNNotification,
    withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
    let userInfo = notification.request.content material.userInfo

    if let messageID = userInfo[gcmMessageIDKey] {
        print("Message ID: (messageID)")
    }

    print(userInfo)

    completionHandler([[.banner, .badge, .sound]])
  }

    func utility(_ utility: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Information) {
        
        print("didRegisterForRemoteNotificationsWithDeviceToken: token: (deviceToken)")
    }

    func utility(_ utility: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
        
        print("utility:didFailToRegisterForRemoteNotificationsWithError: %@", error)
        
    }

  func userNotificationCenter(_ heart: UNUserNotificationCenter,
                              didReceive response: UNNotificationResponse,
                              withCompletionHandler completionHandler: @escaping () -> Void) {
    let userInfo = response.notification.request.content material.userInfo

    if let messageID = userInfo[gcmMessageIDKey] {
      print("Message ID from userNotificationCenter didReceive: (messageID)")
    }

    print(userInfo)

    completionHandler()
  }
}

extension AppDelegate: MessagingDelegate {
    func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String?) {

        guard let deviceTokenFirebase = fcmToken else { return }
        
        var currentInstallation = Set up.present
        currentInstallation?.pushType = "gcm"
        currentInstallation?.GCMSenderId = "mySenderId"
        currentInstallation?.deviceToken = deviceTokenFirebase
        currentInstallation?.save { ends in
            
            change outcomes {
            case .success(let savedInstallation):
                print("Efficiently save set up: (savedInstallation)")
            case .failure(let error):
                print("Didn't replace set up: (error)")
            }
        }  
        
    }
}

Any assist is way appreciated!

LEAVE A REPLY

Please enter your comment!
Please enter your name here