From 07c5e744292b9b385d388417d20dbfab89c820d1 Mon Sep 17 00:00:00 2001 From: Ryan Lepinski Date: Tue, 2 Jul 2024 15:40:18 -0700 Subject: [PATCH] SPM support --- Package.swift | 10 +++++-- UaCapacitorAirship.podspec | 14 ++++++++-- .../AirshipCapacitorBootstrap.m | 5 ++-- .../Public}/AirshipCapacitorBootstrap.h | 0 ios/Plugin.xcodeproj/project.pbxproj | 28 ++++++++++++------- ios/Plugin/AirshipCapacitorAutopilot.swift | 8 ++++-- ios/Plugin/AirshipPlugin.h | 7 ----- ios/Plugin/AirshipPlugin.m | 9 ------ ios/Plugin/AirshipPlugin.swift | 16 +++++++++-- 9 files changed, 61 insertions(+), 36 deletions(-) rename ios/{Plugin => Bootloader}/AirshipCapacitorBootstrap.m (84%) rename ios/{Plugin => Bootloader/Public}/AirshipCapacitorBootstrap.h (100%) delete mode 100644 ios/Plugin/AirshipPlugin.h delete mode 100644 ios/Plugin/AirshipPlugin.m diff --git a/Package.swift b/Package.swift index 0a1eb7f..4dbf925 100644 --- a/Package.swift +++ b/Package.swift @@ -14,14 +14,20 @@ let package = Package( .package(url: "https://github.com/urbanairship/airship-mobile-framework-proxy.git", from: "7.0.0") ], targets: [ - .target( - name: "UaCapacitorAirship", + .target( + name: "UaCapacitorAirshipPlugin", dependencies: [ .product(name: "Capacitor", package: "capacitor-swift-pm"), .product(name: "Cordova", package: "capacitor-swift-pm"), .product(name: "AirshipFrameworkProxy", package: "airship-mobile-framework-proxy") ], path: "ios/Plugin" + ), + .target( + name: "UaCapacitorAirship", + dependencies: [.target(name: "UaCapacitorAirshipPlugin")], + path: "ios/Bootloader", + publicHeadersPath: "Public" ) ] ) \ No newline at end of file diff --git a/UaCapacitorAirship.podspec b/UaCapacitorAirship.podspec index 1a38773..b8a0bb0 100644 --- a/UaCapacitorAirship.podspec +++ b/UaCapacitorAirship.podspec @@ -10,9 +10,19 @@ Pod::Spec.new do |s| s.homepage = package['repository']['url'] s.author = package['author'] s.source = { :git => package['repository']['url'], :tag => s.version.to_s } - s.source_files = 'ios/Plugin/**/*.{swift,h,m,c,cc,mm,cpp}' s.ios.deployment_target = '14.0' s.dependency 'Capacitor' s.swift_version = '5.1' - s.dependency "AirshipFrameworkProxy", "6.3.1" + s.dependency "AirshipFrameworkProxy", "7.0.0" + s.default_subspecs = ["Bootloader", "Plugin"] + + + s.subspec "Bootloader" do |bootloader| + bootloader.source_files = 'ios/Bootloader/**/*.{swift,h,m,c,cc,mm,cpp}' + end + + + s.subspec "Plugin" do |plugin| + plugin.source_files = 'ios/Plugin/**/*.{swift,h,m,c,cc,mm,cpp}' + end end diff --git a/ios/Plugin/AirshipCapacitorBootstrap.m b/ios/Bootloader/AirshipCapacitorBootstrap.m similarity index 84% rename from ios/Plugin/AirshipCapacitorBootstrap.m rename to ios/Bootloader/AirshipCapacitorBootstrap.m index 7aca0e3..faeeb1d 100644 --- a/ios/Plugin/AirshipCapacitorBootstrap.m +++ b/ios/Bootloader/AirshipCapacitorBootstrap.m @@ -4,9 +4,10 @@ #if __has_include() #import +#elif __has_include("UACapacitorAirship-Swift.h") +#import "UaCapacitorAirship-Swift.h" #else -#import - -//! Project version number for Plugin. -FOUNDATION_EXPORT double PluginVersionNumber; - -//! Project version string for Plugin. -FOUNDATION_EXPORT const unsigned char PluginVersionString[]; diff --git a/ios/Plugin/AirshipPlugin.m b/ios/Plugin/AirshipPlugin.m deleted file mode 100644 index abb9d7c..0000000 --- a/ios/Plugin/AirshipPlugin.m +++ /dev/null @@ -1,9 +0,0 @@ -#import -#import -#import "AirshipCapacitorBootstrap.h" - -// Define the plugin using the CAP_PLUGIN Macro, and -// each method the plugin supports using the CAP_PLUGIN_METHOD macro. -CAP_PLUGIN(AirshipPlugin, "Airship", - CAP_PLUGIN_METHOD(perform, CAPPluginReturnPromise); -) diff --git a/ios/Plugin/AirshipPlugin.swift b/ios/Plugin/AirshipPlugin.swift index d75dfb3..d37eecc 100644 --- a/ios/Plugin/AirshipPlugin.swift +++ b/ios/Plugin/AirshipPlugin.swift @@ -1,6 +1,12 @@ import Foundation import Capacitor + +#if canImport(AirshipKit) import AirshipKit +#elseif canImport(AirshipCore) +import AirshipCore +#endif + import AirshipFrameworkProxy /** @@ -8,8 +14,14 @@ import AirshipFrameworkProxy * here: https://capacitorjs.com/docs/plugins/ios */ @objc(AirshipPlugin) -public class AirshipPlugin: CAPPlugin { - +public class AirshipPlugin: CAPPlugin, CAPBridgedPlugin { + + public let identifier = "AirshipPlugin" + public let jsName = "Airship" + public let pluginMethods: [CAPPluginMethod] = [ + CAPPluginMethod(name: "perform", returnType: CAPPluginReturnPromise) + ] + private static let eventNames: [AirshipProxyEventType: String] = [ .authorizedNotificationSettingsChanged: "ios_authorized_notification_settings_changed", .pushTokenReceived: "push_token_received",