Prerequisites

If your iOS app is using Firebase for sending push notifications you can follow the steps below when integrating Castled SDK.

  1. Complete the basic Push Notifications setup.
  2. If you are using rich push notification, checkout the additional steps.
  3. Disable swizzling.
  4. Notify Castled SDK about push tokens. Please find the code snippet for this below.
    • Monitoring token refresh

      extension AppDelegate: MessagingDelegate {
          // [START refresh_token]
          func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String?) {
              print("Firebase registration token: \(String(describing: fcmToken))")
              let dataDict: [String: String] = ["token": fcmToken ?? ""]
              NotificationCenter.default.post(
                  name: Notification.Name("FCMToken"),
                  object: nil,
                  userInfo: dataDict
              )
              if let token = fcmToken {
                 Castled.sharedInstance.setPushToken(token, type: .fcm)
              }
          }
          // [END refresh_token]
      }
      
    • If fetching token manually, you can notify the SDK about the the new token as below.

      Messaging.messaging().token { token, error in
          if let error = error {
              print("Error fetching FCM registration token: \(error)")
          } else if let token = token {
              print("FCM registration token: \(token)")
              Castled.sharedInstance.setPushToken(token, type: .fcm)
          }
      }