iOS RemoteNotification swizzler infinity loop by two libraries

人盡茶涼 提交于 2020-06-26 14:57:52

问题


In my app, I'm using Mixpanel iPhone library to record usage, and Firebase iOS SDK Messaging library to handle notifications.

The issue happens when the iOS app is in the background, after user tap on a notification toast, app launches but will crash in a few seconds. The failure appears to be an EXC_BAD_ACCESS from Mixpanel's mp_swizzledMethod_5 function.

While digging into the call stack I found that Mixpanel's mp_swizzledMethod_5 and Firebase's FCM_swizzle_didReceiveNotificationResponseWithHandler are calling each other infinitely. Please see this part of call stack

Thread 1 Queue : com.apple.main-thread (serial)
#0  0x0000000104f7a010 in is_interesting_event ()
#1  0x0000000104f7966c in gcd_queue_item_enqueue_hook ()
#2  0x00000001054bd1f0 in _dispatch_introspection_queue_item_enqueue_hook ()
#3  0x000000010548fa54 in dispatch_source_set_event_handler_f ()
#4  0x000000018256bce0 in ___lldb_unnamed_symbol372$$libsqlite3.dylib ()
#5  0x00000001824cb7a0 in ___lldb_unnamed_symbol18$$libsqlite3.dylib ()
#6  0x00000001824cb1d8 in ___lldb_unnamed_symbol17$$libsqlite3.dylib ()
#7  0x0000000182527f80 in ___lldb_unnamed_symbol159$$libsqlite3.dylib ()
#8  0x000000018252b878 in ___lldb_unnamed_symbol167$$libsqlite3.dylib ()
#9  0x000000018252b220 in ___lldb_unnamed_symbol164$$libsqlite3.dylib ()
#10 0x0000000182508048 in ___lldb_unnamed_symbol104$$libsqlite3.dylib ()
#11 0x00000001825037dc in sqlite3_step ()
#12 0x000000010480448c in -[FIRMessagingRmq2PersistentStore saveUnackedS2dMessageWithRmqId:] ()
#13 0x00000001048063e8 in -[FIRMessagingRmqManager saveS2dMessageWithRmqId:] ()
#14 0x00000001047ee768 in -[FIRMessaging appDidReceiveMessage:] ()
#15 0x0000000104802360 in FCM_swizzle_didReceiveNotificationResponseWithHandler ()
#16 0x000000010448388c in mp_swizzledMethod_5 at /Users/allanhahaha/Documents/craig_ios/CraigAtWork/workdl/ios/Mixpanel/MPSwizzler.m:85
#17 0x0000000104802380 in FCM_swizzle_didReceiveNotificationResponseWithHandler ()
#18 0x000000010448388c in mp_swizzledMethod_5 at /Users/allanhahaha/Documents/craig_ios/CraigAtWork/workdl/ios/Mixpanel/MPSwizzler.m:85
#19 0x0000000104802380 in FCM_swizzle_didReceiveNotificationResponseWithHandler ()

... thousands of lines of repeating calls

#6030   0x000000010448388c in mp_swizzledMethod_5 at /Users/allanhahaha/Documents/craig_ios/CraigAtWork/workdl/ios/Mixpanel/MPSwizzler.m:85
#6031   0x0000000104802380 in FCM_swizzle_didReceiveNotificationResponseWithHandler ()
#6032   0x000000010448388c in mp_swizzledMethod_5 at /Users/allanhahaha/Documents/craig_ios/CraigAtWork/workdl/ios/Mixpanel/MPSwizzler.m:85
#6033   0x0000000104802380 in FCM_swizzle_didReceiveNotificationResponseWithHandler ()
#6034   0x000000010448388c in mp_swizzledMethod_5 at /Users/allanhahaha/Documents/craig_ios/CraigAtWork/workdl/ios/Mixpanel/MPSwizzler.m:85
#6035   0x0000000104802380 in FCM_swizzle_didReceiveNotificationResponseWithHandler ()
#6036   0x000000018b8f6064 in -[UIApplication _handleNonLaunchSpecificActions:forScene:withTransitionContext:completion:] ()
#6037   0x000000018bb82af8 in -[__UICanvasLifecycleMonitor_Compatability activateEventsOnly:withContext:completion:] ()
#6038   0x000000018c3077c0 in __82-[_UIApplicationCanvas _transitionLifecycleStateWithTransitionContext:completion:]_block_invoke ()
#6039   0x000000018c307664 in -[_UIApplicationCanvas _transitionLifecycleStateWithTransitionContext:completion:] ()
#6040   0x000000018c0752cc in __125-[_UICanvasLifecycleSettingsDiffAction performActionsForCanvas:withUpdatedScene:settingsDiff:fromSettings:transitionContext:]_block_invoke ()
#6041   0x000000018c20e3cc in _performActionsWithDelayForTransitionContext ()
#6042   0x000000018c07517c in -[_UICanvasLifecycleSettingsDiffAction performActionsForCanvas:withUpdatedScene:settingsDiff:fromSettings:transitionContext:] ()
#6043   0x000000018be59760 in -[_UICanvas scene:didUpdateWithDiff:transitionContext:completion:] ()
#6044   0x000000018bcfb2a8 in -[UIApplicationSceneClientAgent scene:handleEvent:withCompletion:] ()
#6045   0x000000018478aca4 in __80-[FBSSceneImpl updater:didUpdateSettings:withDiff:transitionContext:completion:]_block_invoke.362 ()
#6046   0x000000010548d28c in _dispatch_client_callout ()
#6047   0x00000001054999e4 in _dispatch_block_invoke_direct ()
#6048   0x00000001847be7f8 in __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ ()
#6049   0x00000001847be49c in -[FBSSerialQueue _performNext] ()
#6050   0x00000001847bea38 in -[FBSSerialQueue _performNextFromRunLoopSource] ()
#6051   0x000000018206f77c in __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ ()
#6052   0x000000018206f6fc in __CFRunLoopDoSource0 ()
#6053   0x000000018206ef84 in __CFRunLoopDoSources0 ()
#6054   0x000000018206cb5c in __CFRunLoopRun ()
#6055   0x0000000181f8cc58 in CFRunLoopRunSpecific ()
#6056   0x0000000183e38f84 in GSEventRunModal ()
#6057   0x000000018b6e55c4 in UIApplicationMain ()
#6058   0x00000001044b5b48 in main at /Users/allanhahaha/Documents/craig_ios/CraigAtWork/workdl/ios/workdl/main.m:14
#6059   0x0000000181aac56c in start ()

Please help me understand what might take to fix it... Thanks in advance!


回答1:


Figured out. Both of Firebase and Mixpanel are swizzling notification handlers, so I disabled notification swizzler in Mixpanel by adding

#define MIXPANEL_NO_NOTIFICATION_AB_TEST_SUPPORT 1

on top of Mixpanel.h before @implementation Mixpanel



来源:https://stackoverflow.com/questions/50770726/ios-remotenotification-swizzler-infinity-loop-by-two-libraries

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!