Skip to content

Commit

Permalink
[url_launcher] Add Swift Package Manager support (flutter#6677)
Browse files Browse the repository at this point in the history
Adds SPM support for both iOS and macOS.

Also opportunistically updates the unit tests for macOS to match the changes made in flutter#4959 since I noticed that they were failing when running locally. This will prevent issues when we update CI in the future.

Fixes flutter/flutter#146916
  • Loading branch information
stuartmorgan authored and TecHaxter committed May 22, 2024
1 parent d8be8e9 commit fca79e8
Show file tree
Hide file tree
Showing 19 changed files with 86 additions and 11 deletions.
4 changes: 4 additions & 0 deletions packages/url_launcher/url_launcher_ios/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 6.3.0

* Adds Swift Package Manager compatibility.

## 6.2.5

* Adds explicit imports for UIKit.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ A Flutter plugin for making the underlying platform (Android or iOS) launch a UR
s.source = { :http => 'https://github.com/flutter/packages/tree/main/packages/url_launcher/url_launcher_ios' }
s.documentation_url = 'https://pub.dev/packages/url_launcher'
s.swift_version = '5.0'
s.source_files = 'Classes/**/*.swift'
s.source_files = 'url_launcher_ios/Sources/**/*.swift'
s.xcconfig = {
'LIBRARY_SEARCH_PATHS' => '$(TOOLCHAIN_DIR)/usr/lib/swift/$(PLATFORM_NAME)/ $(SDKROOT)/usr/lib/swift',
'LD_RUNPATH_SEARCH_PATHS' => '/usr/lib/swift',
}
s.dependency 'Flutter'
s.platform = :ios, '12.0'
s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES' }
s.resource_bundles = {'url_launcher_ios_privacy' => ['Resources/PrivacyInfo.xcprivacy']}
s.resource_bundles = {'url_launcher_ios_privacy' => ['url_launcher_ios/Sources/url_launcher_ios/Resources/PrivacyInfo.xcprivacy']}
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// swift-tools-version: 5.9
// The swift-tools-version declares the minimum version of Swift required to build this package.

// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import PackageDescription

let package = Package(
name: "url_launcher_ios",
platforms: [
.iOS("12.0")
],
products: [
.library(name: "url-launcher-ios", targets: ["url_launcher_ios"])
],
dependencies: [],
targets: [
.target(
name: "url_launcher_ios",
dependencies: [],
resources: [
.process("Resources")
]
)
]
)
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import 'package:pigeon/pigeon.dart';

@ConfigurePigeon(PigeonOptions(
dartOut: 'lib/src/messages.g.dart',
swiftOut: 'ios/Classes/messages.g.swift',
swiftOut: 'ios/url_launcher_ios/Sources/url_launcher_ios/messages.g.swift',
copyrightHeader: 'pigeons/copyright.txt',
))

Expand Down
2 changes: 1 addition & 1 deletion packages/url_launcher/url_launcher_ios/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: url_launcher_ios
description: iOS implementation of the url_launcher plugin.
repository: https://github.com/flutter/packages/tree/main/packages/url_launcher/url_launcher_ios
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+url_launcher%22
version: 6.2.5
version: 6.3.0

environment:
sdk: ^3.2.3
Expand Down
3 changes: 2 additions & 1 deletion packages/url_launcher/url_launcher_macos/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## NEXT
## 3.2.0

* Adds Swift Package Manager compatibility.
* Updates minimum supported SDK version to Flutter 3.13/Dart 3.1.

## 3.1.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ import XCTest

@testable import url_launcher_macos

// Tests whether NSURL parsing is strict. When linking against the macOS 14 SDK or later,
// NSURL uses a more lenient parser which will not return nil.
private func urlParsingIsStrict() -> Bool {
return URL(string: "b a d U R L") == nil
}

/// A stub to simulate the system Url handler.
class StubWorkspace: SystemURLHandler {

Expand Down Expand Up @@ -43,7 +49,11 @@ class RunnerTests: XCTestCase {
let plugin = UrlLauncherPlugin()

let result = try plugin.canLaunch(url: "invalid url")
XCTAssertEqual(result.error, .invalidUrl)
if urlParsingIsStrict() {
XCTAssertEqual(result.error, .invalidUrl)
} else {
XCTAssertFalse(result.value)
}
}

func testLaunchSuccessReturnsTrue() throws {
Expand All @@ -69,6 +79,10 @@ class RunnerTests: XCTestCase {
let plugin = UrlLauncherPlugin()

let result = try plugin.launch(url: "invalid url")
XCTAssertEqual(result.error, .invalidUrl)
if urlParsingIsStrict() {
XCTAssertEqual(result.error, .invalidUrl)
} else {
XCTAssertFalse(result.value)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@ Pod::Spec.new do |s|
s.license = { :type => 'BSD', :file => '../LICENSE' }
s.author = { 'Flutter Team' => 'flutter-dev@googlegroups.com' }
s.source = { :http => 'https://github.com/flutter/packages/tree/main/packages/url_launcher/url_launcher_macos' }
s.source_files = 'Classes/**/*'
s.source_files = 'url_launcher_macos/Sources/url_launcher_macos/**/*.swift'
s.dependency 'FlutterMacOS'

s.platform = :osx, '10.14'
s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES' }
s.swift_version = '5.0'
end

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// swift-tools-version: 5.9
// The swift-tools-version declares the minimum version of Swift required to build this package.

// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import PackageDescription

let package = Package(
name: "url_launcher_macos",
platforms: [
.macOS("10.14")
],
products: [
.library(name: "url-launcher-macos", targets: ["url_launcher_macos"])
],
dependencies: [],
targets: [
.target(
name: "url_launcher_macos",
dependencies: [],
resources: [
.process("Resources")
]
)
]
)
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import 'package:pigeon/pigeon.dart';

@ConfigurePigeon(PigeonOptions(
dartOut: 'lib/src/messages.g.dart',
swiftOut: 'macos/Classes/messages.g.swift',
swiftOut:
'macos/url_launcher_macos/Sources/url_launcher_macos/messages.g.swift',
copyrightHeader: 'pigeons/copyright.txt',
))

Expand Down
2 changes: 1 addition & 1 deletion packages/url_launcher/url_launcher_macos/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: url_launcher_macos
description: macOS implementation of the url_launcher plugin.
repository: https://github.com/flutter/packages/tree/main/packages/url_launcher/url_launcher_macos
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+url_launcher%22
version: 3.1.0
version: 3.2.0

environment:
sdk: ^3.1.0
Expand Down

0 comments on commit fca79e8

Please sign in to comment.