Post

Replies

Boosts

Views

Activity

Ad hoc App Distribution no Wifi connection?
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
5
0
668
Oct ’21
Security scoped Bookmarks iOS - Swift
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?
10
0
3.3k
Apr ’20
Read from smb server connected in 'Files' App
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
7
0
2.6k
Apr ’20
UIDocumentPickerViewController - didPickdocumentsAt
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
1
0
2.4k
Apr ’20
Read and Write on smb sever through app "Files"
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.
5
0
2.6k
Apr ’20
Pass on the part which doesn't fit into the UILabel
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.
10
0
4.1k
Dec ’19