pod 'Firebase/Database'
pod 'Firebase/InAppMessagingDisplay'
pod 'Firebase/Messaging'
为什么会出现此错误? 我正确阅读了文档,设置代码和项目,但是当我从Firebase Deshboard发送InAppMessaging并打开应用程序时,出现此错误。
[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)"
答案 0 :(得分:0)
这背后有2-3个原因。
如果您也使用InAppMessagingDisplay,则也要安装此pod
在didFinishLaunchingWithOptions处初始化Firebase
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
}
}
}
}