From 5f951bb92f7aa791804ffc6d88f882f66970ee7e Mon Sep 17 00:00:00 2001 From: Alfreedom <00tango.bromine@icloud.com> Date: Fri, 8 Mar 2024 16:00:06 +0100 Subject: [PATCH] make ios query more flexible --- example/ios/Runner.xcodeproj/project.pbxproj | 3 +- .../xcshareddata/xcschemes/Runner.xcscheme | 2 +- example/ios/Runner/Info.plist | 111 ++++++++++-------- example/lib/main.dart | 7 +- ios/Classes/PlatformMetadataPlugin.swift | 38 +++--- lib/platform_metadata.dart | 2 +- lib/platform_metadata_method_channel.dart | 8 +- lib/platform_metadata_platform_interface.dart | 2 +- pubspec.yaml | 2 +- 9 files changed, 96 insertions(+), 79 deletions(-) diff --git a/example/ios/Runner.xcodeproj/project.pbxproj b/example/ios/Runner.xcodeproj/project.pbxproj index d33c5a6..436c4ac 100644 --- a/example/ios/Runner.xcodeproj/project.pbxproj +++ b/example/ios/Runner.xcodeproj/project.pbxproj @@ -156,7 +156,7 @@ 97C146E61CF9000F007C117D /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 1300; + LastUpgradeCheck = 1430; ORGANIZATIONNAME = ""; TargetAttributes = { 97C146ED1CF9000F007C117D = { @@ -205,6 +205,7 @@ files = ( ); inputPaths = ( + "${TARGET_BUILD_DIR}/${INFOPLIST_PATH}", ); name = "Thin Binary"; outputPaths = ( diff --git a/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme b/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme index c87d15a..a6b826d 100644 --- a/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme +++ b/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme @@ -1,6 +1,6 @@ - - CFBundleDevelopmentRegion - $(DEVELOPMENT_LANGUAGE) - CFBundleDisplayName - Platform Metadata - CFBundleExecutable - $(EXECUTABLE_NAME) - CFBundleIdentifier - $(PRODUCT_BUNDLE_IDENTIFIER) - CFBundleInfoDictionaryVersion - 6.0 - CFBundleName - platform_metadata_example - CFBundlePackageType - APPL - CFBundleShortVersionString - $(FLUTTER_BUILD_NAME) - CFBundleSignature - ???? - CFBundleVersion - $(FLUTTER_BUILD_NUMBER) - LSRequiresIPhoneOS - - UILaunchStoryboardName - LaunchScreen - UIMainStoryboardFile - Main - UISupportedInterfaceOrientations - - UIInterfaceOrientationPortrait - UIInterfaceOrientationLandscapeLeft - UIInterfaceOrientationLandscapeRight - - UISupportedInterfaceOrientations~ipad - - UIInterfaceOrientationPortrait - UIInterfaceOrientationPortraitUpsideDown - UIInterfaceOrientationLandscapeLeft - UIInterfaceOrientationLandscapeRight - - UIViewControllerBasedStatusBarAppearance - - CADisableMinimumFrameDurationOnPhone - - UIApplicationSupportsIndirectInputEvents - - meta_key - meta_value from ios - + + CFBundleDevelopmentRegion + $(DEVELOPMENT_LANGUAGE) + CFBundleDisplayName + Platform Metadata + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + platform_metadata_example + CFBundlePackageType + APPL + CFBundleShortVersionString + $(FLUTTER_BUILD_NAME) + CFBundleSignature + ???? + CFBundleVersion + $(FLUTTER_BUILD_NUMBER) + LSRequiresIPhoneOS + + UILaunchStoryboardName + LaunchScreen + UIMainStoryboardFile + Main + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + UISupportedInterfaceOrientations~ipad + + UIInterfaceOrientationPortrait + UIInterfaceOrientationPortraitUpsideDown + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + UIViewControllerBasedStatusBarAppearance + + CADisableMinimumFrameDurationOnPhone + + UIApplicationSupportsIndirectInputEvents + + meta_key + meta_value from ios + CFBundleURLTypes + + + CFBundleTypeRole + Editor + CFBundleURLName + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleURLSchemes + + wcflutterwallet + + + + diff --git a/example/lib/main.dart b/example/lib/main.dart index cc76436..bb0fde0 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -25,16 +25,17 @@ class _MyAppState extends State { } Future getMetaData() async { - String metaDataValue; + dynamic metaDataValue; try { - metaDataValue = await PlatformMetadata.getMetaDataValue('meta_key') ?? ''; + metaDataValue = + await PlatformMetadata.getMetaDataValue('CFBundleURLTypes'); } on PlatformException { metaDataValue = 'Failed to get metaDataValue.'; } if (!mounted) return; setState(() { - _metaDataValue = metaDataValue; + _metaDataValue = metaDataValue.toString(); }); } diff --git a/ios/Classes/PlatformMetadataPlugin.swift b/ios/Classes/PlatformMetadataPlugin.swift index c475d79..efae53f 100644 --- a/ios/Classes/PlatformMetadataPlugin.swift +++ b/ios/Classes/PlatformMetadataPlugin.swift @@ -2,25 +2,25 @@ import Flutter import UIKit public class PlatformMetadataPlugin: NSObject, FlutterPlugin { - public static func register(with registrar: FlutterPluginRegistrar) { - let channel = FlutterMethodChannel(name: "platform_metadata", binaryMessenger: registrar.messenger()) - let instance = PlatformMetadataPlugin() - registrar.addMethodCallDelegate(instance, channel: channel) - } - - public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) { - - switch call.method { - case "getMetaData": - let arg = call.arguments as! String - let apiURL = Bundle.infoPlistValue(forKey: arg) as? String - result(apiURL) - - default: - result(nil) - } - } - + public static func register(with registrar: FlutterPluginRegistrar) { + let channel = FlutterMethodChannel(name: "platform_metadata", binaryMessenger: registrar.messenger()) + let instance = PlatformMetadataPlugin() + registrar.addMethodCallDelegate(instance, channel: channel) + } + + public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) { + + switch call.method { + case "getMetaData": + let arg = call.arguments as! String + let apiURL = Bundle.infoPlistValue(forKey: arg) + result(apiURL) + + default: + result(nil) + } + } + } extension Bundle { diff --git a/lib/platform_metadata.dart b/lib/platform_metadata.dart index cd9e1e3..f92b6a0 100644 --- a/lib/platform_metadata.dart +++ b/lib/platform_metadata.dart @@ -1,7 +1,7 @@ import 'platform_metadata_platform_interface.dart'; class PlatformMetadata { - static Future getMetaDataValue(String metaDataName) { + static Future getMetaDataValue(String metaDataName) { return PlatformMetadataPlatform.instance.getMetaDataValue(metaDataName); } } diff --git a/lib/platform_metadata_method_channel.dart b/lib/platform_metadata_method_channel.dart index 46d2cdb..47afa4e 100644 --- a/lib/platform_metadata_method_channel.dart +++ b/lib/platform_metadata_method_channel.dart @@ -10,9 +10,11 @@ class MethodChannelPlatformMetadata extends PlatformMetadataPlatform { final methodChannel = const MethodChannel('platform_metadata'); @override - Future getMetaDataValue(String mateDataName) async { - final metaDataValue = - await methodChannel.invokeMethod('getMetaData', mateDataName); + Future getMetaDataValue(String mateDataName) async { + final metaDataValue = await methodChannel.invokeMethod( + 'getMetaData', + mateDataName, + ); return metaDataValue; } } diff --git a/lib/platform_metadata_platform_interface.dart b/lib/platform_metadata_platform_interface.dart index 14ea774..c34c49b 100644 --- a/lib/platform_metadata_platform_interface.dart +++ b/lib/platform_metadata_platform_interface.dart @@ -23,7 +23,7 @@ abstract class PlatformMetadataPlatform extends PlatformInterface { _instance = instance; } - Future getMetaDataValue(String mateDataName) { + Future getMetaDataValue(String mateDataName) { throw UnimplementedError('getMetaData() has not been implemented.'); } } diff --git a/pubspec.yaml b/pubspec.yaml index c376e99..e6a19a2 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -12,7 +12,7 @@ dependencies: sdk: flutter flutter_web_plugins: sdk: flutter - plugin_platform_interface: ^2.0.2 + plugin_platform_interface: ^2.1.8 dev_dependencies: flutter_test: