Post

Replies

Boosts

Views

Activity

iOS Creating a file in a public folder
Hello there. I want to create a file in a public folder (where it could be seen by user, and the file could be read again. To achieve that, I use document picker, and set the document type to "public.folder" and inMode "UIDocumentPickerModeOpen". After user opens the document picker and selects the desired folder, in "didPickDocumentsAtURLs" callback I get the NSUrl object, which has permissions to modify the file at that url (in this case, it's an url to a folder). There is my issue. I have the url with access permission to a folder, however, to create a file I ussualy need to have the filename.extension in the url. If I were to modify the NSUrl object I've received from the document picker, or convert it to NSString, my guess is I lose the access permission and "createFileAtPath" method always fails. Any leads would be kindly appreciated!
4
0
4.1k
Jul ’21
Save DocumentPicker URL for further use
Hello, I'm having trouble saving the value of an NSURL object. The code bellow is used in a c++ project, however, this issue shouldn't be exclusive to this scenario. I want to use document picker, only to choose a file and get its url, which I would use on c++ side to read/write data. That I've managed to do successfully, by passing the url to c++ side by calling FileWasPicked(std::string) c++ method. However, since document picker allows us to choose files only from public folders, I need to call start/stopAccessingSecurityScopedResource, and to call them I need to pass an NSURL object, that I get from the document picker. I call startAccessingSecurityScopedResource method before leaving didPickDocumentsAtURLs method, however I can't do that with the stopAccessingSecurityScopedResource. I've tried to save the NSURL we get from document picker in a class variable @property NSURL *m_LastUsedURL;, however it's value changes after leaving didPickDocumentsAtURLs method. My guess, is that after leaving the before mention method, the value of the object that we save a pointer to gets deinitialized. Passing the string value back from c++ and converting it to an NSURL object doesn't work either. Is there any way to save NSURL object value in this case, or call the stopAccessingSecurityScopedResource method in a different manner? I attach my current code: @implementation DocumentPicker //In a DocumentPicker.mm file //We call this method from c++, to open document picker - (void)openDocumentPicker:(NSString*)pickerType //We pass the picker type from c++ { //Find the current app window, and its view controller object UIApplication* app = [UIApplication sharedApplication]; UIWindow* rootWindow = app.windows[0]; UIViewController* rootViewController = rootWindow.rootViewController; UIDocumentPickerViewController *documentPicker = [[UIDocumentPickerViewController alloc] initWithDocumentTypes:@[pickerType] inMode:UIDocumentPickerModeOpen]; documentPicker.delegate = self; documentPicker.modalPresentationStyle = UIModalPresentationFormSheet; [rootViewController presentViewController:documentPicker animated:YES completion:nil]; } //Callback, that gets called after user successfully chooses a file - (void)documentPicker:(UIDocumentPickerViewController *)controller didPickDocumentsAtURLs:(NSArray<NSURL *> *)urls { //Start accessing file, that the user have picked if ( [urls[0] startAccessingSecurityScopedResource] ) { _m_LastUsedURL = urls[0]; //Pass the url and exit this method, to do actions in c++ GlobalCppClass->FileWasPicked(urls[0].absoluteString.UTF8String); } else { NSLog(@"startAccessingSecurityScopedResource failed"); } } //This would be called, after we finish reading the file in c++ -(void)stopAccesingFile { [_m_LastUsedURL stopAccessingSecurityScopedResource]; } @end
2
0
1.6k
Jul ’21
Objective-C Assert dialog
Hello, I'm trying to write custom behaviour for assert on iOS. If an assert is triggered, I want to show a dialog, that would inform the user, that a critical error occurred. However, since an assert can occur before the main window is loaded, the dialog must be shown regardless of the main window, which I'm having difficulties with. Is there any good practice on iOS to do this?
1
0
929
Aug ’21
Get current WiFi password programmatically
Hello, I'm trying to find a way, to programmatically get the password, of current WiFi connection, so I could use the password to connect another device to the same WiFi. One of the possibilities that I've found was using a terminal command: "security find-generic-password -ga TypeInYourWiFiNameHere | grep “password:”". Is there any other, more appropriate way to do this in Objective C/C++? Asking user for permission is completely fine and understandable.
5
0
4k
Oct ’21
MacOS Add new WiFi profile programmatically
Hello, I'm struggling to find a way, on how to add a new WiFi profile (SSID & password, that are in System Preferences > Network > Wi-Fi > Preferred Networks) programmatically, on MacOS (preferably something that'd work on obj c). This is if some device would host a wifi hotspot, the Mac could connect to it automatically, or atleast the password would be already present (assuming there's no wifi connection already present).
3
0
1.8k
Oct ’21
DocumentPicker no callback on close
Hello, I've noticed, that when I close DocumentPicker by swiping from top to bottom (without picking a file or pressing cancel), no callback gets called. Currently I'm using didPickDocumentsAtURLs and documentPickerWasCancelled callbacks, neither of them get's called if DocumentPicker is closed by swiping. This is a problem, because while DocumentPicker is open (and a bit after that, while the file would get processed), I show a loading popup, which get's closed in one of the callbacks. In this case, I cant' find a callback to use and close the loading popup. Am I missing a callback, or is there some other issue?
0
1
626
Apr ’22
Giving my paid app for free
Hello, I've been looking into the possibility of giving my paid app for free. So far I've only found 2 ways: Using promo codes. It provides only a single app install per code and the user can't rate it. I'd like to provide full access to the application. Gifting the app. However, I assume that I'd have to pay for it. Is there any FREE way to give user full access to my paid app?
0
0
684
May ’22