Git Product home page Git Product logo

icloudaccess's Introduction

iCloud Access

Author: Drew McCormack
Created: 18th January, 2014
Last Updated: 18th January, 2014

iCloud Access is a simple class that makes it easier to work with iCloud, hiding details such as file coordination and metadata queries. It is much more like accessing a web service with a Cocoa networking class, which most developers are more used to.

The class was originally developed as part of the Ensembles Core Data Sync framework, and has been extracted for easier integration in projects not using Ensembles.

Install

Just drag the ICACloud.h and ICACloud.m files directly into your Mac or iOS Xcode project.

Using ICACloud

The methods of the class are fairly self explanatory, mirroring NSFileManager to some extent. One big difference is that most are asynchronous, with a completion callback block. The completion block includes an error parameter, which should be checked. If it is nil, the operation was successful, and if an NSError is supplied, it failed.

Cloud paths are relative to the ubiquity container, but you can optionally supply a relative path to a root directory in the container. This directory, and intermediate directories, will be created automatically if they don't exist.

You should check the isConnected property to make sure the user is logged into iCloud before using the class.

Here is a simple example of using the ICACloud class.

ICACloud *cloud = [[ICACloud alloc] initWithUbiquityContainerIdentifier:@"XXXXXXXXXX.com.mycompany.cloudtest"
    rootDirectoryPath:@"Path/To/Data/Root"];
if (cloud.isConnected) {
    [cloud createDirectoryAtPath:@"Subdirectory" completion:^(NSError *error) {
        if (error) {
          NSLog(@"Failed to create subdirectory");
          return;
        }
        
        [cloud uploadLocalFile:@"/Users/me/Downloads/LocalImage.png" 
          toPath:@"Subdirectory/CloudImage.png" 
          completion:^(NSError *error) {
          if (error) NSLog(@"Failed to upload: %@", error);
      }];
  }];
}

icloudaccess's People

Contributors

drewmccormack avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.