无法连接到FCM.错误域= com.google.fcm代码= 2001

Die*_*ers 9 objective-c firebase-cloud-messaging

我试图从我的iOS-Objective-C应用程序发送一条消息:

    NSInteger iTime = [NSDate timeIntervalSinceReferenceDate];
    NSString *strID = [NSString stringWithFormat:@"%@%ld", setting.uid, (long)iTime];
    NSDictionary *msg = @{@"title": @"My iOS-APP",
                          @"text": @"Message from the app"};
    [[FIRMessaging messaging]sendMessage:msg to:setting.uid  withMessageID:strID timeToLive:240];
Run Code Online (Sandbox Code Playgroud)

我的应用程序正确连接到AppDelegate中的FCM.但是在发送上面的消息时,几分钟后我收到以下错误:

Unable to connect to FCM. Error Domain=com.google.fcm Code=2001 "(null)"
Run Code Online (Sandbox Code Playgroud)

在最后几天搜索我发现了很多建议,但即使应用它们,我也没有成功发送消息.希望有人在那里有同样的问题,并找到了解决方案.

Gia*_*mmo 13

显示此代码错误2001是因为,当您发送消息时,应用程序已连接到FCM.您正尝试再次连接到FCM,这就是消息的原因.代码的某些部分当您尝试发送消息时,请尝试再次连接.


Die*_*ers 0

更新:在类中添加了通知:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(sendDataMessageFailure:) name:FIRMessagingSendErrorNotification object:nil];

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(sendDataMessageSuccess:) name:FIRMessagingSendSuccessNotification object:nil];

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didDeleteMessagesOnServer) name:FIRMessagingMessagesDeletedNotification object:nil];
Run Code Online (Sandbox Code Playgroud)

并得到反馈:

NSConcreteNotification 0x15df4f120 {
    name = com.firebase.messaging.notif.send-success;
    userInfo = {
        messageID = ZisMh2OdBsVgjhUlWx9xKnZ3nTk1489164725;
    }
}
Run Code Online (Sandbox Code Playgroud)

所以它接缝消息已发送,现在的问题是,如何检索消息,我认为它将作为推送通知传递。