首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Xcode控制台中的Firebase/InAppMessaging错误显示

Xcode控制台中的Firebase/InAppMessaging错误显示
EN

Stack Overflow用户
提问于 2019-02-08 05:37:10
回答 1查看 2.2K关注 0票数 4
代码语言:javascript
复制
 pod 'Firebase/Database'
 pod 'Firebase/InAppMessagingDisplay'
 pod 'Firebase/Messaging'

为什么会有这个错误?我也正确地阅读了文档、设置代码和项目,但是当我从火基解算板发送InAppMessaging并打开应用程序时,我得到了这个错误。

代码语言:javascript
复制
[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)"
EN

回答 1

Stack Overflow用户

发布于 2019-03-07 05:46:31

这背后有2-3个原因。

  • 在didFinishLaunchingWithOptions上没有配置/初始化防火墙
  • FCM令牌过期或无效,而未添加刷新令牌观察者
  • 使用无效/不同的GoogleService-Info.plist,也就是说,如果您在同一项目中使用2个GoogleService-Info.plist,用于开发和生产。因此,确保在安装应用程序时,正确的GoogleService-Info.plist正在接收

pod 'Firebase/Messaging‘

如果你也在使用InAppMessagingDisplay,那么也安装这个吊舱。

pod 'Firebase/InAppMessagingDisplay‘

在didFinishLaunchingWithOptions启动Firebase

代码语言:javascript
复制
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
            }
        }
    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54586561

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档