4
 pod 'Firebase/Database'
 pod 'Firebase/InAppMessagingDisplay'
 pod 'Firebase/Messaging'

Why this error? I read the document and setup code and project as well properly, but when I send InAppMessaging from firebase deshboard and open the app I got this error.

[Firebase/InAppMessaging][I-IAM130004] Failed restful api request to fetch in-app messages: seeing http status code as 400 with body as {
  "error": {
    "code": 400,
    "message": "Request contains an invalid argument.",
    "status": "INVALID_ARGUMENT"
  }


[Firebase/InAppMessaging][I-IAM700002] Error happened during message fetching Error Domain=NSURLErrorDomain Code=400 "(null)"
KENdi
  • 7,576
  • 2
  • 16
  • 31
Deepak Singh
  • 241
  • 3
  • 11
  • I have the same problem. Did you manage to solve it? – Maksim Feb 13 '19 at 12:07
  • yes my problem solved by adding pod step 1 - #pod 'Firebase/InAppMessagingDisplay' step 2 - Pod install step 3 - configure firebase by code Messaging.messaging().shouldEstablishDirectChannel = true step 3 - Delete app from iPhone and reinstall - send APNS token to firebase – Deepak Singh Feb 13 '19 at 12:42

1 Answers1

0

There are 2-3 reasons behind this.

  • Firebase is not configured/initialised at didFinishLaunchingWithOptions
  • FCM token get expired or invalid and refresh token observer not added
  • Use of invalid/different GoogleService-Info.plist i.e if your are using 2 GoogleService-Info.plist in same project for Dev and production . so make sure at the time of installing app the correct GoogleService-Info.plist is picking up

pod 'Firebase/Messaging'

if you are using InAppMessagingDisplay too then install this pod also

pod 'Firebase/InAppMessagingDisplay'

initiation of Firebase at didFinishLaunchingWithOptions

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

    window = UIWindow(frame: CGRect(x: 0, y: 0, width: kDeviceWidth, height: kDeviceHeight))
    
    FirebaseApp.configure()
    NotificationCenter.default.addObserver(self, selector: #selector(tokenRefreshNotification), name: NSNotification.Name.InstanceIDTokenRefresh, object: nil)
    Messaging.messaging().delegate = self
    Messaging.messaging().shouldEstablishDirectChannel = true

    UNUserNotificationCenter.current().delegate = self
    
    if #available(iOS 10.0, *) {
                   
        let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
        UNUserNotificationCenter.current().requestAuthorization(
            options: authOptions,
            completionHandler: {_, _ in })
    } else {
        let settings: UIUserNotificationSettings =
            UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil)
        application.registerUserNotificationSettings(settings)
    }
    
    application.registerForRemoteNotifications()
}
// [START refresh_token]
func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String) {
    
 //You save or send fcm token to your sever
}


//+++++++++++++++++++++++
// FCM Token Get Refreshed
@objc func tokenRefreshNotification(_ notification: Notification) {
    getFCMToken()
}
private func getFCMToken() {
    
    InstanceID.instanceID().instanceID { (result, error) in
        
        if error == nil {
            
            if let result = result {
                let fcmToken = result.token
                //Save or send to your server
            }
        }
    }
}
Community
  • 1
  • 1
Deepak Singh
  • 241
  • 3
  • 11
  • but adding `shouldEstablishDirectChannel` changing the behaviour how your app receiving the messages from firebase https://firebase.google.com/docs/reference/ios/firebasemessaging/api/reference/Classes/FIRMessaging#/c:objc(cs)FIRMessaging(py)shouldEstablishDirectChannel – Peacemoon Apr 12 '19 at 13:35