-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
[url_launcher] migrating objc plugin to swift #4753
[url_launcher] migrating objc plugin to swift #4753
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the contribution! Could you split out a new PR that contains just the migration of the tests to Swift, so we can land that first in a separate PR? Rewriting tests and implementation in the same PR is much, much riskier than doing each one at a time.
@chrisdlangham do we plan to rebase and update this PR? |
@hellohuanlin Yes this is ready now |
packages/url_launcher/url_launcher_ios/example/ios/RunnerTests/URLLauncherTests.swift
Show resolved
Hide resolved
packages/url_launcher/url_launcher_ios/ios/Classes/Launcher.swift
Outdated
Show resolved
Hide resolved
* @param url The invalid URL string | ||
* @return The error to return | ||
*/ | ||
func invalidURLError(for url: String) -> LaunchResultDetails { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this be private?
private var currentSession: URLLaunchSession? | ||
private let launcher: Launcher | ||
|
||
var topViewController: UIViewController? { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this be private?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmmm, what's the diff between this func, and the one in UIViewController extension below?
I think I have addressed everything so far. Thanks for the feedback. |
XCTAssertEqual(error?.code, "argument_error") | ||
XCTAssertEqual(error?.message, "Unable to parse URL") | ||
XCTAssertEqual(error?.details as? String, "Provided URL: urls can't have spaces") | ||
XCTAssertTrue(details == .failedToLoad || details == .invalidUrl) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
which case will it actually be?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It depends on the iOS version the tests are being run on. I think @stuartmorgan can explain it better, but on iOS 17 we should get .failedToLoad, and on older versions, we should get .invalidUrl
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you do "if iOS 17 else".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately Swift apparently has no equivalent to Obj-C SDK preprocessor checks, and that's the determining factor. We don't want to switch on whether it's running on iOS 17, we want to switch on whether it was linked against the iOS 17 SDK, and that's apparently not expressible in Swift. (The best I can find is people suggesting mapping from the SDK to the version of Xcode that introduced that SDK, and then from there to the version of Swift introduced by that version of Xcode, but that's extremely gross since this has nothing to do with Swift language version.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I realized there's a better option; I've added a utility method in the test file that checks the NSURL behavior directly, and then switches based on that in the tests.
} | ||
|
||
/// Default implementation of Launcher, using UIApplication. | ||
final class UIApplicationLauncher: Launcher { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can this simply be an empty extension?
extension UIApplication: Launcher {}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! Done.
} | ||
|
||
func launchUrl( | ||
url: String, universalLinksOnly: Bool, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
line break
} | ||
|
||
func openUrlInSafariViewController( | ||
url: String, completion: @escaping (Result<LaunchResult, Error>) -> Void |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
line break. please go over all signatures and make sure comma separated items are in separate lines.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've swift-format
ed the whole plugin.
topViewController?.present(session.safariViewController, animated: true, completion: nil) | ||
} | ||
|
||
func closeSafariViewController() throws { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is this throwing?
/// The URL could not be launched | ||
failedToLoad, | ||
|
||
/// The URL was not launched because it is not invalid URL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"because the URL is invalid."
/// The URL was successfully launched. | ||
success, | ||
|
||
/// The URL could not be launched |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is missing a period.
); | ||
expect( | ||
await launcher.launch( | ||
'invalid://u r l', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please don't use the URL that's used for invalid URL tests for a case where the return value isn't invalidUrl
. (You could just use the same URL in every test now, but if you're going to keep the URLs that used to be special, please be consistent with them.)
required String url, | ||
}) { | ||
// Replace this in https://github.com/flutter/flutter/issues/127665 | ||
// This is temporary since FlutterError is not a NSError. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line can be removed; it's not temporary due to FlutterError
. What's temporary is throwing a PlatformException
at all.
}) { | ||
// Replace this in https://github.com/flutter/flutter/issues/127665 | ||
// This is temporary since FlutterError is not a NSError. | ||
// The PlatformExceptions thrown here are for compatibility with the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"is for"
// Replace this in https://github.com/flutter/flutter/issues/127665 | ||
// This is temporary since FlutterError is not a NSError. | ||
// The PlatformExceptions thrown here are for compatibility with the | ||
// previous Objective-C implementation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove "Objective-C" since that's not true of the previous implementation.
required final LaunchResult results, | ||
required String url, | ||
}) { | ||
// Replace this in https://github.com/flutter/flutter/issues/127665 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// TODO(stuartmorgan): Remove this as part of standardizing error handling. See
// flutter/flutter#127665
required final LaunchResult results, | ||
required String url, | ||
}) { | ||
// Replace this in https://github.com/flutter/flutter/issues/127665 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please move this entire comment block to be on the throw PlatformException
rather than here, since that's the only part it applies to in this version.
I've noticed quite a few merge conflicts. I've been contemplating whether to continue this, and this has helped me make a decision. Unfortunately, I'm now facing a shortage of both time and energy for this. Please feel free to either close this or relocate it as needed. |
@chrisdlangham Thanks for letting us know. This is basically done, and I definitely don't want to lose all the great work you've done on this, so I'll resolve the conflicts with my recent PR, and do any last adjustments to get it landed. We really appreciate the contribution! |
Taking over PR; dismissing previous review
I think I've addressed the previous comments, so this should be ready for another review @hellohuanlin |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
flutter/packages@fea24c5...2af6954 2023-10-26 katelovett@google.com [two_dimensional_scrollables] Add TableSpanPadding (flutter/packages#5039) 2023-10-26 engine-flutter-autoroll@skia.org Roll Flutter (stable) from 6c4930c to d211f42 (1 revision) (flutter/packages#5238) 2023-10-26 chrislangham@rightnow.org [url_launcher] migrating objc plugin to swift (flutter/packages#4753) 2023-10-26 ybz975218925@live.com [go_router_builder]Avoid losing NullabilitySuffix for typeArguments (flutter/packages#5215) 2023-10-26 engine-flutter-autoroll@skia.org Roll Flutter from 5dd2a4e to c555599 (14 revisions) (flutter/packages#5237) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-packages-flutter-autoroll Please CC flutter-ecosystem@google.com,rmistry@google.com on the revert to ensure that a human is aware of the problem. To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://issues.skia.org/issues/new?component=1389291&template=1850622 Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
This PR converts the iOS portion of the url_launcher plugin from objc to swift. *List which issues are fixed by this PR. You must list at least one issue.* flutter/flutter#119102
This PR converts the iOS portion of the url_launcher plugin from objc to swift.
Fixes flutter/flutter#119102
Pre-launch Checklist
dart format
.)[shared_preferences]
pubspec.yaml
with an appropriate new version according to the [pub versioning philosophy], or this PR is [exempt from version changes].CHANGELOG.md
to add a description of the change, [following repository CHANGELOG style].///
).