Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash while trying to forward method from RxApplicationDelegateProxy #11

Closed
zulkis opened this issue Nov 23, 2017 · 11 comments
Closed

Crash while trying to forward method from RxApplicationDelegateProxy #11

zulkis opened this issue Nov 23, 2017 · 11 comments

Comments

@zulkis
Copy link

zulkis commented Nov 23, 2017

I implemented UNUserNotificationCenterDelegate protocol in my AppDelegate,
then use UIApplication.shared.rx.appState.map...etc

Then after getting push from system RxApplicationDelegateProxy crashed with unrecognized selector at [RxAppState.RxApplicationDelegateProxy userNotificationCenter:didReceiveNotificationResponse:withCompletionHandler:]

After a bit of debugging it seems that forward delegate in RxCocoa's DelegateProxy is nil

screen shot 2017-11-23 at 14 36 51

@pixeldock
Copy link
Owner

Thanks for opening the issue. I'll try to reproduce the issue.

@zulkis
Copy link
Author

zulkis commented Nov 23, 2017

This issues #6
should not be a case, since original call coming from iOS itself in that case.

Also, should not be a case in ObjectiveC, since we could cast UIApplication.sharedApplication.delegate to (id) and as a user of it - I should not worry how Proxy handles forwarding.

@zulkis
Copy link
Author

zulkis commented Nov 23, 2017

Wow, interesting case.
My AppDelegate is ObjectiveC based.

Next screenshots I could not fully understand.
Stacktrace is the same.
1st one is when original setForwardingToDelegate called. We see our RawPointer to AppDelegate:
screen shot 2017-11-23 at 15 00 23
Next call is a RxCocoa call:
screen shot 2017-11-23 at 15 00 31

Delegate is nil.

@zulkis
Copy link
Author

zulkis commented Nov 23, 2017

From the other side, ObjectiveC side of RxCocoa setter is working:

-(void)_setForwardToDelegate:(id __nullable)forwardToDelegate retainDelegate:(BOOL)retainDelegate {
    __forwardToDelegate = forwardToDelegate;
    if (retainDelegate) {
        self.strongForwardDelegate = forwardToDelegate; // self.strongForwardDelegate is existing
    }
    else {
        self.strongForwardDelegate = nil;
    }
}

So my screenshots could be easily misleading since xcode bug of showing bridgeable variables to be nil

@zulkis
Copy link
Author

zulkis commented Nov 23, 2017

Implementing

override open func forwardingTarget(for aSelector: Selector!) -> Any? {
            return self.forwardToDelegate()
}

Fixes an issue, but I am not sure if this solution stable should be done here or like issue in RxCocoa
@pixeldock

@pixeldock
Copy link
Owner

I did not have time to setup a new Objective-C project yet but I tried your scenario with one of my Swift projects. Everything is working fine when your AppDelegate is a Swift class. The issue seems to be related to having a Objective-C AppDelegate.

I think we should open a new issue at RxCocoa.

@pixeldock
Copy link
Owner

@zulkis Thanks!

@kanstraktar
Copy link

Any update on this? I'm having the same issue in a mixed Objective C/Swift project, AppDelegate being ObjC. Thanks

@pixeldock
Copy link
Owner

pixeldock commented Jan 31, 2018

@kanstraktar Unfortunately this issue seems to be caused by something inside RxSwift. There is an open PR (ReactiveX/RxSwift#1503) with a fix but there seems to be some uncertainty why the fix is needed . Have you tried the suggested fix? Maybe you can provide some additional info there?

@pixeldock
Copy link
Owner

I'll close this issue as this has not seen any feedback for over a year. Thank you guys for your feedback!

@Tayphoon
Copy link

Tayphoon commented Aug 17, 2019

It was easy recreate this crash if you have objective-c app with code like this in app delegate

@implementation AppDelegate

+ (instancetype)sharedDelegate {
    return (AppDelegate*)[UIApplication sharedApplication].delegate;
}

Now any calls sharedDelegate in objective-c will return proxy and crash when you try access to any property of AppDelegate.

2019-08-17 21:20:08.183948+0300 CS DEV[3789:29536] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[RxAppState.RxApplicationDelegateProxy managedObjectContext]: unrecognized selector sent to instance 0x600003ed3240'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants