Post

Replies

Boosts

Views

Activity

Reply to MacOS Add new WiFi profile programmatically
Hello @meaton, thank you for your answer! You could try looking a associateToNetwork in CoreWLAN on the macOS side to see if this gets you closer to what you are looking for. I've tried to use associateToNetwork, and it works if it's an existing Network (aka currently available). However, at the time of this operation, I'm configuring the device, and it's network (WiFi) is not available yet. I've tried digging through Core WLAN framework, but it doesn't seem like it's possible to associate to not available network. Do you have any other tips on leads, regarding this issue?
Oct ’21
Reply to Save DocumentPicker URL for further use
Hello, This issue does not exists on native XCode generated projects, only on Qt generated XCode projects. So the closest conclusion that I've came to is different memory management in Qt generated XCode project and native XCode projects. On a native XCode project, if you assign an NSURL object that we get at didPickDocumentsAtURLs method, to a class variable, the object is being kept alive and we can use it even if we leave the didPickDocumentsAtURLs method. However on a Qt generated XCode project, as soon as we leave didPickDocumentsAtURLs method, the NSURL object value is deinitialized. ARC (Automatic Reference Counting) is disabled on Qt (according to: https://stackoverflow.com/questions/55181370/arc-enabled-for-qt-project-on-macos), and XCode has it enabled by default. My guess that this is the cause for the memory management difference, and there is no way to solve this issue. Or atleast if there is a solution, it's too much of a hassle.
Aug ’21
Reply to iOS Creating a file in a public folder
Hello eskimo! Thank you for the advices, they are super helpful and I'll be sure to implement them in my code! However, I won't accept your answer, since the issue in my case was, that I was trying to call startAccessingSecurityScopedResource with a modified url (the folder that the user chose + NewFileName.extension). It kept returning false, no matter how I've modified the URL. What worked for me, was calling startAccessingSecurityScopedResource with an unmodified folder url, that I receive from document picker. Here I will leave a fully working example for future readers, to make their life easier: - (void)openDocumentPicker { //This is needed, when using this code on QT! //Find the current app window, and its view controller object /* UIApplication* app = [UIApplication sharedApplication]; UIWindow* rootWindow = app.windows[0]; UIViewController* rootViewController = rootWindow.rootViewController; */ //Initialize the document picker. Set appropriate document types //When reading: use document type of the file, that you're going to read //When writing into a new file: use @"public.folder" to select a folder, where your new file will be created UIDocumentPickerViewController *documentPicker = [[UIDocumentPickerViewController alloc] initWithDocumentTypes:@[@"public.folder"] inMode:UIDocumentPickerModeOpen]; //Assigning the delegate, connects the document picker object with callbacks, defined in this object documentPicker.delegate = self; documentPicker.modalPresentationStyle = UIModalPresentationFormSheet; //In this case we're using self. If using on QT, use the rootViewController we've found before [self presentViewController:documentPicker animated:YES completion:nil]; } - (void)documentPicker:(UIDocumentPickerViewController *)controller didPickDocumentsAtURLs:(NSArray<NSURL *> *)urls { //If we come here, user successfully picked a single file/folder //When selecting a folder, we need to start accessing the folder itself, instead of the specific file we're going to create if ( [urls[0] startAccessingSecurityScopedResource] ) //Let the os know we're going use this resource { //Write file case --- //Construct the url, that we're going to be using: folder the user chose + add the new FileName.extension NSURL *destURLPath = [urls[0] URLByAppendingPathComponent:@"Test.txt"]; NSString *dataToWrite = @"This text is going into the file!"; NSError *error = nil; //Write the data, thus creating a new file. Save the new path if operation succeeds if( ![dataToWrite writeToURL:destURLPath atomically:true encoding:NSUTF8StringEncoding error:&error] ) NSLog(@"%@",[error localizedDescription]); //Read file case --- NSData *fileData = [NSData dataWithContentsOfURL:destURLPath options:NSDataReadingUncached error:&error]; if( fileData == nil ) NSLog(@"%@",[error localizedDescription]); [urls[0] stopAccessingSecurityScopedResource]; } else { NSLog(@"startAccessingSecurityScopedResource failed"); } }
Jul ’21
Reply to iOS Creating a file in a public folder
Here's the code: NSError *error = nil; NSString* data = @"This data going into the file"; NSURL *destURLPath = [NSURL URLWithString:urls[0].absoluteString]; NSURL *destURLPath2 = [destURLPath URLByAppendingPathComponent:@"testText.txt"]; [destURLPath2 startAccessingSecurityScopedResource]; //Let the os know we're going to read the file //destURLPath2 = file:///private/var/mobile/Containers/Shared/AppGroup/C9D2B2AF-4086-45BF-98C6-B0BEBA599FA4/File%20Provider%20Storage/New/testText.txt if( [data writeToURL:destURLPath2 atomically:true encoding:NSUTF8StringEncoding error:&error] == NO ) NSLog(@"Error: %@ %@", error, [error userInfo]); [destURLPath2 stopAccessingSecurityScopedResource];
Jul ’21