【发布时间】:2020-08-14 17:27:51
【问题描述】:
我正要在stackoverflow上问这个问题,但我刚刚想通了。为了后代,我还是发布了这个,因为这个错误花了我几天的时间,我在这个网站上找不到任何提及它。
根据 AppDelegate 中的方案制定了两个不同的方案并选择了不同的 plist 后,我无法通过 FCM 发送推送通知。选择我的 plist 的代码如下所示:
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate, MessagingDelegate {
let defaults = UserDefaults.standard
// NOTE: DONT call registrationDataManager here or any other VC that uses Firebase before it's configured
let gcmMessageIDKey = "gcm.message_id"
let window: UIWindow? = nil
//XXX OVERRIDE INIT BREAKS SWIZZLING -- DO NOT USE
override init() {
super.init()
let buildFor = ProcessInfo.processInfo.environment["BUILD_FOR"]! as String
var firebasePlistFileName = "GoogleService-Info"
if buildFor == "PROD" {
//firebasePlistFileName = "GoogleService-Info-Production"
firebasePlistFileName = "RELEASE-NEW-GoogleService-Info"
print("--- USING PRODUCTION / RELEASE PLIST")
}
else {
firebasePlistFileName = "DEBUG-NEW-GoogleService-Info"
print("--- USING DEBUG PLIST")
}
let filePath = Bundle.main.path(forResource: firebasePlistFileName, ofType: "plist")
guard let fileopts = FirebaseOptions(contentsOfFile: filePath!) else {
assert(false, "Couldn't load config file")
return
}
FirebaseApp.configure(options: fileopts)
}
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// FirebaseApp.configure()
}
如果您尝试执行上述操作,您可能会注意到类似于
的错误[AppDelegateSwizzler] App Delegate does not conform to UIApplicationDelegate protocol firebase
【问题讨论】:
标签: ios swift firebase firebase-cloud-messaging swift5