mixpanel/mixpanel-iphone

+[MPSwizzler swizzleSelector:onClass:withBlock:named:async:] unrecognized selector sent to class

tmgsca opened this issue · 3 comments

Integration Method: CocoaPods
Xcode Version: 12.5
Library Version: 3.6.3 (also tested with 3.7.1)
Platform: iOS / App Extension / watchOS / tvOS
Language: Swift / Objective-C
Description:

Once notifications have been allowed by the user, the app crashes whenever we set the delegate of UNUserNotificationCenter.

I tried version 3.7.1 but the same issue keeps happening.
The only "solution" I found was registering as the delegate UNUserNotificationCenter as soon as the app is launching. Although I can't guarantee that it will work on all cases since we haven't shipped this to QA yet.

Crash happens at the following method in Mixpanel.m

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
    if ([keyPath isEqualToString:@"delegate"]) {
        Class cls = [[UNUserNotificationCenter currentNotificationCenter].delegate class];
        if (class_getInstanceMethod(cls, NSSelectorFromString(@"userNotificationCenter:didReceiveNotificationResponse:withCompletionHandler:"))) {
            SEL selector = NSSelectorFromString(@"userNotificationCenter:didReceiveNotificationResponse:withCompletionHandler:");
            if (selector) {
                [MPSwizzler swizzleSelector:selector
                                    onClass:cls
                                  withBlock:^(id view, SEL command, UIApplication *application, UNNotificationResponse *response) {
                                      [self trackPushNotification:response.notification.request.content.userInfo];
                                  }
                                      named:@"notification opened"];
            }
        }
    }
}

Exception

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[MPSwizzler swizzleSelector:onClass:withBlock:named:async:]: unrecognized selector sent to class 0x109bd49d8'

Expected Behavior:

App wouldn't crash.

hi @emisvx , Are you using the Mixpanel messaging feature? If yes, we are deprecating Messaging and Mobile A/B testing features(more details), please contact our support if you need to continue the conversation. Sorry for the inconvenience.

If you are not using the Mixpanel Messaging feature, please use our 4.0.0.beta, it's in parity with the 3.x but without Messaging so you won't see the crash.

You can use Swift Package Manager to install the beta version:

  1. In Xcode, select File > Swift Packages > Add Package Dependency.
  2. Follow the prompts using the URL for this repository and point to branch 4.0.0.beta

I'm closing this issue, please feel free to reopen if you have any questions.

@zihejia how to do it while using cocoapod?