gpt4 book ai didi

swift - ios10、Swift 3 和 Firebase 推送通知设置

转载 作者:行者123 更新时间:2023-11-28 16:08:18 25 4
gpt4 key购买 nike

我正在尝试按照推送通知的示例 https://firebase.google.com/docs/cloud-messaging/ios/client

我在 appDelete.swift 上遇到问题例如

<pre>
extension AppDelegate : FIRMessagingDelegate {
// Receive data message on iOS 10 devices.
func applicationReceivedRemoteMessage(remoteMessage: FIRMessagingRemoteMessage) {
print("%@", remoteMessage.appData)
}

}

错误是

方法“applicationReceivedRemoteMessage(remoteMessage:)”与协议(protocol)“FIRMessagingDelegate”(“applicationReceivedRemoteMessage”)所需的参数名称不同

我在屏幕上看到以下错误

enter image description here

我也有以下的cocopods

Analyzing dependencies
Downloading dependencies
Installing Firebase (3.7.1)
Installing FirebaseAnalytics (3.4.4)
Installing FirebaseCore (3.4.3)
Installing FirebaseInstanceID (1.0.8)
Installing FirebaseMessaging (1.2.0)
Installing GoogleIPhoneUtilities (1.2.1)
Installing GoogleInterchangeUtilities (1.2.2)
Installing GoogleSymbolUtilities (1.1.2)
Installing GoogleUtilities (1.3.2)
Generating Pods project
Integrating client project

有人能告诉我哪里错了吗?我看到了项目 fcm 示例,当我编译时一切正常。

最佳答案

问题是您正在查看的示例代码是 Swift 2.3,而您的项目是 Swift 3.0。

有几种方法可以解决这个问题:

  1. 继续使用 swift 2.3。为此,您可以转到您的项目,选择 Build Settings 并将 Use Legacy Swift Language Version 更改为 Yes

  2. 让 Xcode 自动为您更新它。您可以通过转到 Edit > Convert > To Current Swift Syntax... 来完成此操作,它应该有望解决您遇到的问题。

  3. 手动更新代码。如您所见,Xcode 通常知道更新的代码“应该”是什么,但看起来给您带来麻烦的方法可以更新为看起来有点像这样的东西:

    func application(application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {

    if #available(iOS 10.0, *) {
    let authOptions : UNAuthorizationOptions = [.alert, .badge, .sound]
    UNUserNotificationCenter.current().requestAuthorization(options: authOptions, completionHandler: {_,_ in })

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

    } else {
    let settings: UIUserNotificationSettings =
    UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil)
    application.registerUserNotificationSettings(settings)
    }

    application.registerForRemoteNotifications()

    FIRApp.configure()

    // Add observer for InstanceID token refresh callback.
    NotificationCenter.default.addObserver(self,
    selector: #selector(self.tokenRefreshNotification),
    name: NSNotification.Name.firInstanceIDTokenRefresh,
    object: nil)

    return true
    }
  4. 打扰 Firebase 示例代码人员并告诉他们,“嘿!你忘了将此示例更新到 Swift 3.0!”幸运的是,我能够做到这一点,所以现在就告诉他们。 :)

关于swift - ios10、Swift 3 和 Firebase 推送通知设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39917657/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com