34

I've been coding an app, and using CloudKit would make my life a lot easier. However, this app needs a web-base app along side the iOS app. I was wondering if there was any way I could use CloudKit with Android or web-based apps.

While this might not directly possible with an API provided by Apple, another possibility would be to use OS X Server for CloudKit. Would that be possible too/comply with Apple's Terms of Service for CloudKit?

Dharman
  • 30,962
  • 25
  • 85
  • 135
Zoyt
  • 4,809
  • 6
  • 33
  • 45

3 Answers3

36

Yes you can. Apple provides CloudKit JS, specifically designed for web services. I don't know much about Android, but I'm pretty sure it'll be not a hard challenge to run JavaScript.

Also CloudKit WebServices could be interesting for you.

EDIT advice and discussion

To give you an honest advice: Better use something "own". I currently work with a custom server on an AWS EC2 instance and am really happy.

You could, for example, write a really simple server using Node.js and connect a Mongo DB NoSQL database. CloudKit is actually not more than this.

This is really a simple task. I did this before and with some JavaScript experience and a few days Node exercises it is absolutely feasible; you'll write really nice servers very quickly.

In the end, when dealing with more customers, CloudKit will be more expensive, actually. And if you, why ever, must move to a different service, you will have trouble with CK, because you are not able to access the privately stored data.

Also, be sure that CKs concept fits your needs. I was in your situation a few months ago. As I read more about CloudKit and viewed some WWDC sessions, I more and more realised that it is not a BAAS as you would probably expect.

One example: You have no access control: private or public, thats it. There is a public database which everyone can access each resource in. And a private one for any user, which is inaccessible by others.

If you don't want to, or can't, do something on your own, you could simply use BAASBOX for self-hosted APIs or just any commercial BAAS.


EDIT II

To point that out again for anyone late in the game:

The private (per-user) databases are absolutely inaccessible for others – even you as the developer and operator can't access the, most probably encrypted, data to move to a different (maybe self-hosted) service.

You'd need to make an update and the app then needs to move the data to your new service on the users behalf – "device-ly".

These kind of processes are typically problematic because you'd need to run two services until all active users moved their data – which is REALLY hard to tell; your customer might be idle for some time and they'd be upset if their data is lost in void forever.

Ok – Cloudkit might continue until... Yeah, until then. So it might not be as problematic to do that kind of passive longterm-movement.

Julian F. Weinert
  • 7,474
  • 7
  • 59
  • 107
  • 1
    Since CloudKit now exposes JSON API, it would not be hard to write native Android library. The only problem would be authentication, which would have to be done over Webview or such. https://github.com/jaumecornado/DroidNubeKit – Legoless Aug 11 '15 at 21:47
  • 1
    Oh, that's sad to hear... But I think it's okay to utalize a web view for that in Android – isn't it? – Julian F. Weinert Aug 12 '15 at 07:50
  • what you mean 'No real access control; private or public, thats it.'? – János Oct 03 '15 at 10:50
  • 1
    There is a public database, which everybody can access each resource. And a private one for each user, which only this user can access resources in. You have no control of which user can acces which resource. This might be necessary for most API based apps, as I think. – Julian F. Weinert Oct 03 '15 at 11:02
  • 2
    Since 2016 CloudKit already supports shared database. Device-initiated data migration is indeed a problem but still the benefit outweights IMHO, especially when you have a low or zero budget. Apple now also provides a preliminary web service for CloudKit. CK is not going to die – strongwillow Sep 11 '17 at 13:23
  • 1
    Well, I think nobody said CK would ever die... Maybe poorly worded, but "until then" refers to a very (may infinitely) far future here, as implicated by the following sentence ;) It's simply a discussion and consideration of the pros and cons. Simply meant to maybe help people to decide which is the best for their particular case. But I agree, for too-low- and zero-budget and micro projects it's a really nice service. And well... Improvements are always possible and probable, but I didn't work on the platform for some time. – Julian F. Weinert Jun 24 '19 at 18:19
5

Use CloudKit JS to build a web interface that lets users access the same public and private databases as your CloudKit app running on iOS or macOS.

You must have an existing CloudKit app and enable web services to use CloudKit JS.

for Set up your app’s containers and configure CloudKit JS do following step by step:

  1. Create your app’s containers and schema.

    If you are new to CloudKit, start by reading CloudKit Quick Start. You’ll use Xcode to create your app’s containers and use CloudKit Dashboard to view the containers. Then create an iOS or Mac app that uses CloudKit to store your app’s data.

  2. In CloudKit Dashboard, enable web services by creating either an API token or server-to-server key.

  3. Embed CloudKit JS in your webpage.

    Embed CloudKit JS in your webpage using the script tag and link to Apple’s hosted version of CloudKit JS at https://cdn.apple-cloudkit.com/ck/2/cloudkit.js.

    <script src="https://cdn.apple-cloudkit.com/ck/2/cloudkit.js">

The CloudKit JS version number is in the URL. For example, 2 specifies CloudKit JS 2.0.

  1. Enable JavaScript strict mode.

    To enable strict mode for an entire script, put "use strict" before any other statements.

    "use strict";

  2. Configure CloudKit JS.

    Use the CloudKit.configure method to provide information about your app’s containers to CloudKit JS. Also, specify whether to use the development or production environment. See CloudKit for an example, and see CloudKit JS Data Types for details on the CloudKit.CloudKitConfig properties you can set.

Now you can use the CloudKit.getDefaultContainer method in your JavaScript code to get the app container (CloudKit.Container) and its database objects (CloudKit.Database).

ref lineks:

Cloud kit quick Start

Accessing CloudKit Using an API Token

CloudKit Web Services Reference

Accessing CloudKit Using a Server-to-Server Key

CloudKit Catalog: An Introduction to CloudKit (Cocoa and JavaScript)

iCloud Design Guide

Ref Page:

CloudKit JS

mohsen
  • 4,698
  • 1
  • 33
  • 54
4

Unfortunately CloudKit is only available for the Apple ecosystem. However, there are similar technologies called Parse and FireBase that allows you to do the same, but can be cross platform. However, they cost a lot more and are not client-side services.

NOTE - Parse's hosted services will be fully retired on January 28, 2017.

Puran
  • 984
  • 6
  • 15
josedlujan
  • 5,357
  • 2
  • 27
  • 49
  • OK. I guess not. I guess I was more asking about the OS X server part. – Zoyt Jul 03 '14 at 05:53
  • I would not compare Parse with CloudKit, CloudKit is a cutting edge cloud technology nowadays, Parse focusing more on business model, rather than fulfill developers needs – János Oct 03 '15 at 10:52
  • 2
    Problem with 3-party services is that they are closing, moving on or get acquired by other companies all the time! I liked Parse, but the same thing happened. Got acquired by Facebook and then it was shut down. – Maziyar Apr 14 '18 at 12:54
  • This is the problem with third party services. Parse went out of business leaving behind many developers and companies struggling to migrate to something new, re-writing their codes, and not everyone was able to do this migration. Realm was also another example which was bought by MongoDB, with a different price plan and needed re-write of entire apps to use it their way, and I personally lost so much of my work and had to shut down many of my apps which were dependent on Realm. CloudKit is at least going to stay as long as Apple is in business. There is nothing similar for Android or web. – zeeshan Mar 15 '23 at 17:39