flutter_background_geolocation icon indicating copy to clipboard operation
flutter_background_geolocation copied to clipboard

Objective-C classes should be prefixed

Open stuartmorgan-g opened this issue 2 years ago • 9 comments

Currently most of the Objective-C classes in this plugin have no prefix. This violates Apple's recommended practice for library code, which is very dangerous since collisions would cause undefined behavior at runtime.

Adding a specific-to-this-plugin prefix (e.g., FBG) to all Objective-C classes, per Apple's guidelines, would make it much less likely that someone using this plugin would end up with undefined behavior in their application.

See also https://github.com/transistorsoft/flutter_background_geolocation/issues/1144

Your Environment

  • Plugin version: N/A
  • Platform: iOS
  • OS version: N/A
  • Device manufacturer / model: N/A
  • Flutter info (flutter doctor): N/A
  • Plugin config: N/A
N/A

Expected Behavior

The plugin class uses a 3-letter prefix unique to this plugin.

Actual Behavior

No prefix on most classes.

Steps to Reproduce

N/A

Context

N/A

Debug logs

Logs
N/A

stuartmorgan-g avatar Oct 03 '23 21:10 stuartmorgan-g

Fair enough.

christocracy avatar Oct 03 '23 21:10 christocracy

Released to 4.13.2

christocracy avatar Oct 05 '23 14:10 christocracy

FYI, Apple explicitly reserves all two-letter prefixes for their own use (per the documentation linked above), so while you've avoided potential conflicts with future Flutter-team-authored code, you are now subject to collisions with Apple code in any future iOS release. Third-party code is supposed to use three-letter prefixes.

stuartmorgan-g avatar Oct 05 '23 14:10 stuartmorgan-g

I'm satisfied for the time-being.

christocracy avatar Oct 05 '23 14:10 christocracy

I would urge you to consider the fact that the new situation is significantly more dangerous than the one you fixed with the change. Previously a collision could only have happened if one of the clients of your plugin updated to a new version of Flutter and rebuilt, which means they at least would have an opportunity to discover the problem pre-release.

With this version, existing, published applications are subject to undefined behavior when the users of the application update to a new version of iOS, without any change by the application developer.

stuartmorgan-g avatar Oct 05 '23 14:10 stuartmorgan-g

I'm satisfied for now. I've been doing this for over 9 years without issue.

christocracy avatar Oct 05 '23 14:10 christocracy

I've been doing this for over 9 years without issue.

Yes, the nature of this class of problems is that it works fine as long as there are no collisions, and then suddenly if there are—which is impossible to predict in advance—it is likely catastrophic. I've been writing Obj-C code since before iOS existed, and have seen this happen in the wild with modules that did not follow Apple's guidelines, including cases where applications were suddenly rendered completely useless due to crashes on launch.

If you are set on not changing this, I sincerely hope for the sake of your plugin's clients and their customers that Apple doesn't ever happen to use this prefix.

stuartmorgan-g avatar Oct 05 '23 14:10 stuartmorgan-g

It'll be fine. Relax.

christocracy avatar Oct 05 '23 14:10 christocracy

I’ve had a review of this thread. I will implement a 3-letter namespace.

christocracy avatar Apr 27 '24 00:04 christocracy

This issue is stale because it has been open for 30 days with no activity.

github-actions[bot] avatar May 27 '24 01:05 github-actions[bot]

This issue was closed because it has been inactive for 14 days since being marked as stale.

github-actions[bot] avatar Jun 10 '24 01:06 github-actions[bot]