Skip to content

Commit

Permalink
add iOS support
Browse files Browse the repository at this point in the history
  • Loading branch information
sun-jiao committed Feb 26, 2024
1 parent 109e433 commit d6ca6d7
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 13 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ todo:
- ~~Convert, including case convert, Chinese simp/trad/pinyin convert, Latin/Cyrillic script transliteration~~.(Done.)
- ~~Incremental renaming: for example, RenamerFile-1, RenamerFile-2, RenamerFile-3, RenamerFile-4, ...~~.(Done.)
- Rules re-editing.
- Implement iOS renamer with specific code and Platform channel, references: [Writing custom platform-specific code](https://docs.flutter.dev/platform-integration/platform-channels?tab=type-mappings-swift-tab#type-mappings-swift-tab), [Providing access to directories](https://developer.apple.com/documentation/uikit/view_controllers/providing_access_to_directories), [juanmartin/renamerApp-ios](https://github.com/juanmartin/renamerApp-ios)

# Screenshots
## Desktop
Expand Down
7 changes: 3 additions & 4 deletions ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@
A40B1E21F74A722135CAF778 /* Pods-RunnerTests.release.xcconfig */,
2581B69E8F1CCD428434EC5E /* Pods-RunnerTests.profile.xcconfig */,
);
name = Pods;
path = Pods;
sourceTree = "<group>";
};
Expand Down Expand Up @@ -475,7 +474,7 @@
INFOPLIST_FILE = Runner/Info.plist;
INFOPLIST_KEY_CFBundleDisplayName = Renamer;
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.utilities";
IPHONEOS_DEPLOYMENT_TARGET = 17.0;
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand Down Expand Up @@ -661,7 +660,7 @@
INFOPLIST_FILE = Runner/Info.plist;
INFOPLIST_KEY_CFBundleDisplayName = Renamer;
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.utilities";
IPHONEOS_DEPLOYMENT_TARGET = 17.0;
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand All @@ -687,7 +686,7 @@
INFOPLIST_FILE = Runner/Info.plist;
INFOPLIST_KEY_CFBundleDisplayName = Renamer;
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.utilities";
IPHONEOS_DEPLOYMENT_TARGET = 17.0;
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand Down
47 changes: 40 additions & 7 deletions ios/Runner/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,44 @@ import Flutter

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
GeneratedPluginRegistrant.register(with: self)
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
GeneratedPluginRegistrant.register(with: self)
let controller: FlutterViewController = window?.rootViewController as! FlutterViewController
let filePickerChannel = FlutterMethodChannel(name: "net.sunjiao.renamer/picker",
binaryMessenger: controller.binaryMessenger)
filePickerChannel.setMethodCallHandler({
[weak self] (call: FlutterMethodCall, result: @escaping FlutterResult) -> Void in
// This method is invoked on the UI thread.
if call.method == "dirAccess" {
self.dirAccess(result: result)
} else if call.method == "renameFile" {
self.renameFile(result: result)
} else {
result(FlutterMethodNotImplemented)
}
})

return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}

private func dirAccess(result: @escaping FlutterResult) {
let documentPicker = UIDocumentPickerViewController(forOpeningContentTypes: [.folder])
documentPicker.delegate = self
window?.rootViewController?.present(documentPicker, animated: true, completion: nil)
}

private func renameFile(result: @escaping FlutterResult) {
return
}
}

extension AppDelegate: UIDocumentPickerDelegate {
func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt urls: [URL]) {
if let url = urls.first {
// result(url.path)
}
}
}
3 changes: 3 additions & 0 deletions ios/Runner/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,8 @@
<key>NSPhotoLibraryUsageDescription</key>
<string>Explain why your app uses photo library</string>

<key>NSDocumentsFolderUsageDescription</key>
<string>Explain why your app uses</string>

</dict>
</plist>
2 changes: 0 additions & 2 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,6 @@ class AppPage extends StatelessWidget {
return;
}
}


}

void _permissionRequest(BuildContext context) => showDialog(
Expand Down
2 changes: 2 additions & 0 deletions lib/pages/files_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ class FilesPageState extends State<FilesPage> {
} else {
return;
}
} else if (Platform.isIOS) {

} else {
FilePickerResult? result = await FilePicker.platform.pickFiles(allowMultiple: true);
if (result != null) {
Expand Down
21 changes: 21 additions & 0 deletions lib/tools/ios_platform.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import 'package:flutter/services.dart';

class PlatformFilePicker {
static const MethodChannel _channel = MethodChannel('net.sunjiao.renamer/picker');

static Future<void> dirAccess() async {
try {
await _channel.invokeMethod('dirAccess');
} on PlatformException catch (e) {
// show error message
}
}

static Future<void> renameFile() async {
try {
await _channel.invokeMethod('renameFile');
} on PlatformException catch (e) {
// show error message
}
}
}

0 comments on commit d6ca6d7

Please sign in to comment.