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

Objective c 无法连接到FCM。错误域=com.google.fcm代码=2001,objective-c,firebase-cloud-messaging,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",

我正在尝试使用以下方式从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];
我的应用程序正确连接到AppDelegate中的FCM。但在发送上述消息时,几分钟后我收到以下错误:

Unable to connect to FCM. Error Domain=com.google.fcm Code=2001 "(null)"
在过去几天的搜索中,我发现了很多建议,但即使应用了它们,我也没有成功地发送信息。希望有人也有同样的问题并找到了解决方案。

更新: 将通知添加到类中:

[[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];
并获得反馈:

NSConcreteNotification 0x15df4f120 {
    name = com.firebase.messaging.notif.send-success;
    userInfo = {
        messageID = ZisMh2OdBsVgjhUlWx9xKnZ3nTk1489164725;
    }
}

因此,消息已发送,现在的问题是,如何检索消息,我认为它将作为推送通知发送。

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

FCM只能向应用程序服务器上游发送消息。因此,setting.uid必须是Firebase项目的发件人ID。然后,当您的应用程序服务器收到消息时,它可以使用uid将消息中继到客户端。似乎您正在尝试执行尚未实现的设备到设备的消息传递