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

loading...


1

我的应用尝试使用 Firebase 远程通知,我按照Firebase指南进行操作 . 现在我的应用程序崩溃在 AppDelegate ,我正在尝试设置 Firebase 消息传递的委托 .

这是代码

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

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

[FIRInstanceIDCheckinPreferences preferencesFromKeychainContents:]:无法识别的选择器发送到类0x10ef2a538 *由于未捕获的异常'NSInvalidArgumentException'终止应用程序,原因:'[FIRInstanceIDCheckinPreferences preferencesFromKeychainContents:]:无法识别的选择器发送到类0x10ef2a538'*第一次抛出调用堆栈:(0 CoreFoundation 0x00000001116671e6 exceptionPreprocess 294 1 libobjc.A.dylib 0x0000000110cfc031 objc_exception_throw 48 2的CoreFoundation 0x00000001116e86c4 [NSObject的(NSObject的)doesNotRecognizeSelector:] 132 3的CoreFoundation 0x00000001115e9898 __forwarding 1432 4的CoreFoundation 0x00000001115e9278 _CF_forwarding_prep_0 120 5 MobilePro开发0x000000010ed09af3 - [FIRInstanceIDCheckinStore cachedCheckinPreferences] 407 6 MobilePro开发0x000000010ed0d73a - [FIRInstanceIDStore resetCredentialsIfNeeded] 145 7 MobilePro Dev 0x000000010ed0d230 - [FIRInstanceIDStore initWithCheckinStore:tokenStore:delegate:] 174 8 MobilePro Dev 0x000000010 ed0d154 - [FIRInstanceIDStore initWithDelegate:] 142 9 MobilePro Dev 0x000000010ed10acc - [FIRInstanceIDTokenManager init] 105 10 MobilePro Dev 0x000000010ed022ae - [FIRInstanceID setupTokenManager] 50 11 MobilePro Dev 0x000000010ed0225c - [FIRInstanceID start] 90 12 libdispatch.dylib 0x0000000114c4f7ec _dispatch_client_callout 8 13 libdispatch.dylib 0x0000000114c50d64 dispatch_once_f 285 14 MobilePro开发0x000000010ecfefac [FIRInstanceID实例ID] 45 15 MobilePro开发0x000000010ed26a6a - [FIRMessaging initPrivately] 38 16 MobilePro开发0x000000010ed26939 25 FIRMessaging消息] _block_invoke 41 17 libdispatch.dylib 0x0000000114c4f7ec _dispatch_client_callout 8 18 libdispatch.dylib 0x0000000114c50d64 dispatch_once_f 285 19 MobilePro开发0x000000010ed2690d [FIRMessaging messaging] 45 20 MobilePro Dev 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_Compatability _scheduleFirstCommitForScene:过渡:firstActivation:完成:] _ block_invoke 866 25 UIKit的0x0000000113075a39 [_UICanvas _enqueuePostSettingUpdateTransactionBlock:] 153 26的UIKit 0x0000000112ca2bba - [__ UICanvasLifecycleMonitor_Compatability _scheduleFirstCommitForScene:过渡:firstActivation:完成:] 236 27的UIKit 0x0000000112ca33db - [__ UICanvasLifecycleMonitor_Compatability activateEventsOnly:withContext:完成:] 675 28的UIKit 0x0000000113614614 __82 - [_ UIApplicationCanvas _transitionLifecycleStateWithTransitionContext:完成: ] _block_invoke 299 29 UIKit 0x00000001136144ae - [_ UIApplicationCanvas _transitionLifecycleStateWithTransitionContext:co mpletion:] 433 30的UIKit 0x00000001132f875d __125 - [_ UICanvasLifecycleSettingsDiffAction performActionsForCanvas:withUpdatedScene:settingsDiff:fromSettings:transitionContext:] _ block_invoke 221 31的UIKit 0x00000001134f34b7 _performActionsWithDelayForTransitionContext 100 32的UIKit 0x00000001132f8627 - [_ UICanvasLifecycleSettingsDiffAction performActionsForCanvas:withUpdatedScene:settingsDiff:fromSettings:transitionContext:] 223 33的UIKit 0x00000001130750e0 - [_ UICanvas场景:didUpdateWithDiff:transitionContext:完成:] 392 34的UIKit 0x00000001128deeac - [UIApplication的工作区:didCreateScene:withTransitionContext:完成:] 515 35的UIKit 0x0000000112eb1bcb - [UIApplicationSceneClientAgent场景:didInitializeWithEvent:完成:] 361个36 FrontBoardServices 0x00000001176452f3 - [FBSSceneImpl _didCreateWithTransitionContext :完成:] 331 37 FrontBoardServices 0x000000011764dcfa __56- [FBSWorkspace客户端:handleCreateScene:withCompletion:] _ block_invoke_2 225 38 libdispatch.dy LIB 0x0000000114c4f7ec _dispatch_client_callout 8 39 libdispatch.dylib 0x0000000114c54db8 _dispatch_block_invoke_direct 592个40 FrontBoardServices 0x0000000117679470 __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK 24个41 FrontBoardServices 0x000000011767912e - [FBSSerialQueue _performNext] 439个42 FrontBoardServices 0x000000011767968e - [FBSSerialQueue _performNextFromRunLoopSource] 45 43的CoreFoundation 0x0000000111609bb1 CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION 17 44的CoreFoundation 0x00000001115ee4af __CFRunLoopDoSources0 271 45的CoreFoundation 0x00000001115eda6f __CFRunLoopRun 1263 46 CoreFoundation 0x00000001115ed30bCFRunLoopRunSpecific 635 47 GraphicsServices 0x000000011779ca73 GSEventRunModal 62 48 UIKit 0x00000001128e2057 UIApplicationMain 159 49 MobilePro Dev 0x000000010eac56cf main 111 50 libdyld.dylib 0x0000000114ccc955 start 1 51 ??? 0x0000000000000001 0x0 1)libc abi.dylib:以NSException类型的未捕获异常终止

3回答

  • 0

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

    检查Appdelegate中是否调用了以下方法 .

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

    或者确保在Appdelegate中写入 FIRMessagingDelegate

    @interface AppDelegate ()<FIRMessagingDelegate>
    

  • 0

    您需要更改Firebase配置方法 .

    称之为,

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

    它将解决您的问题 .


  • 0
    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 ?? "")")
    }
    

loading...

评论

暂时没有评论!