USB file transfer on iOS - iphone

I want to write an app that stores its data in a file that can be retrieved and transfered to the user's PC. Does the iOS support file transfers over USB (through my app or through a mass storage device type feature). Preferably, I do not want to write a client for the PC to receive the files, and I want to prompt the user about new files when they plug in their device to their PC if possible. Do the iOS frameworks support these features?

Yes, this is available in newer versions of iOS (3.2 and above). See here for details on "File-Sharing Support" (explained for users in this KB article).

Related

How can I get the actual payload that the phone downloads when it installs my app from the app store?

I want to inspect the payload to answer questions like, is the whole __TEXT segment encrypted or just the __text section? The furthest I've gotten is, with a jailbroken phone, disabling SSL and then sniffing the download. However, that requires me to be on wi-fi, and on wi-fi, it downloads a pre-thinned version of the app that's larger. This is OK, except that I want to see what a fully thinned version looks like and see how close it is to the 100 MB WWAN limit. When I do find / -name '*.ipa', I don't find the app. So I guess it's immediately decompressing the .ipa upon download and then deleting it? But in that case, I don't know how to intercept it.
To get an iOS app .ipa (zipped bundle) file, just download the app from the App Store using iTunes on a Mac.
Added: Or download with Apple Configurator 2 on a Mac.
It might be easier on a Mac to sniff the ipa file read when installing an app from macOS iTunes to an iOS device (during a Sync).

Copying data from a free iOS version to a full version of my app?

How could a full version of my iOS app access / copy the database / settings from the free version ?
I'm thinking of providing a free version of my app and I can't see how people then buying the full version could get access to the data from my free version ?
All apps are isolated on iOS. They are installed as different iOS system users. One user do not have permission to access another user's files. In the old times, one common approach to address this problem is to enable iTunes file sharing. And tell users to manually copy the files.
Your better bet is to use the freemium model to sell your app. Make the app free, and unlock extra features via in-app-purchase. This way, your files, documents, settings won't need transferring to the pro version. The app itself becomes pro after unlocking.
Here is the guide from Apple: https://developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/StoreKitGuide/Introduction/Introduction.html (though not very intuitive).
The walkthrough here: http://troybrant.net/blog/2010/01/in-app-purchases-a-full-walkthrough/ is very helpful.
Last but not least, be aware that in-app-purchase is crackable. So please read: How to detect "IAP crackers"? , Verifying In App Purchase Receipt from Client , and https://stackoverflow.com/questions/4715414/apple-in-app-purchase-verify-receipt , verify in app purchase , In App Purchase Receipt verification within app .
Note that you are supposed to setup a server to validate iap receipts. Though it's doable from within the app, it's not safe. As far as I can remember, you can test in-app-purchase through StoreKit in iOS simulator v5.0, that should be Xcode 4.2. Before that, it can only be tested on a device.
#Dominik Hadl mentioned you can use a server to sync the file. The operation is usually complicated. If you prefer this idea, you can choose to use custom url scheme to launch one app from another to ease the operation. See steps below:
User press "Begin sync" in the free app to upload the file to your server
Server return the ID of the file to the free app
User press "Launch Pro App and Download my file", which leads to a custom url scheme to launch your Pro version (must be installed first), with the file ID
Pro version use the file ID to download that file directly
I think the only way how you can do this is syncing the data with some server, registering the device and the syncing the data back to the full version.
Because all iOS apps are sandboxed, they can't access any other application data (unless you have jailbroken iOS).
Since multiple apps can share the same iCloud container, I'd say that the best practice nowadays is to "simply" store the data in iCloud.
(I'm putting "simply" under quotes, because it is easy to put data in iCloud and take it out; but if you actually want to do syncing, you may need to do more than just "I'll load from iCloud and save to iCloud" in order to provide the best experience to the user.)

How can I make an SQLite database within an iPhone app available to the desktop?

My Android app stores its SQLite database on the SD card, so that when the phone is connected to a PC my desktop application can access it using an ODBC driver. Is a similar technique possible on the iPhone?
I know that iPhones do not have SD cards.
I use iTunes file sharing to access sqlite DBs on both the iPhone and iMac; iTunes moves the data. Enabled in the plist
As it has been said, it can't be done.
However what you could do is to embed a small Web Server into your App, and let the users to download the DB ( or even visualize it ), via WiFi on their homes/work. This approach would work for Windows/Mac/Linux users, and several apps are already doing it this way.
Good luck!
Not built-in, unfortunately. You'll have to roll your own Wi-Fi syncing system. You could use iCloud when it comes out in the fall, but that only works on Macs for now.
SQLite is present in the iPhone SDK, but there's no way to flag a file stored by your application as being visible to the file system when you plug your iPhone into the computer. As stated already by Chris Long, Apple's answer to this criticism is iCloud, which allows you to do synchronisation between arbitrarily many devices without cables, but that isn't available yet. The iOS 5 beta is available to registered developers and is publicly known to function with iCloud, so you could start developing now.
More painful temporary alternatives are to email the database out (there's a supplied way to do in-app email) or to expect your user to drag and drop the thing out of iTunes.

Any way to get your SQLite DB off iPhone?

I'd like to analyze the data that I have in my iPhone app after doing some tests, and the data is in a SQLite database. Is there any way for me to be able to copy it off of the iPhone back to my laptop? I'm not aware of any mechanisms that allows me filesystem style access.
You don't need to turn on file sharing in the app to get this, you can get the data for any app you've built via Xcode's devices window.
In recent versions of Xcode (8 and up, I think), open this with Window menu --> Devices. Find the device in the device list and look at the installed apps list for the device. Each app that you've built and installed on the device will be listed (and maybe some others). Select your app and click the gear menu below the list. Clicking the "Download" item on the pop-up menu will enable you to copy the app's documents, library, and other directories to your Mac.
NB: This will download an .xcappdata file. Right-clicking on that and selecting "Show Package Contents" will allow you to drill down to the actual sqlite file.
In Xcode 6 this is available at:
Window -> Devices -> -> Installed Apps.
Select your application.
Click the gear icon -> "Download Container"
You can also use iExplorer (for Windows or Mac, free version available) to browse and copy data on the iphone, without needing to jailbreak it.
If this is your own application you can enable Application supports iTunes file sharing (UIFileSharingEnabled) in your applications plist and your database is stored in your documents directory of your application you will be able to easily access your database through iTunes.
UIFileSharingEnabled (Boolean - iOS)
specifies whether the application
shares files through iTunes. If this
key is YES, the application shares
files. If it is not present or is NO,
the application does not share files.
Applications must put any files they
want to share with the user in their
/Documents
directory, where is
the path to the application’s home
directory.
In iTunes, the user can access an
application’s shared files from the
File Sharing section of the Apps tab
for the selected device. From this
tab, users can add and remove files
from the directory.
This key is supported in iOS 3.2 and
later.
Other Options:
Jailbreaking your phone, adding afc2add through Cydia and then using some type of iPhone Explorer application.
Jailbreak your phone and install ssh and use a tool such as CyberDuck.
There are windows alternatives to both of those applications.
If your iPhone is jailbroken, you can access it through SSH. A program like WinSCP (on Windows) can allow you to connect to the phone and give you filesystem access. Then you can navigate to where your application stores the DB.
There are also multiple Filesystem applications out there that might allow you to do this, but I don't think they will give you the full extent if your phone is not jailbroken.
You can also use iMazing (for Windows or Mac, free version available) to browse and copy data on the iphone, ipad or ipod

Accessing the iPhone filesystem from a Mac OS X application

I need to get a file (sms.db) from an iPhone connected to a Mac. I cannot find any way to access the iPhone filesystem searching in Apple Developers Connection...
I cannot SSH to the iPhone, the application I want to develop is meant to be used on non-jailbroken iPhones... And I would like to avoid some MacFuse modules I found googling, too... I would like to access the filesystem thru some sort of API, the simpler the better.
Thanks!
This api was developed to allow access to ios devices:
http://www.libimobiledevice.org/
There is no Apple-documented public API for accessing the entire filesystem on a stock OS iOS device. Even private OS/API calls won't work due to the app sandbox restrictions.
Xcode, iTunes, and probably other apps that take over the iTunes USB driver, are using a non-Apple-documented private API that only works over the USB connection.
It appears that DiskAid silences all nay sayers. That app seems to have complete access to the iOS device filesystem - whether or not iTunes is running and whether or not the files are shared. It even sees files down to root level. I am still trying to figure out how it is done. Oh yea, this is all on a non jailbroken device.
It is not possible for non-jailbroken iPhone due to file system restrictions.
You can't access the filesystem from an OSX application, the filesystem is locked down.
Phoneview (as mentioned in a few comments) does not allow access to the file system.
It uses public APIs to get things like call data and contacts, and allows you to copy files into one location on the phone.
From the FAQ: "PhoneView will store your files in the media section of the iPhone's disk"
Smoke and mirrors.
If it's for your own app, use the document sharing included in iOS 4.x. You can then have files show up in iTunes, and drop files from the desktop into your app's section.
A tutorial is found here:
Ray Wenderlich's nice tutorial