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

Refactor timer code into separate utility class #53

Closed
wants to merge 6 commits into from

Conversation

julianrex
Copy link
Contributor

@julianrex julianrex commented Jul 31, 2018

This PR moves the timer code out of MMELocationManager to avoid circular references.
It also ensures that the location manager's delegate property is set to nil to avoid a crash. (CLLocationManager's delegate property is declared as assign so needs to be manually nil'd.)

We may want to move this secondary bug fix into a separate PR, so we merge faster, but both of these changes are related to circular references so seemed appropriate.

@rclee I wanted to get this PR in, even though we're still discussing the related telemetry crash at #50.

Update: Please note, there is a similar change we need to make in https://github.com/mapbox/mapbox-gl-native, both of these bugs could account for the above crash. (I'll update this PR with that change when I create it.)

Update 2: The introduction of a custom location manager (via the MGLCLLocationManager protocol in mapbox/mapbox-gl-native#12013) does away for the related change I mention above).

@property (nonatomic) BOOL hostAppHasBackgroundCapability;
@property (nonatomic) MMEEventsConfiguration *configuration;

@end

@implementation MMELocationManager

- (void)dealloc {
_locationManager.delegate = nil;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we call stopUpdatingLocation here?

Copy link
Contributor Author

@julianrex julianrex Aug 2, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a great question. I had all the stop... variants in here, but since the location manager is being deallocated (and its delegate is going too) I'm assuming* that there's no need to call these. It's not clear from the documentation, but I think it's a fair assumption.

Do you know?

*uh oh.

return;
}

if (![delegate timeoutHandlerShouldCheckForTimeout:self]) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While this is an internal application, would it be good if we check first if the delegate already implements the method?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These aren't optional protocol methods, so there's no need to check to see if the delegate already implements it. The compiler will warn if the client hasn't implemented them.

Since these are really internal methods, I didn't see a need to make them optional.

__typeof__(self) strongSelf = weakself;

[strongSelf stopTimer];
[strongSelf.delegate timeoutHandlerBackgroundTaskDidExpire:strongSelf];

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as above.

@class MMEBackgroundLocationServiceTimeoutHandler;
@protocol MMEUIApplicationWrapper;

@protocol MMEBackgroundLocationServiceTimeoutHandlerDelegate
Copy link
Contributor Author

@julianrex julianrex Aug 2, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hate this protocol name 😢 - any suggestions @rclee @fabian-guerra. Maybe replace HandlerDelegate with just one of Protocol, Delegate, Handler?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MMEBackgroundLocationServiceTimeoutDelegate works for me.

Copy link

@fabian-guerra fabian-guerra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please rebase and test the deallocation before merge.

@julianrex
Copy link
Contributor Author

Assigning to @rclee so that further tests can be run.

@julianrex
Copy link
Contributor Author

Closing, in preference of a performSelector:withObject:afterDelay: / [NSObject cancelPreviousPerformRequestsWithTarget:selector:object:] approach.

Please re-open if necessary.

@julianrex julianrex closed this Sep 26, 2018
@rclee rclee deleted the jrex/background-timeout-handler branch February 12, 2020 22:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants