mirror of
https://github.com/amnezia-vpn/amnezia-client.git
synced 2026-06-22 02:01:08 +07:00
reworking of getting the path to the file when saving/opening files
This commit is contained in:
@@ -4,15 +4,16 @@
|
||||
#include <QObject>
|
||||
#include <QStringList>
|
||||
|
||||
class MobileUtils : public QObject {
|
||||
class MobileUtils : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
MobileUtils() = delete;
|
||||
|
||||
public slots:
|
||||
static void shareText(const QStringList& filesToSend);
|
||||
|
||||
static void shareText(const QStringList &filesToSend);
|
||||
static void openFile();
|
||||
};
|
||||
|
||||
#endif // MOBILEUTILS_H
|
||||
|
||||
@@ -35,3 +35,31 @@ void MobileUtils::shareText(const QStringList& filesToSend) {
|
||||
}
|
||||
}
|
||||
|
||||
@interface MyFilePickerDelegate : NSObject <UIDocumentPickerDelegate>
|
||||
@end
|
||||
|
||||
@implementation MyFilePickerDelegate
|
||||
|
||||
- (void)documentPicker:(UIDocumentPickerViewController *)controller didPickDocumentsAtURLs:(NSArray<NSURL *> *)urls {
|
||||
for (NSURL *url in urls) {
|
||||
NSString *filePath = [url path];
|
||||
|
||||
NSData *fileData = [NSData dataWithContentsOfFile:filePath];
|
||||
NSString *fileContent = [[NSString alloc] initWithData:fileData encoding:NSUTF8StringEncoding];
|
||||
NSLog(@"Содержимое файла: %@", fileContent);
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
void MobileUtils::openFile() {
|
||||
UIDocumentPickerViewController *documentPicker = [[UIDocumentPickerViewController alloc] initWithDocumentTypes:@[@"public.item"] inMode:UIDocumentPickerModeOpen];
|
||||
|
||||
MyFilePickerDelegate *filePickerDelegate = [[MyFilePickerDelegate alloc] init];
|
||||
documentPicker.delegate = filePickerDelegate;
|
||||
|
||||
UIViewController *qtController = getViewController();
|
||||
if (!qtController) return;
|
||||
|
||||
[qtController presentViewController:documentPicker animated:YES completion:nil];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user