当应用程序正在设置FirebaseMessaging的委托时,应用程序崩溃



我的应用程序尝试使用Firebase远程通知,我遵循了Firebase指南。现在,我的应用程序在AppDelegate中崩溃,我正试图设置Firebase消息的代理。

这是代码

[FIRApp configure];
[FIRMessaging messaging].delegate = self;

在第二行中,它崩溃了,崩溃消息如下:

+[FIRInstanceIDCheckinPreferences preferenceFromKeychainContents:]:无法识别的选择器发送到类0x10ef2a538

*由于未捕获的异常"NSInvalidArgumentException"而终止应用程序,原因:'+[FIRInstanceIDCheckinPreferences首选项FromKeychainContents:]:无法识别的选择器发送到类0x10ef2a538'*第一次抛出调用堆栈:(0 CoreFoundation 0x00000001116671e6exceptionPreprocess+294 1 libobjc.A.dylib
0x0000000110cfc031 objc_exception_show+48 2 CoreFoundation
0x0000001116e86c4+[NSObject(NSObject)doesNotRecognizeSelector:]+132 3核心基础0x00000001115e9898___forwarding_
+1432 4 CoreFoundation 0x00000001115e9278 _CF_forwarding_prep_0+120 5 MobilePro开发
0x000000010ed09af3-[FIRInstanceIDCheckinStorecachedCheckinPreferences]+407 6 MobilePro开发人员
0x000000010ed0d73a-[FIRInstanceIDStore resetCredentialsIfNeed]+145 7 MobilePro开发人员0x000000010ed0d230-[FIRInstanceIDStore initWithCheckinStore:tokenStore:委托:]+174 8 MobilePro开发人员0x000000010ed0d154-[FIRInstanceIDStore initWithDelegate:]+142 9 MobilePro Dev 0x000000010ed10acc-[FIRInstanceID TokenManager init]+105 10MobilePro开发人员0x000000010ed022ae-[FIRInstanceIDsetupTokenManager]+50 11 MobilePro开发
0x000000010ed0225c-[FIRInstanceID启动]+90 12 libdispatch.dylib0x0000000114c4f7ec_dispatch_client_callout+8 13 libdispatch.dylib0x0000000114c50d64 dispatch_once_f+285 14 MobilePro开发人员
0x000000010ecfefac+[FIRInstanceID instanceID]+45 15 MobilePro开发者0x000000010ed26a6a-[FIRMessaging initPrivately]+38 16 MobilePro开发人员0x000000010ed2693925+[FIRMessaging消息传递]_block_invoke+41 17 libdispatch.dylib
0x0000000114c4f7ec_dispatch_client_callout+8 18 libdispatch_dylib0x0000000114c50d64 dispatch_once_f+285 19 MobilePro开发人员
0x000000010ed2690d+[FIRMessaging消息]+45 20 MobilePro研发人员
0x000000010eaa9ac3-[AppDelegate应用程序:didFinishLaunchingWithOptions:]+323 21 UIKit
0x00000001128d96fb-[UIApplication_handleDelegateCallbacksWithOptions:isSuspended:restoreState:]+278 22 UIKit 0x00000001128db172-[UIApplication_callInitializationDelegatesForMainScene:transitionContext:]+4123 23 UIKit 0x00000001128e05cb-[UIApplication_runWithMainScene:transitionContext:完成:]+1677 24 UIKit 0x0000000112ca2f7e__111-[__UICanvasLifecycleMonitor_Compability _scheduleFirstCommitForScene:转换:第一次激活:完成:]_block_invoke+866 25 UIKit 0x0000000113075a39+[UICanvas _enqueuePostSettingUpdateTransactionBlock:]+153 26 UIKit 0x0000000 112ca2bba-[__UICanvasLifecycleMonitor_Compability _scheduleFirstCommitForScene:转换:首次激活:完成:]+236 27 UIKit 0x0000000112ca33db-[__UICanvasLifecycleMonitor_Compatibility activateEventsOnly:withContext:completion:]+675 28 UIKit
0x0000000113614614__82-[_UIApplicationCanvas_transitionLifecycleStateWithTransitionContext:完成:]_block_invoke+299 29 UIKit 0x00000001136144ae-[UIApplicationCanvas _transitionLifecycleStateWithTransitionContext:完成:]+433 30 UIKit 0x0000000 1132f875d__125-[_UICanvasLifecycleSettingsDiffAction performActionForCanvas:带更新的场景:设置Diff:来自设置:transitionContext:]_block_invoke+221 31 UIKit 0x00000001134f34b7 _针对TransitionContext执行延迟操作+100 32 UIKit 0x0000000 1132f8627-[UICanvasLifecycleSettingsDiffActionperformActionsForCanvas:withUpdatedScene:settingsDiff:fromSettings:transitionContext:]+223 33 UIKit 0x00000001130750e0-[UICanvas场景:didUpdateWithDiff:transitionContext:完成:]+392 34 UIKit 0x0000000 1128deeac-[UIApplication工作区:didCreateScene:withTransitionContext:完成:]+515 35UIKit 0x0000000112eb1bcb-[UIApplicationSceneClientAgent场景:didInitializeWithEvent:完成:]+361 36FrontBoardServices 0x00000001176452f3-[FBsceneImpl_didCreateWithTransitionContext:完成:]+3331 37 FrontBoardServices 0x000000011764dcfa__56-[FBSWorkspace客户端:handleCreateScene:带完成:]_block_invoke_2+225 38libdispatch.dylib 0x0000000114c4f7ec_dispatch_client_callout+8 39 libdispatch.dylib 0x0000000114c54db8 _dispatch_block_invoke_direct+592 40FrontBoardServices 0x0000000117679470__FBSSERIALQUE_IS_CALLING_OUT_TO_A_BLOCK
+24 41 FrontBoardServices 0x000000011767912e-[FBSSerialQueue _performNext]+439 42 FrontBoardServices 0x000000011767968e-[FBSSerialQueue_performNext FromRunLoopSource]+45 43 CoreFoundation 0x0000000111609bb1CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION+17 44 CoreFoundation 0x00000001115ee4af__CFRunLoopDoSources0+271 45 CoreFoundation 0x00000001115eda6f__CFRunLoopHun+1263 46 CoreFoundation
0x00000001115 ed30b CFRunLoophRunSpecific+635 47 GraphicsServices
0x0000011779ca73 GSEventRunModal+62 48 UIKit
x0000001128e2057 UIApplicationMain+159 49 MobilePro开发人员
0x00000010eac56cf main+111 50libdyld.dylib
0x0000000114ccc955开始+1 51
0x0000000000000001 0x0+1)libc++abi.dylib:终止于NSException 类型的未捕获异常

如果不使用pod,则必须为目标添加objC链接器标志。

来自文件:

"无需CocoaPods即可集成如果你不想使用Cocoapods,你仍然可以通过直接导入框架来利用Firebase SDK。

下载框架SDK zip。这是一个约1GB的文件,可能需要一些时间才能下载。

解压缩文件,然后查看要包含在应用程序中的框架的自述文件。

在目标的生成设置中的其他链接器设置中添加ObjC链接器标志">

链接:https://firebase.google.com/docs/ios/setuphttps://developer.apple.com/library/archive/qa/qa1490/_index.html

调用委托时,必须确保编写该委托的所有必需方法。

请检查是否在Appdelegate中调用了以下方法。

-(void)messaging:(FIRMessaging *)messaging didReceiveRegistrationToken:(NSString *)fcmToken 
{
}

或者确保FIRMessagingDelegate写入您的Appdelegate

@interface AppDelegate ()<FIRMessagingDelegate>

您需要更改Firebase配置方法。

称之为

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 42.0), dispatch_get_main_queue(), ^{
[FIRApp configure];
});

它会解决你的问题。

import FirebaseMessaging
FirebaseApp.configure()
Messaging.messaging().delegate = self

//MARK:-消息代理方法。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。

func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String) {
let token = Messaging.messaging().fcmToken
print("FCM token: (token ?? "")")
}

相关内容

  • 没有找到相关文章

最新更新