share core data between many users on app - ios

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

Related

Multiple iOS apps with single database and single log on

I created multiple apps in android with single database (Content provider) , single log on (which means if i login in one app it should work for all , if I logout from one app it should logout from all other apps) , I have to open one app from another app and every day I have to update all my off line data to server (it should happen particular time on every day ) . Now I am going to port this system (all apps) to iOS , is it possible in iPhone ? And I am not going to submit this apps to app store.
Yes it is possible. You would need to save your database at container url which you can get using:
- (NSURL *)containerURLForSecurityApplicationGroupIdentifier:(NSString *)groupIdentifier;
The groupIdentifier param needs to be same for all the apps and needs to be configured inside Target->Capabilities->App Groups.
Once you have configured same appGroup for each application, you can use above method to save database at the location, provided by the method. That way the same DB would be accessible to all the apps.
There is NSUserDefaults init methid which takes suitename(appGroup), and creates a shared UserDefaults, which can be used for your single log-on purpose.
- (instancetype)initWithSuiteName:(NSString *)suitename;
Refer:
containerURLForSecurityApplication
NSUserDefaults
You can use AppGroups to share files between your apps. Using AppGroups you can implement a Single Sing-On functionality by storing a Bool in your database that each of your apps have access to that indicates whether the user is currently signed in or not and act accordingly when opening one of your apps.

Import core data from free app to paid app in Swift

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

Is it possible for an app to obtain the information about how long the user uses another app?

In iOS, is it possible for an app to get the information about how long the user uses another app?
In iOS each app runs in its own sandbox and cannot see data from other apps, even apps from the same publisher. An app can access special shared data, like photos from the album or contact data, but it is not possible for an app to directly access information like you have mentioned.
No, there isn't. There is no way to fetch data from another app, this is part of the App Sandboxing principle.

forcing a file to open in predefined application in iOS

I am trying a simple web app which downloads files from internet and saves on iPad. Theses files are of .pdf,.xls,.doc, etc format. Now, I want to assign a default application to open a specific file type. (Say Adode reader for pdf file, Some image viewer app for image files etc). I dont want my app/os to decide which app the file should open in. Instead, if assigned app doesnt exists then it should give me a message that no such app found. Is it possible to do?
With a web app you cannot do such things.
If you go native, you can use Custom URL Schemes (see http://developer.apple.com/library/ios/#DOCUMENTATION/iPhone/Conceptual/iPhoneOSProgrammingGuide/AdvancedAppTricks/AdvancedAppTricks.html)
But with Custom URL Schemes, you only are able to pass a view parameters. If you want more, UIPasteboard is recommended.
Apps are sandboxed. You cannot access other apps, nor their data!!!
But on native apps you can pass over data with pasteboard, call a custom url handler, pass a few parameters to cause the other apps to process your data.
Often App developers, like camera+ offer a documentation for the usage of their custom url schemes (Camera+ URL Schemes API)

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