Can you share data with NSPersistentCloudKitContainer between multiple apps? - swift

So my question is as written in the title if you could use NSPersistentCloudKitContainer to share data between different apps like if you have a different app for iPad, a different one for iPhone and a different one for Mac and if possible how would you do that?
Thanks in advance!

Yes, you can, even across different platforms (macOS, iOS). I have done that several times, actually. All it takes is the same iCloud bundle ID. Click on Capability to select iCloud. Turn on the CloudKit checkbox button. Then select a specific bundle ID below.
If you are going to use the same cloud container, you must be careful with the data types you use. For example, you shouldn't save UIImage or NSImage there because they are not exactly compatible with each other. In this case, you should save an image as Data.
Addition
When you want to use a specific cloud container other than the (default) one that your project has automatically created, make sure you specify it in accessing the cloud database. That's the same for macOS and iOS.
let cloudContainer = CKContainer(identifier: "iCloud.com.tomato.Eltomato")
let publicDB = cloudContainer.publicCloudDatabase

Related

How do I save text to a flutter web app's website subdirectory and then have the app read it later?

So I have an app on website.com/app
I want the app to save a text variable, and then have the app parse the same text variable to use it later, in a different session, or even on a completely different computer.
It would be even better if website.com/app2 could access the file, but the first case is fine as well.
Would shared preferences work for this, or does every user have one shared preferences? Or does it get wiped when the website is closed?
Thanks!
What you are talking about is cross device sharing. SharedPreferences can only help you in case of a single device.
If you want to persist your value against a user across devices, you need to use some backend storage mechanism. Something like firestore which is beginner friendly.
More on it here.

Icloud Sync between 2 app having different app identifier

I have an app which has different app identifier for iphone and ipad and i want to sync both of them using icloud, is it posible to use different app identifer for same container in icloud.
Yes, it is possible to sync data between different apps using iCloud (different apps always have different app IDs, don't they?). Use the entitlements of your apps to specify to which containers they should have access. Then use a common container to store and sync your files.
Update on 10/30/2013 on request of Dinesh Kaushik:
Open your project in Xcode and select the project in the ProjectNavigator
Go to the "Capabilities" Tap (Xcode 5) of the project and find the iCloud section (should be right on the top)
Here you can specify all Ubiquity Container the app should have access to.
To share data between apps they need to share a common Ubiquity Container. Thus add at least one Ubiquity Container that is used by
all participating apps. The easiest way to just one Ubiquity
Container (of course the same in each app)
When "connecting" to iCloud you use the following code to get the Ubiquity URL:
NSURL *cloudURL = [[NSFileManager defaultManager] URLForUbiquityContainerIdentifier:nil];
Using nil as identifier will return the URL of the default Ubiquity Container. Use a concrete ID to get the URL of another Ubiquity Container.
The Ubiquity Container is basically just a folder on your device. The iCloud Service will observe this folder and transfer all changes to the same folder on other devices.
From my experience there is one golden rule about iCloud:
DONT USE IT!
I am serious. iCloud is unstable and unreliable. Your app might crash from time to time and you will never find out the concrete source of the problem. Users will ask why syncing does not work from time to time and blame you and your app for the poor performance.
iCloud might be OK for simple KeyValueStore but anything else is a mess. Do not wast your time. Use another Cloud service like Dropbox instead.

share data between two separated applications in iPhone

I'm developing two separated applications but there is a plist file for one of those app contains data that I need it on the other one.
is there is any way to get data? in case yes please show me some sample code? what about the NSUserDefault could it be useful?
NSUserDefault will not work. You need to create a custom URL scheme for your app and then you will be able to pass some data to your another app.
follow these url's you will find what you want.
http://www.tutoplanet.com/android-tutorials/ios-sdk-working-with-url-schemes/
http://iosdevelopertips.com/cocoa/launching-your-own-application-via-a-custom-url-scheme.html
NSUserDefaults will not help you at all. Your applications are each sandboxed separately and have access to very little other than their own data.
You can, however, open a file from one app in another. You can see more about that here.
Other Resources
Apple Approved iPhone Inter-process Communication
2-way app integration on the iPhone: How it works

iPhone :Can we add more than One application in a Single application

I do have an Idea to integrate with my application. I want to create multiple application within a single one application.
Like
and application containing Weather application as well as image processing application + camera based application.
I want to know Is this thing possible with iphone application?
Please suggest me is this possible with iPhone app development and is it allowed by apple or not.
thanks for your suggestion in advance.
Consider these things as features. Weather information is a feature, image processing is another and camera in another. You can create any number of features in your app. If that is what you have meant by application then that is technically possible and seems also OK with Apple. This is not 3 different applications, rather it's one application with three different features. No matter how many features you have, iOS will treat that as a single application(a single app bundle with a single executable file).
But if are asking whether there is any way to combine separate applications(separate projects, separate app bundles with separate executables) then that is not possible.
Note: Personally I think adding completely different features in a single app is not a good idea.
Go to App Store and search for this app, App Tool Box - All in One. It's exactly the same structure as you mentioned in your post. And it only costs $0.99.
Sure, you can do it. I don't think Apple has anything against an app that does more than one thing. As long as none of those things breaks any of their rules.

Store and manage files between two applications?

It is possible to store some application files and share it with another application?
Can application A remove files created in such shared space by application B?
In general, no. There are a few things you can consider.
All apps can read/write/share photos via the user's photos library.
Some apps have been known to share data via the address book. That is, they put data in a special address card which can be read by multiple apps.
If the apps have matching App ID bundle seeds, they can access the same keychain entries. I'm not sure how much data can be stored in the keychain, but it is possible to share data this way.
Apps can pass data to each other via a launch URL. That is, one app can ask iOS to open a URL that launches the next app, and that URL can have parameters that pass data.
No, each application has its own sandbox. Only way to communicate is to use custom URLs to call the other application or have a 'middle man' (eg a computer).
As an alternative to RupertP's answer, the only real work-around is to use a globally-accessible server. A lot of iOS devs use MobileMe's iDisk (not free) or DropBox (free for a limited account).