react-native-cloudkit-storage
TypeScript icon, indicating that this package has built-in type declarations

0.1.1 • Public • Published

react-native-cloudkit-storage

Like AsyncStorage, but syncs with Apple's CloudKit

Installation

npm install react-native-cloudkit-storage

Usage

import CloudKitStorage from 'react-native-cloudkit-storage';

// Must call this!
CloudKitStorage.registerForPushUpdates();

await CloudKitStorage.setItem('itemName', JSON.stringify({ key: 'value' }));
const json = JSON.parse(await CloudKitStorage.getItem('itemName'));

// Handle remote events
CloudKitStorage.addListener('delete', ({ key, value }) => {
  console.log(`Deleted item ${key}`, value);
});
// Remote events only - not called when calling setItem
CloudKitStorage.addListener('change', ({ key, value }) => {
  console.log(`Changed item ${key}`, value);
});

Set Up

Open XCode.

Click the top item in the files list (your project). In the Signing & Capabilities tab, click + Capability, then iCloud.

Scroll down to the iCloud section, then click the CloudKit. It may ask you to set your team.

Under containers, click the + button. Pick a name in the form iCloud.org.{team name}.{project name}. Ensure it is checked.

Next, open AppDelegate.m and add the following,

#import "RCTCloudKitStorage.h"
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
{
  BOOL didHandle = [RCTCloudKitStorage
                    didReceiveRemoteNotification:userInfo
                    fetchCompletionHandler:completionHandler];

  if (!didHandle) {
    completionHandler(UIBackgroundFetchResultNoData);
  }
}

It can take a day or so for the CloudKit database to fully set up. If you're having issues, wait a few days, and check again.

Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

License

MIT

Dependencies (0)

    Dev Dependencies (19)

    Package Sidebar

    Install

    npm i react-native-cloudkit-storage

    Weekly Downloads

    0

    Version

    0.1.1

    License

    MIT

    Unpacked Size

    33.8 kB

    Total Files

    19

    Last publish

    Collaborators

    • jacobp100