Hello Everyone,
I am developing an IOS application for communicating with USB Flash Drive. For that I am going to use EAAccessory Framework. To be use EAAccessory Framework I need to mention protocol specification of USB Flash Drive (hardware) in info.plist file.
Looking forward to know generic protocol specification which will enable IOS application to communicate with most or all USB flash drives.
Files and Storage
RSS for tagAsk questions about file systems and block storage.
Posts under Files and Storage tag
200 Posts
Sort by:
Post
Replies
Boosts
Views
Activity
it can read the files before I replace container in xcode .
Has anyone encountered the same problem? and any solution?
Error: Error Domain=NSCocoaErrorDomain Code=257 "The file “Documents” couldn’t be opened because you don’t have permission to view it." UserInfo={NSUserStringVariant=(
Folder
), NSFilePath=/var/mobile/Containers/Data/Application/97D816A0-8B58-4E33-8455-3F19E0A9FBAA/Documents, NSUnderlyingError=0x281e650b0 {Error Domain=NSPOSIXErrorDomain Code=13 "Permission denied"}}
I was successfully able to get the callback for file reads for the files in my mounted folder. Now we need to implement some read protection on top of that, we need to only allow some specific applications to access the data through the File provider.
for that, we need to get the name or any information regarding the Application that requested the read.
one thing I've seen is the request.requestingExecutable , which is coming nil for all the applications trying to read the files in the mounted folder. But i do get applications name for the things done by finder (drag&drop and Copy paste) .
What are the ways I can get the reading Application names ?
and what could be done for implementing data leak features working in pair with the File Provider Extension ?
I am writing a code to capture the accelerometer data for one hour, it suppose to save in the iOS device first, and then I would like to upload to cloudkit. Here is my code.
import UIKit
import CoreMotion
import CloudKit
class ViewController: UIViewController {
@IBOutlet weak var accelerometerSwitch: UISwitch!
private let recorder = CMSensorRecorder()
private let cloudKitContainer = CKContainer(identifier: "iCloud.com.example.accelerometer-recorder")
override func viewDidLoad() {
super.viewDidLoad()
accelerometerSwitch.addTarget(self, action: #selector(accelerometerSwitchValueChanged), for: .valueChanged)
}
private func saveDataToAppFolder(data: [CMSensorRecordingData]) {
let fileName = "accelerometer_data.dat"
let fileManager = FileManager.default
let documentsDirectoryURL = fileManager.urls(for: .documentDirectory, in: .userDomainMask).first!
let fileURL = documentsDirectoryURL.appendingPathComponent(fileName)
let jsonData = try! JSONEncoder().encode(data)
try! jsonData.write(to: fileURL)
}
@objc private func accelerometerSwitchValueChanged() {
if accelerometerSwitch.isOn {
recorder.recordAccelerometer(forDuration: 3600.0) { sensorData in
if let sensorData = sensorData {
// Handle the recorded data
saveDataToAppFolder(data: sensorData)
uploadDataToCloudKit(data: sensorData)
} else {
print("No accelerometer data recorded")
}
}
} else {
// No need to stop recording since it will stop automatically after the duration
}
}
private func uploadDataToCloudKit(filePath: String) {
let fileURL = URL(fileURLWithPath: filePath)
let data = try! Data(contentsOf: fileURL)
let record = CKRecord(recordType: "RecordedData")
record["data"] = data
let database = cloudKitContainer.publicCloudDatabase
database.save(record, completionHandler: { record, error in
if let error = error {
print("Error uploading data to CloudKit: \(error)")
} else {
print("Data uploaded to CloudKit successfully")
}
})
}
}
Anyone can help to fix the error. Thanks a lot.
I have folder monitoring code using makeFileSystemObjectSource.
The events are triggered for everything else, but not for when I edit a file with nano terminal command.
Am I doing something wrong? Is it a bug? Is this intended and unfixable?
Code sample:
monitoredFolderFileDescriptor = open(currentlyMonitoredPath, O_EVTONLY)
folderMonitorSource = DispatchSource.makeFileSystemObjectSource(fileDescriptor: monitoredFolderFileDescriptor, eventMask: .all, queue: .main)
folderMonitorSource?.setEventHandler {
// ...
}
folderMonitorSource?.setCancelHandler {
// ...
}
folderMonitorSource?.resume()
Good day ,
thank you very much for the #virtualization article
I have now managed to create a linux(#debian 12/bookworm) virtual machine
I now have the following questions.
How can i increase the size of the GUI Linus VM.bundle from 68.72G to 150G?
Unable to obtain an IP V4 address to a bridge (have intall brige-utils package) - can get IP v6 address without any problem.
my #bridge setup is
auto br0
iface br0 inet dhcp
bridge_ports enp0s1
bridge-stp on
bridge-fd 0
Unable to ping the host from the virtual machine , but able to ping vms from the host - no firewalls are running, how can i enable icmp from vm to host and host to other containers.
my target is to run lxd/incus containers to test few of my applications in apple silicon
I am now able to run lxd/incus without any problem. however i am not able to access the application that are running in the containers, provided I am logged into the linux vm which beats the purpose of publishing the my apps, few of the services are IBM informix REST API / Nginx .
My #requirement is
1, increase the size of the vm image.(#GUI Linux vm.bundle)
2. Obtain #ip address V4 for br0
3. Run #lxd / #incus containers
4. #icmp comms between host / vm / containers
Please let me know if there are possibilities to achieve my requirement.
Thank you
Hi all,
I’ve never used NSFileCoordinator class, simply because I haven’t had any need for it until now. And now that I’m about to need it rather soon, I’m trying to get a grasp on it, but it does’t go very well so far. Even though the documentation reads pretty clear, I don’t seem to get it correctly. Also, I haven’t found any example online, which would be of any value to me, so I’m taking my chances here. In order to begin to understand it, I’ll start with the simplest real case scenario, for which I don’t even understand yet whether NSFileCoordinator is the way to go.
Let’s say, I have a bunch of directories in a parent directory (so, all are at the same level in the file system hierarchy), which I want to compress and pack in a ZIP archive (for example) programatically (e.g. using libarchive). After selecting which directories to zip, I’d like to ensure that once the zipping operation has started, any changes to all files and directories in the hierarchies of selected directories to be packed will stay unchanged, until the zipping operation is complete. That means, no file anywhere in the hierarchies should be modified in any way and no directory or file anywhere in the hierarchies should be added, deleted or moved.
I thought I would achieve this by using one NSFileCoordinator and a bunch NSFileAccessIntent objects, each for every directory at the top level of the hierarchies. The intents will be for reading without changing, because that’s what I want to do; just to read those directories and files (and zip them) without making any changes to them. The code would be something like this (I want to do the operation asynchronously):
NSMutableArray *intents = [NSMutableArray arrayWithCapacity:[sources count]];
for (NSURL *source in sources)
[intents addObject:[NSFileAccessIntent readingIntentWithURL:source options:NSFileCoordinatorReadingWithoutChanges]];
NSFileCoordinator *coordinator = [[NSFileCoordinator alloc] initWithFilePresenter:nil];
[coordinator coordinateAccessWithIntents:intents queue:[NSOperationQueue new] byAccessor:^(NSError *error)
{
// Do the zipping here.
}];
It looks simple and straightforward, but it doesn’t really work as I thought it would. Once the operation is started, I can modify files and directories the way I described above, from within the same application/process, as well as others (using NSFileCoordinator approach), like Finder.
Hence, I’d really appreciate if someone can point me in the right direction. For example, what needs to be done to achieve this simple example I described above. Once I get some pointers, I may start understanding those classes and documentation in the right way and work myself through more complex examples and use cases.
Thanks for any insights.
-- Dragan
Prior to Sonoma 14.0 and Xcode 15.0.1 my custom class was encoded in a consistent pattern that I exploited to append the file many thousands of times. Now, the encodings are of a seemingly random pattern that cannot be exploited to append. This may be a result of efforts to make the encoding more efficient or virtually any other reason.
My questions are:
how do I revert to the previous JSONEncoder while using current OS & Xcode versions?, i.e, what files and in what locations do I restore?
is it likely to be sustainable if I did so?
It has been previously noted that atomic files are not "append able" which is why I used JSON in the first place.
Any info or suggestion is appreciated. Thank you.
Hi, I'm a new developer using Xcode to develop an app for a university research project. Once I publish the app I need users to fill in text fields and then for the app to store that data somewhere where I'll be able to access it. How would I go about doing this, and is there a tutorial I can follow to make the app able to do this?
My computer crashed recently, and afterwards a lot of my files wouldn't open and it said it was because of "nsfileprovidererrordomain error -2005." I tried looking up what to do but nothing online really made sense and it was not offering me a solution to the problem. What should I do?
I'm getting the following error message on on iOS 17.1 and Xcode 15.0.1
The view service did terminate with error: Error Domain=_UIViewServiceErrorDomain Code=1 "(null)" UserInfo={Terminated=disconnect method}
In my info.plist I have given access to all file related permissions to rule out any issues
Supports opening documents in place -> YES
#if os(iOS)
.fileImporter(isPresented: $isiOSFilePickerShown, allowedContentTypes: [.item], allowsMultipleSelection: false, onCompletion: { result in
do{
guard let selectedURL: URL = try result.get().first else { return }
guard selectedURL.startAccessingSecurityScopedResource() else {
return
}
//Some operation with selectedURL
}
catch let e{
print("error reading file \(e)")
}
})
#endif
My app iterates over all folders on disk and queries metadata of each folder.
After Sonoma was released, a bunch of users (but not all) complained that the app has become very slow or stalls indefinitely while performing the scan.
I have narrowed down that the delay occurs in POSIX open() function, and the folders it stalls on are folders inside ~/Library/Containers and ~/Library/Group Containers, which store data of sandboxed apps.
My app is not sandboxed itself, and the problem doesn't happen on all Macs, only on a subset of Macs.
I read it in WWDC transcripts that in macOS Sonoma, Apple has introduced additional privacy access control to these particular folders, and my guess is that the delays and stalling are related to this new macOS feature.
Is anyone else is experiencing this problem? Can I do something to work around this problem? Or is this a bug of macOS Sonoma and I should report it to Apple?
Hello,
I'm working on an iOS app called "scribe-frontend-ios," and I'd like to change the default folder name that the app creates in the Files app on iOS. Currently, when the app saves files to the Files app, they all go into a folder named "scribe-frontend-ios." However, I want to just call this folder Scribe.
I've tried modifying the Info.plist file in my Xcode project by adding the "NSFileProviderServiceName" key with a custom folder name, but it doesn't seem to have any effect. I've also set "LSSupportsOpeningDocumentsInPlace" to true to indicate that my app supports opening documents in place.
Can someone please provide guidance on how to change the default folder name for the app in the Files app? Is there a step I might be missing, or is there another way to achieve this?
Any help or advice would be greatly appreciated.
Thank you!
Hello,
There is something i do not understand about TCC:
I have allowed Terminal app to Full Disk Access.
I was able to open my current user's TCC.db file with sqlite3 from terminal.
I was able to delete entries in access table with sqlite3.
I had no errors, but these changes haven't been applied.
My question is why was I able to modify TCC.db file ?
Is there a specific thing to do to flush privileges ?
I have a second question:
When an application fires an NSOPenDialog on a cocoa application, the selected file access rule bypasses TCC. This is normal because this is an intent from user.
But this file access seems to be stored somewhere because if i reboot computer, my cocoa application can read this file again, without NSOpenDialog opening. I have tried to look in current user's TCC.db file but i did not found anything. My question is: where is this information stored ?
Thanks
I'm from china,english is not well,in UIDocumentPickerViewController inMode:UIDocumentPickerModeOpen select the storage device path directoty ,I get the path string :file:///private/var/mobile/Library/LiveFiles/com.apple.filesystems.userfsd/D33D4EE8-E75C-3B21-8126-C5FD453D3D5B/ ,then use it will pop up UIDocumentPickerViewController window, ,there are any other api to obtain this path and to write and read storage device and no pop up viewcontroller?like iFile use api no UI.
I have an app that needs to read a file the user selects from an Open dialog.
Right now it works fine on my machine (of course), but doesn't let my app access the file on other systems.
I code signed it using my Apple Developer ID. I have notarized it. I have checked it all with the notaryTool and it shows NO ERRORS and as far as I can tell, no warnings either.
Here's the entitlements:
com.apple.security.cs.disable-library-validation
com.apple.security.cs.disable-executable-page-protection
com.apple.security.app-sandbox
com.apple.security.files.user-selected.read-write
What could I be doing wrong?
Thank you,
-Chilton
Hi,
I have a developer tool that often needs access to files outside of the file the user has selected. For example, they can easily select a file that contains a reference to an include file NOT in the current folder or a descendent. But I still need access to that file.
How do I handle this, on the latest version of MacOS? Right now it just fails to give me access to the file, making it look like our Mac version is WAY BEHIND the Windows version.
Oh and this needs to be in the App Store eventually, but right now I need it to be available outside of it, so I have to use my Developer ID and notarized. I think I've got all of that nailed down, but I'm still having file permission issues.
My entitlements currently (which doesn't work):
com.apple.security.cs.disable-library-validation
com.apple.security.cs.disable-executable-page-protection
com.apple.security.app-sandbox
com.apple.security.files.user-selected.read-write
Thank you,
-Chilton
I am following the instructions at : https://developer.apple.com/documentation/xcode/installing-additional-simulator-runtimes.
When I run
sudo xcrun simctl runtime add "/Users/<user_name>/Downloads/iOS_17.0.1_Simulator_Runtime.dmg"
I get an error :
(1) Operation not permitted
Accessing '/Users/<user_name>/Downloads/iOS_17.0.1_Simulator_Runtime.dmg' requires Security & Privacy approval.
I get the same error even if
Xcode in the Applications folder or the Downloads folder.
If the .dmg is mounted or not.
How can grant access to the .dmg ?
Hello,
It is possible to restrict access to Desktop or Documents folder with TCC for a given application in macOS Preferences.
For example Terminal is not allowed to access Documents folder. But i have see it is possible to write files or to create directory from Terminal !
I don't understand this behaviour. Is there a particular reason ?
Thanks
My app saves the file URLs obtained from UIDocumentPickerViewController as bookmark data and reads them on the "history screen".
In the "history screen", whenever viewWillAppear is called in ViewController, URLByResolveBookmarkData is called for all bookmarks to check if the file has been deleted or moved. (Please see code below)
- (void)refresh {
NSManagedObjectContext* context = self.managedObjectContext;
// read all bookmarks
NSArray<HistoryItem*>* all = [self histories];
[all enumerateObjectsUsingBlock:^(HistoryItem * _Nonnull item, NSUInteger idx, BOOL * _Nonnull stop) {
BOOL isStale;
NSURL* url = [NSURL URLByResolvingBookmarkData: item.bookmark
options: 0
relativeToURL: nil
bookmarkDataIsStale: &isStale
error: nil];
if(url == nil) {
// file is deleted
[context deleteObject: item];
} else {
item.filename = url.lastPathComponent;
if(isStale) {
// file is moved
NSData *data = [url bookmarkDataWithOptions: 0
includingResourceValuesForKeys: 0
relativeToURL: nil
error: nil];
if(data != nil) {
item.bookmark = data;
}
}
}
}];
[context save: nil];
}
Then, after many calls to viewWillAppear, calling startAccessingSecurityScopedResource on the URL obtained by URLByResolvingBookmarkData returns NO.
I suspect that URLByResolveBookmarkData is consuming some resources, because the problem reproduces even if I change the code inside the block to only call URLByResolveBookmarkData, and it doesn't reproduce when I empty the block.
Does URLByResolvingBookmarkData consume any resources? If so, how do I release the consumed resources?
OS: iOS 15
Xcode: 15.0