Posts

Post marked as solved
7 Replies
2.2k Views
Hey,This is my code. I have the url of the smb server which I have connected in the 'Files' app. It finds the file on the server, but I always says that it has no permission to read it. On my server I have allowed everyone to read and write. Do I need to write something in my code that my app knows that it has permission to read ?let url: URL = URL(fileURLWithPath: "/private/var/mobile/Library/LiveFiles/com.apple.filesystems.smbclientd/xVUdQwTestApp/testaufbau.csv") do { let fileURLs = try FileManager.default.contentsOfDirectory(at: url, includingPropertiesForKeys: nil) Admin.fileContent = try String(contentsOf: fileURLs[0], encoding: .utf8) print("ADMIN: \(Admin.fileContent)") } catch { print(error) }Thank you for all the helpRegards,Tell Tobler
Posted
by Relbot.
Last updated
.
Post not yet marked as solved
5 Replies
465 Views
Hello, I distributed an App through Ad hoc and was able to install the app through the web server I set up. In my app I need a network connection. But my error handling always tells me that I have no internet connection. Is it possible that there is no Network connection for apps that are distributed through Ad hoc? Thank you for your help Regards, Tell
Posted
by Relbot.
Last updated
.
Post not yet marked as solved
1 Replies
331 Views
Hey,I have multiple TableViews. Here a link how it should looks like: https://ibb.co/JqQr1zQI get the data from a smb serverI want to to have multiple stages.Now my question is, what would be the best structure for this? How do I create this?Thank you for you help.Regars, Tell
Posted
by Relbot.
Last updated
.
Post marked as solved
10 Replies
2.7k Views
Hey, I am trying to save the url which I get from my didPickDocumentAt as a security scoped bookmarkThis is my code:Here just the declaration of the UIDocumentPickerViewControllerlet documentPicker = UIDocumentPickerViewController(documentTypes: [kUTTypePlainText as String], in: .open) documentPicker.delegate = self if #available(iOS 11.0, *) { documentPicker.allowsMultipleSelection = false } else { // Fallback on earlier versions } present(documentPicker, animated: true, completion: nil)Now didPickDocumentAt - there I am saving my bookmark data from my selected file on the smb server. Data.bookmarkAdmin is just the variable in which I store the bookmark.func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentAt url: URL) { print(url) do { let shouldStoppAccessing = url.startAccessingSecurityScopedResource() defer { if shouldStoppAccessing { url.stopAccessingSecurityScopedResource() } } let bookmarkData: Foundation.Data = try url.bookmarkData() Data.bookmarkAdmin = bookmarkData print(Data.bookmarkAdmin) } catch let error { print(error) } }Later in my app I want to use the bookmark data to create the url again and write on that filefunc readFile() { Admin.fileContent = "" Admin.readString.removeAll() do { var isStale = false let url = try URL(resolvingBookmarkData: Data.bookmarkAdmin, bookmarkDataIsStale: &isStale) guard !isStale else { return } var errorText: Error? do { let didStartAccessing = url.startAccessingSecurityScopedResource() defer { if didStartAccessing { url.stopAccessingSecurityScopedResource() } } print(url) let fileURLs = try FileManager.default.contentsOfDirectory(at: url, includingPropertiesForKeys: nil) Admin.fileContent = try String(contentsOf: fileURLs[0], encoding: .utf8) print("ADMIN: \(Admin.fileContent)") } catch { errorText = error } // Errorhandling if errorText != nil { let alertController = UIAlertController(title: "Error", message: "Keine Datei gefunden \(String(describing: errorText))", preferredStyle: .alert) let okAction = UIAlertAction(title: "ok", style: .default, handler: nil) alertController.addAction(okAction) present(alertController, animated: true, completion: nil) } else {} } catch let error {} }I get an error in my readFile() function ERROR:Error Domain=NSCocoaErrorDomain Code=256 "The file “testaufbau” couldn’t be opened." UserInfo={NSURL=file:///private/var/mobile/Library/LiveFiles/com.apple.filesystems.smbclientd/ctPrTwTestApp/testaufbau.csv, NSFilePath=/private/var/mobile/Library/LiveFiles/com.apple.filesystems.smbclientd/ctPrTwTestApp/testaufbau.csv, NSUnderlyingError=0x2834bfbd0 {Error Domain=NSPOSIXErrorDomain Code=20 "Not a directory"}}When I set the url manually in the readFile() without the bookmark justlet url: URL = URL(fileURLWithPath: "/private/var/mobile/Library/LiveFiles/com.apple.filesystems.smbclientd/ctPrTwTestApp/testaufbau.csv")Then I get a different ERROR: Error Domain=NSCocoaErrorDomain Code=257 "The file “testaufbau.csv” couldn’t be opened because you don’t have permission to view it." UserInfo={NSURL=file:///private/var/mobile/Library/LiveFiles/com.apple.filesystems.smbclientd/ctPrTwTestApp/testaufbau.csv, NSFilePath=/private/var/mobile/Library/LiveFiles/com.apple.filesystems.smbclientd/ctPrTwTestApp/testaufbau.csv, NSUnderlyingError=0x280ac1440 {Error Domain=NSPOSIXErrorDomain Code=1 "Operation not permitted"}}How can I solve this and how do I get permission?
Posted
by Relbot.
Last updated
.
Post marked as solved
1 Replies
2.1k Views
Hey,I have been working with the UIDocumenPickerViewController in the last few days.This is my current code:let documentPicker = UIDocumentPickerViewController(documentTypes: [kUTTypePlainText as String], in: .open) documentPicker.delegate = self if #available(iOS 11.0, *) { documentPicker.allowsMultipleSelection = false } else { } present(documentPicker, animated: true, completion: nil)Now my question: After this code I call the didPickDocumentAt MethodedocumentPicker(, didPickDocumentsAt: )But I have no idea what I should put in it, I tried it like thisdocumentPicker(documentPicker, didPickDocumentsAt: [UIDocumentPickerMode.open])I tried it like this but then I always get the Error: Cannot call value of non-function type 'UIDocumentPickerViewController'And my second question is: I want to acces the content of the selected File and found this in the documentation https://developer.apple.com/documentation/uikit/view_controllers/providing_access_to_directoriesIf you go to Access the Directory´s content you find this code// Start accessing a security-scoped resource. guard url.startAccessingSecurityScopedResource() else { // Handle the failure here. return } // Make sure you release the security-scoped resource when you are done. defer { url.stopAccessingSecurityScopedResource() } // Use file coordination for reading and writing any of the URL’s content. var error: NSError? = nil NSFileCoordinator().coordinate(readingItemAt: url, error: &error) { (url) in let keys : [URLResourceKey] = [.nameKey, .isDirectoryKey] // Get an enumerator for the directory's content. guard let fileList = FileManager.default.enumerator(at: url, includingPropertiesForKeys: keys) else { output.append("*** Unable to access the contents of \(url.path) ***\n") return } for case let file as URL in fileList { // Also start accessing the content's security-scoped URL. guard url.startAccessingSecurityScopedResource() else { // Handle the failure here. continue } // Make sure you release the security-scoped resource when you are done. defer { url.stopAccessingSecurityScopedResource() } // Do something with the file here. } }Where do they get the url from in the beginning? The documentation never explains where the url got created.Thank you for your helpRegards,Tell
Posted
by Relbot.
Last updated
.
Post not yet marked as solved
5 Replies
2.3k Views
Hey,so currently I am downloading and import the file I want to read from the smb server through a UIDocumentPickerViewController into the local folder of my app.After that I am able to read this file through the FileManagerThis is how I get the directorylet dir = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!and if I want to upload the same file or another file I write into the local folder, I need to manually upload the file to the smb server through the Files App.Is there any way that I can read and write directly to the smb server?How do I get the directory of the server? Is there a path?Thank you for all your help.Regards,Tell. T.
Posted
by Relbot.
Last updated
.
Post not yet marked as solved
10 Replies
3.4k Views
Hey,I am trying to create a ViewController with a UILabel in it. The UIlabel has multiply lines and a fixed font size. On different devices, different amount of text can fit in this Label. Now my question is if not all of the text fits into the UILabel, how can I pass this remaining text to the next page. Thank you for your helpYours sincerellyTell T.
Posted
by Relbot.
Last updated
.
Post marked as solved
1 Replies
1.3k Views
Is it possible to disable the page chance trigger through swiping and trigger the new page only through a button?In the picture you can see what I try to do. I have a ViewController and the PageViewController is embed in it. The Button is on the bottom of that ViewController. The button shouldn't move.It should always stay the same position but the text and picture above should change to the next ViewController ( the ViewController do not all have the same layout. Some have pictures and some do not have) of the PageViewController.Or is the PageViewController the wrong way for this? If you have an idea would be awesome if you can help me.Yours sincerelly Tell aka. Relbot
Posted
by Relbot.
Last updated
.
Post marked as solved
2 Replies
558 Views
Hey,my aim is to build a local notification which should be triggered at three specific times a day. The notification body should be a different one every day.This is the String Array of which one string should be shown in the notifiaction.It doesn´t matter if the String gets choosen randomly or in the sequence the array is ordered.var arrayText: [String] = ["1", "2", "3", "4", "5"]This is how far I got. Just a normal local notification with everytime the same body text and only one trigger a day, but I want 3 triggers a day and not everytime the same body text. let center = UNUserNotificationCenter.current() center.requestAuthorization(options: [.alert, .sound]) { (granted, error) in if !granted { print("Something went wrong") } } let content = UNMutableNotificationContent() content.title = "text" content.body = "text" content.sound = UNNotificationSound.default let gregorian = Calendar(identifier: .gregorian) let now = Date() var components = gregorian.dateComponents([.year, .month, .day, .hour, .minute, .second], from: now components.hour = 8 components.minute = 0 components.second = 0 let date = gregorian.date(from: components)! let triggerDaily = Calendar.current.dateComponents([.hour, .minute, .second], from: date) let trigger = UNCalendarNotificationTrigger(dateMatching: triggerDaily, repeats: true) let uuidString = UUID().uuidString let request = UNNotificationRequest(identifier: uuidString, content: content, trigger: trigger) center.add(request, withCompletionHandler: { (error) in if let error = error { // Something went wrong } }) Help would be awesome. And thank you for every helpfull answerYours sincerelyTell aka. Relbot
Posted
by Relbot.
Last updated
.
Post not yet marked as solved
3 Replies
3.4k Views
I am trying to build an app where I am able to access(read/write) windows/mac shared folders in my local network with swift.Is there any possible way to do that with swift?There is an App in the App Store called "FileExplorer" https://apps.apple.com/de/app/fe-file-explorer-file-manager/id510282524 where you can access these shared folders, but I do not know how they programmed this and with which language. I also tried to access my shared folders via this App and yes it worked I can see my shared folders on my Phone.But there needs to be a way to do it with swift...I already tried different things(code bellow). In the code bellow I tried to access the shared folder of my second mac and write the Text "Write this text to the fileURL as text in iOS using Swift" into the file named "Test.txt" and after that I want to read the same file again.@IBAction func Button(_ sender: UIButton) { var uc = URLComponents() uc.scheme = "smb" uc.user = "user" uc.password = "password" uc.host = "ip-adress" uc.path = "document-directory" // Save data to file let fileName = "Test" let url = uc.url //let DocumentDirURL = URL(fileURLWithPath: "/Users/f/d/t/App/Assets/Apps/TestApp") let DocumentDirURL = try! URL(resolvingAliasFileAt: url!) let fileURL = DocumentDirURL.appendingPathComponent(fileName).appendingPathExtension("txt") print("FilePath: \(fileURL.path)") let writeString = "Write this text to the fileURL as text in iOS using Swift" do { // Write to the file try writeString.write(to: fileURL, atomically: true, encoding: String.Encoding.utf8) } catch let error as NSError { print("Failed writing to URL: \(fileURL), Error: " + error.localizedDescription) } var fullString: String = "" // Used to store the file contents do { // Read the file contents fullString = try String(contentsOf: fileURL, encoding: .utf8) } catch let error as NSError { print("Failed reading from URL: \(fileURL), Error: " + error.localizedDescription) } print("File Text: \(readString)") }If I run the code as shown, he always gives me the error "smb scheme is not supported" and then some additional errors that he can not write/read the file because he can not access it.When I change the code and only search on the device I am programming on and run the simulator to search for this file everything works fine. So I have problems with "smb".Thank you for every helpful answer.
Posted
by Relbot.
Last updated
.