Import core data from free app to paid app in Swift - ios

I have a free version of an app and a paid version. I'd like to give users the option to import their existing data from the free version into the paid version.
Currently the data is stored in Core Data.
I've looked at existing solutions across the internet and SO, the existing solutions suggest making a request from the free application to the paid application using a URL request that contains the data. (e.g. http://mobileorchard.com/lite-to-paid-iphone-application-data-migrations-with-custom-url-handlers/)
So my question is, how is best to implement the solution in Swift:
Is the URL method still the best approach?
Are there any code samples available?
One idea I've had is to convert the entire DB to JSON, then to make a request with the JSON payload and deserialise it into Core Data the other side. Create json string from core data and vice versa?

What I'd do is set up an app group that both apps can access. Put your data in the app group folder and access it from both versions. You don't need to copy it, just leave it where it is.
To do this:
Set up an app group in the "App Groups" section of the target settings in Xcode. Use the same app group for both versions.
Find the location of the app group folder with:
NSURL *groupURL = [[NSFileManager defaultManager]
containerURLForSecurityApplicationGroupIdentifier:
#"GROUP_NAME_HERE"];
Or in Swift:
//swift
let groupURL = NSFileManager.defaultManager().containerURLForSecurityApplicationGroupIdentifier("groupIdentifier")
Modify your Core Data setup code to put the persistent store file in the directory you found in the previous step.
Since you have existing apps, you probably want to move the existing data into the new app group directory. You'd do this by using migratePersistentStore:toURL:options:withType:error: to move the existing store to the new location from step 2.
At this point both apps can read and write the same directory. When people buy the paid app, the data is literally already there for it.

The keyword is Inter-App Communication. One straightforward way would be to write a URL scheme handler.
From: iPhone OS Programming Guide
Apps communicate only indirectly with other apps on a device. You can
use AirDrop to share files and data with other apps. You can also
define a custom URL scheme so that apps can send information to your
app using URLs.
Note: You can also send files between apps using a
UIDocumentInteractionController object or a document picker. For
information about adding support for a document interaction
controller, see Document Interaction Programming Topics for iOS. For
information about using a document picker to open files, see Document
Picker Programming Guide.
https://developer.apple.com/library/ios/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/Inter-AppCommunication/Inter-AppCommunication.html

Related

Using Document Provider extension without iCloud and DocumentPicker - non UI variant

I recently found some articles and information on using Document Provider extension introduced in iOS 8 to share data between iOS apps.
But almost all the articles and tutorials made use of either iCloud or DocumentPicker.
I am basically looking to save some huge amount of data by creating a, say, Sample.txt file in say an app A. I was wondering from an app B, can I read the contents of Sample.txt file leveraging Document Provider extension?
I would ideally not like to use iCloud and also want a seamless transition from app A to app B on click of a button without any kind of document picker, controller, etc.
Is this possible?
You can just use an App Group for this. Then you can access all files using [[NSFileManager defaultManager] containerURLForSecurityApplicationGroupIdentifier:#"groupname"].
Of course, all apps must have the App Group entitlement added.

Share data across multiple apps on iOS

I know there are quite a few threads on this, but it seems none of them would satisfy what I am trying to look for. Here's my constraints:
not a hack that uses private API/framework or undocumented
directory access that would run the risk of app being rejected
because of that
being able to share data across different
vendors / app developers
data can persist outside the lifecycle
of the app (even after app is deleted)
UPDATED: I was in general trying to stay away from using a 3rd party cloud-based service to achieve the goal as this would introduce additional external dependency. But if I have to, I was hoping it could satisfy this one constraint
being able to tell which iOS device it is communicating with. It shouldn't have to uniquely identify the device (which will go into that evil UDID discussion route as we all experienced ). But as long as it can differentiate among different iOS devices it should be fine.
I kind of need this too. I use Parse.com as the backend of all my apps — their free tier should satisfy your development needs.
Parse has APIs available for iOS, Android, Windows 8, OS X, JavaScript and .NET, with all your data available on the cloud on any platform (contrary to Core Data and iCloud). They also offer "Cloud Code," which is code you can execute remotely, to process information remotely and get the data back to your app.
You should definitely check Parse.com out for cloud storage for your app. In my experience, it really gets the job done.
For Data Persistence, I think you might want to take a look at FMDB (although if you decide to persist data locally, it will get deleted with your app, but it might help you, anyways). Core Data is an overkill in many cases.
Edit: Parse.com has an "Installation" class, in which all the devices that have your app installed get listed (wether they're running iOS or Android), uniquely, without you having to type any code.
Maybe this blog post by TextExpander authors will help:
Smile has responded to this by discussing the issue with Apple
engineers at WWDC, filing a bug (#14168862), and checking up on the
status of that bug. We also developed a workaround by storing the
TextExpander data in a new place. Reminders requires user consent to
store and retrieve data. Completed reminders are not normally shown in
its interface. Long-past reminders appear at the bottom of the
completed reminders.
TextExpander touch 2.1 (and later) supports storing shared snippet
data in a long-past, completed reminder. We produced an updated SDK
and kept our developers posted on its progress. Our final SDK was
ready within a few hours of the end of Apple's official iOS 7
announcement.
UPDATE (22.11.2013)
This might not be the best way to do that, because TextExpander's team recently had problems with the App Review Team.
Edit: this only works for apps with the same vendor.
You can save a password to the device's keychain, then access that password from any app.
Using the SSKeychain library...
NSString *service = #"com.yourcompany.yourservice";
// read
NSString *password = [SSKeychain passwordForService:service account:#"user"];
// write
[SSKeychain setPassword:password forService:service account:#"user"];
The password string doesn't have a length limit, so encode all your data as a string and save it there. The keychain entry will persist after the user deletes the app.
One of the ways to do this is using THRIFT. This is a data communication protocol that would need a back end server (private) and THRIFT can be compiled into many languages / platforms. There is a meta language to describe the data and then can be thrift compiled into many languages. Write the data definition once and can be used on many platforms.
More information at.
http://thrift.apache.org/
for me (I have 2 apps and a widged) the best solution is using SSKeyChain and do not forget to add Capabilities for your apps like here
or if you don't wanna to use 3rd party library you can use NSUserDefaults and set the group identifier like here but again do not forget to add the group identifier in Capabilities in AppGroups section for all your apps that have share data.

share core data between many users on app

I wanna develop an iOS app as the platform for many users. Is it possible to enable multiple users of my app to share resources on the same core data database?
The other alternative to iCloud (with the whole ownership issue) is to have an online server that stores the data remotely.
Then you can create a web service to store and retrieve the data from the server onto the device.
yes This can be done using a custom url scheme on the iphone by help of iCloud URL.
but it has some dark sides.If you use a custom url scheme, only one application "owns" the data. The other application would have to import data from the main application.
another method is system pasteboard i.e. clipboard. you can put stuff on it and then launch another application with a URL that tells the other app to check the pasteboard.There's also the system pasteboard .
for more information on custom URL scheme check this link

How can I transfer files from one application to another in the same iOS device?

I am writing an iOS application that performs conversion of a file saved by another application on the same device to another format. How can I transfer files from one application to another in the same device? Note that the files are non-textual files.
UIDocumentInteractionController is your friend.
Basically it works like this:
App 1 registers as being able to handle files of type XYZ
App 2 implements UIDocumentInteractionController and will give users the options to "send the file to App1" (I believe this has to be user activated)
App 1 implements -(BOOL)application:openURL:sourceApplication:annotation: and deals with the transferred file which will be saved in your Documents/Inbox directory. From there you can copy the file elsewhere and then manipulated it, making sure you clean up by getting rid of the original one saved on the Inbox folder.
Class reference available here
Document interaction programming guide available here
If you are developing both apps, you can store shared information in the keychain as long as your bundle identifiers conform to the same bundle seed id. See here for more info. Of course, if you are making both applications, you can use a URL scheme to pass in base64 encoded data as well.
Update: As rog said below, UIDocumentInteractionController is great, but it is only available for 4.2 and up, so you are cutting out a major portion of your users if you want to use it.

Import data from free app to paid app

I developed a free application where you can save some user data. Now I developed a paid version without any ads and some other new features. I would like to have the data from the free app version transferred! How can I achieve this the best way?
Edit: you can save data of a played game with some infos (gamescore, playername, date etc) via NSKeyedArchiver. You can see all your saved data in a table view. I would like to see these stored data in the paid version as well, but how can I share the data? The given answers don't seem to be the straightest way!
I've never done this before but the way I can think of on how to do this is by first getting the location of your file (if it is Core Data, it is in your Documents folder) and then depending on how you want to import data either:
Attach the file to an email and have the user email himself and then open the file with your app
Send the file to a server, which then the user can access and download the file
A good starting point is Apple's documentation on NSFileManager and this tutorial. This other one deals with preparing for sharing files and custom extensions.
Modify both apps to register for and handle custom URLs. Have the paid app try to send a request URL to launch the free app. If the free app handles the URL it can send data back using the paid app's URL.

Resources