How to transfer a file created in an ios app to the mac - ios

i'm starting the implementation of a feature for transfer some files (lets say csv files) created in an ios app to the mac.
But i've made some reading about the subject without anything conclusive.
So, can anyone point me a direction to follow in order to achieve my goal ? I need, somehow to access the files created on my app throw the mac

ITunes file sharing.
iCloud.
Network transfer. (This third party library works with iOS and OSX)

Related

How to read files of External Mass Storage Devices Without DocumentPicker? (iOS)

Just to give some context, there is an iOS app I'm building (in Xamarin) that requires the ability to fetch files (in an automatic way without having the user to navigate to the files and select them manually) that are stored on External Storage Devices (USB Sticks), and are connected (paired) to an iPhone/iPad.
Users connect a lighting cable to the iOS Devices, and plug their USB Sticks into this lighting cable. Here is an example of the cable that end users use to pair the USB Sticks with their iPhone/iPad, and the app then auto fetches these files from the USB Storage Devices.
The app then performs 2 functions:
It listens to notifications, for when a usb stick is paired with the iOS Device.
When it receives this notification, it then proceeds with querying the files on the USB Stick, and reads and processes the files. The app reads these files automatically and the user does not need to manually select these files
I've tried using External Accessory Framework, however that's only suitable for devices that you register with the MFi program.
https://developer.apple.com/documentation/externalaccessory
Notifications Center never seems to work (the Notifications that handle when a Device gets Connected and Disconnected, the delegates never get called), and I've tried using the Microsoft Helpers.
https://learn.microsoft.com/en-us/dotnet/api/externalaccessory.eaaccessorymanager.notifications.observedidconnect?view=xamarin-ios-sdk-12
I've also tried some 3rd party libraries, but haven't found anything useful.
It doesn't look Apple has any Api Available to auto query and read the files, without having to use a DocumentPickerController. I know this is because of the App Sandbox, and I cannot directly access the Removable Storage Devices.
Now for my questions:
Are there any 3rd party libraries anybody can recommend, that can help achieve most of the heavy lifting for this task? I'd prefer a library that's compatible with Xamarin, however if it's a native library (Swift or Objective-C Library, Cocoapods) I'm sure there is a binding I can use on nuget.
Does anybody have any snippets, or documentation, or can point me in the right direction here (Please feel free to post Swift, or Objective-c solutions here if you like)? Where should I look, which Apple Framework (iOS SDK) is most suitable to deal with this situation. And to summarise, is what I'm asking for at all possible on iOS, without having to jailbreak, or get around the App Sandbox?
Update
So I've tried the solution that #Saamer suggested:
Detect if USB is connected to iPhone device
Here is an example I wrote just to verify if the callback gets invoked, and the app can detect if a usb is plugged in.
CFNotificationCenter.Darwin.AddObserver("com.apple.mobile.lockdown.host_attached", null, (e, s) =>
{
MainThread.BeginInvokeOnMainThread(async () =>
{
var picker = await Xamarin.Essentials.FilePicker.PickAsync();
});
}, CFNotificationSuspensionBehavior.DeliverImmediately);
A file picker should immediately get invoked, and open up, once I plug the USB in, however this doesn't happen.
I'm happy for a solution right now which opens up a file picker, when the user plugs in a USB Device, and navigates to the root directory to start off with. So when the File Picker opens up the user should see this. Then they can select the files they want to transfer into the app.
I thought you needed to jailbreak but it seems unlikely, a solution is possible for <iOS 12
CFNotificationCenter's AddObserver seems to be usable for detecting when a device is connected using host attached and detached as shown here
Or if you don’t submit it to the App Store, you can use this
According to the Apple Docs
You can use the Files app and other supported apps to access files stored on external devices, such as USB drives and SD cards, connected to your iPhone.
Essentially you have to make your a "supported app". I have downloaded a free app called "Clockology" that I recommend downloading and playing with, which allows users to see data within the app as you can see below:
You generally use UIDocumentPickerViewController along with the right uttype to get the files from the Files apps or iCloud Drive, and you require activating the Key-value storage and iCloud Documents from iCloud entitlements capability. There's a lot of tutorials on UIDocumentPickerViewController usage, but you specifically want the capabilities that became available from iOS 13 onwards
This video from WWDC is the best example of getting to where you want. I also didn't find any 3rd party libraries that can help with this
——————-
Edit: If the app does not need to be distributed through TestFlight or the App Store, you can use IOKit and distribute through AppCenter, as long as you have the UDIDs of all the devices you need the app installed on (up to 100?)

Are there APIs to copy files from an iOS app's documents folder?

If I connect my phone to my computer, I can select the phone in the finder (Catalina) or in iTunes (pre-Catalina).
Once selected, I can copy files from my Mac to the document folder of an app I have installed on my phone.
My question is whether or not there are public APIs that allow me to do this programmatically...?
You are correct in that Apple is very discrete as to how they allow people to access their private APIs. The closest thing I could find was this https://www.appcoda.com/files-app-integration/
This tutorial shows you how to integrate the Files app to your app, and from there, with enough tinkering, you should be able to figure out how to export them directly from your said app. Hope this helps.

iOS File Retrieval - NSDocumentDirectory

I am working on a library with a very verbose logger module that, on iOS, writes xml logs to NSDocumentDirectory in a consistent file tree. I want to come up with a way for the user of this library to easily access these logs.
I know it is simple to programatically retrieve files from this directory, but is it possible to access this directory on an iOS physical device in any way from outside Xcode to retrieve these logs? I feel like I have seen it somewhere before, something in the manner of extracting the .ipa file and going into the package contents, but I could be wrong.
---------------------------------------------------------EDIT------------------------------------------------------------------
This (Browse the files created on a device by the IOS application I'm developing, on workstation?) is how to do it with Xcode on a device, but I have to assume that there is some way we can create that gets the logs off of a device for a user.
is it possible to access this directory on an iOS physical device in any way from outside Xcode to retrieve these logs?
It is possible to expose the Documents directory by enabling iTunes file sharing. When file sharing is enabled through this method, the contents of Documents directory would be visible to the user in iTunes, which can also be exported. The documents would also be visible for export through some third party desktop apps like iExplorer.
Here is the link to Apple documentation. You may also refer this thread to understand how this is done.
If you're using a simulator (apparently your task doesn't seem to need te real device) you are in luck.
You should go to a folder similar to this one:
/Users/[YOUR_USER_NAME]/Library/Developer/CoreSimulator/Devices/[RANDOM_HASH_YOU_SHOULD_DISCOVER]/data/Containers/Data/Application/[RANDOM_HASH_2_YOU_SHOULD_ALSO_DISCOVER]
Once there, with finder, you'll get the "documents" folder of the simulator and the app you're trying to retrieve your logs from.
You might say: I don't know which 2 RANDOM_HASHES should I go to.
Yes, you're right. If you have MANY simulators installed and or being used, it might be tricky to discover which one is the one you're trying to debug.
The same thing with your APP, your app will live in another RANDOM_HASH folder, and you should browse them, one by one, and then discover your documents folder.
Someone needed to solve this "mess" and created a Xcode Alcatraz Extension that leads you to the exact live simulator and APP you're debugging in any given moment, and then you don't need to guess which 2 random_hash paths you need to navigate to.
If Xcode + Alcartaz plugin extension manager is somewhat out of your reach, you might need to google it. It's not a difficult process.
PS: That magical Alcatraz Extension is named "XCodeWay" (in case you are brave enough to install Alcatraz onto your copy of XCode).
EDIT: Useful link to get Alcatraz: http://alcatraz.io/ Follow its easy instructions and you're done.
EDIT2: If Xcode cannot be used, then the last question in this other thread might come in handy: Browse the files created on a device by the IOS application I'm developing, on workstation?
(Still, an external application in your users machine will be needed )

How to access all the files(pdf, doc etc) in iOS?

How can I find out programmatically all the files present in iOS device and list them out to user? Also I need to download the file in my local application database?
How this can be achieved with Objective-C.
You cannot access all files in an iOS device outside the sandbox of the app. But there are other ways you can achieve this. What you can do is:
Access all the files in Gallery using UIImagePickerController.
Access all the user files in network- Dropbox/Google drive/iCloud. They all have separate public APIs that can be downloaded and used to download/upload files in network.
In this way, you can access most of the user files and use the same in your application.
Simple answer : you can't (on a non-jailbroken device).
Each app is launched is in own sandbox and can't interact with the others apps, expect using API provided by Apple for app-communication (ex: extension)
You should look at that Apple guide about App Sandboxing, which is valid for OSX and iOS apps.
The main difference between these two OS, as quoted directly from the doc :
iOS Note: Because it is not for user documents, an OS X container
differs from an iOS container—which, in iOS, is the one and only
location for user documents. In addition, an iOS container contains
the app itself. This is not so in OS X.
You cannot access all the files outside the app sandbox. But, if they are available at some shared location(network), you can use third party libraries to access them. For eg.
1. For iCloud- iOS provides inbuilt framework of UIDocument
2. For dropbox- DropBoxAPI is available
3. For Google drive- there is a separate library to access files in the drive.
Hope this helps :)

Where does iPad app store data?

I have an iPad app that downloads PDF and audio files. I though these might be in the .ipa file (I used this thread ipad - extract images from application?) but I didn't see anything there.
Is there some way to find where these might be stored on a Mac (after syncing)?
Normally in many apps the media files will be downloaded to documents directory of app, which is inside the sandbox for the app. Simply telling when you instal a app OS will create a sand box, and all the data will be inside this sand box and only that particular app will have access to this data. So you will not be able to copy data.
Hope this answers your question.
The IPA is an application only. Once it is installed on your iPad, it becomes a "package". It does contain the data within that package with some apps that store locally. There is no Apple supported way to get to this data directly. Think of it like this. The IPA is kind of like a blueprint for a program. Like a blueprint for a shelf, I could build the shelf but the books wouldn't be stored in the blueprint. Only the shelf. When you install the app, the iPad builds your "shelf".

Resources