我正在使用一些Swift和FCM代码,并且在更新了pod之后,我遇到了两个错误。我已经进行了研究,但无法弄清楚该如何解决。

这是代码:

// For iOS 10 display notification (sent via APNS)
[UNUserNotificationCenter currentNotificationCenter].delegate = self;
// For iOS 10 data message (sent via FCM)
[FIRMessaging messaging].remoteMessageDelegate = self;

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
    [[FIRInstanceID instanceID] setAPNSToken:deviceToken type:FIRInstanceIDAPNSTokenTypeProd]; error message———> No visible @interface for 'FIRInstanceID' declares the selector 'setAPNSToken:type:'<--error message ends

    NSLog(@"deviceToken1 = %@; %@",deviceToken,[[FIRInstanceID instanceID] token]);
}

这是错误消息:

在类型的对象上找不到属性“remoteMessageDelegate”
“FIRMessaging *”

最佳答案

在5.0.0版中,他们删除了remoteMessageDelegate并将其替换为delegate:
https://firebase.google.com/support/release-notes/ios#5.0.0
ios - 在类型为&#39;FIRMessaging *&#39;的对象上找不到属性&#39;remoteMessageDelegate&#39;-LMLPHP

在当前delegate API文档中,现在也是FIRMessaging:
https://firebase.google.com/docs/reference/ios/firebasemessaging/api/reference/Classes/FIRMessaging#/c:objc(cs)FIRMessaging(py)delegate

委托处理FCM token 刷新和远程数据消息
通过FCM直接渠道收到。

@property (readwrite, nonatomic, nullable) id<FIRMessagingDelegate> delegate;
您可以参考他们的quickstart-ios代码以获取示例用法:
https://github.com/firebase/quickstart-ios/blob/master/messaging/MessagingExample/AppDelegate.m#L36

  // [START set_messaging_delegate]
  [FIRMessaging messaging].delegate = self;
  // [END set_messaging_delegate]

10-08 02:43