Skip to content

[ffigen] ObjC version compatibility runtime check #300

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

Closed
liamappelbe opened this issue Apr 7, 2022 · 5 comments · Fixed by #1995
Closed

[ffigen] ObjC version compatibility runtime check #300

liamappelbe opened this issue Apr 7, 2022 · 5 comments · Fixed by #1995
Assignees
Labels
lang-objective_c Related to Objective C support package:ffigen

Comments

@liamappelbe
Copy link
Contributor

Not all APIs are available on all versions of iOS. There are annotations in Objective C for this, so we can turn that into version checks, and throw user friendly exceptions rather than crashing. Suggestion from Brian:

  - (NSURLSessionWebSocketTask *)webSocketTaskWithURL:(NSURL *)url protocols:(NSArray<NSString *>*)protocols API_AVAILABLE(macos(10.15), ios(13.0), watchos(6.0), tvos(13.0));

Could translate into:

webSocketTaskWithURL(NSURL url, NSArray<NSString> protocols) {
  if (platform.isIOS) {
    if (platform.version < 13.0) {
      throw UnsupportedError("webSocketTaskWithURL requires: macos > 10.15, ios >= 13.0, watchos >= 6.0 or tvos >= 13.0 [is ios ${platform.version}.")
    }
  } else ...
  <do the real work>
}
@liamappelbe liamappelbe added the lang-objective_c Related to Objective C support label Apr 7, 2022
@liamappelbe liamappelbe self-assigned this Apr 7, 2022
@liamappelbe
Copy link
Contributor Author

cc @brianquinlan

@dcharkes
Copy link
Collaborator

dcharkes commented Apr 8, 2022

Cool, reading those annotations and generating version checking code is a cool idea!

@dcharkes
Copy link
Collaborator

platform.version

Isn't that the Dart version instead of the OS version?

@liamappelbe
Copy link
Contributor Author

Oops, yeah. Probably meant to use operatingSystemVersion, but I don't think we want to try parsing that.

@liamappelbe liamappelbe changed the title ObjC version compatibility [ffigen] ObjC version compatibility runtime check Aug 13, 2024
@liamappelbe liamappelbe moved this from Backlog to Todo in ObjC/Swift interop Aug 13, 2024
@liamappelbe liamappelbe added this to the ffigen 14.1.0 milestone Aug 13, 2024
@liamappelbe
Copy link
Contributor Author

We're now parsing those API version annotations (#1403). So the only remaining issue is how do we get the OS version at runtime. Since a check like that is OS specific and requires native calls, it might make sense to add a native function to package:objective_c to do this on iOS and macOS. If OS version getters are available on every mobile and desktop platform, and always returns an answer that fits in a semver, then we could instead add this to dart:ffi or package:ffi.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lang-objective_c Related to Objective C support package:ffigen
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants