DropKit Documentation

1.1

What is DropKit?

My Drop.io iPhone application, Droppler, is built on top of my own library of classes that provide an Objective-C wrapper around the Drop.io API. I am releasing this library, which I have dubbed DropKit, to the world as open source code, so that Mac OS, iPhone and iPod Touch developers can create great apps using Drop.io.

In particular, DropKit easily solves a problem vexing iPhone developers -- namely, how to get data created on the iPhone off of it, storing it somewhere where other users can get to it? Prior to the release of the DropIO API, developers were forced to roll their own solutions, building filesharing code or mini-servers into their iPhone apps. With DropKit, developers now have a simple API for storing iPhone data on the web.

DropKit allows iPhone and Mac OS developers to easily create apps that interface with the Drop.io API, allowing those apps to easily do things such as: Now, because of limitations in the Drop.io API, it is currently not possible to read back the original file that you store on Drop.io, unless you receive special permission through your developer API key from Drop.io. You must read back a version of the file that has been converted for use within your drop's web pages. If you are granted that special access, however, you could use Drop.io to read and write your application's data. For instance, your app could persist its data across iPhone OS restores or application updates.

Read more about Droppler, the drop.io iPhone app.

Click here to access the DropKit source code.

Getting Started with DropKit

First, you must sign up for a Drop.io API key, which the Drop.io API uses to uniquely identify your apps and grant or revoke them access privileges.

Next,  you must download the DropKit source code. The source code is maintained in a Mercurial repository, so you must first install Mercurial if you don't already have it. Then use Mercurial to clone DropKit onto your machine somewhere, such as a folder within your new XCode project.

Within XCode, add the DropKit source files to your project.

  1. Register your API key, typically in your app delegate's applicationDidFinishLaunching: method.
        [DropIO setAPIKey:@"...yourAPIKeyHere..."];
    

  2. Get a reference to an existing drop.io drop, or create a new drop.io drop. To get a reference to an existing drop, call one of the DropIO class's findDrop... methods, like so:
        NSError* error = nil;
        DropIODrop* addedDrop = [DropIO findDropNamed:@"myDrop" 
                                            withToken:@"yourTokenHere" 
                                                error:&error];
    

    To create a new drop, call one of the DropIO class dropWith... methods, like so:
        DropIODrop* newDrop = [DropIO dropWithName:@"myNewDrop"
                                       andPassword:@"mySuperSecretPassword"];
        NSError* error = [DropIO lastError];
    

    Check for any errors returned from the drop.io API. Use the kDropIOErrorAction, kDropIOErrorMessage, and/or kDropIOErrorResult key constants to access the error values returned from drop.io in the NSError.userInfo dictionary, like so:
        if (error != nil)
        {
            NSString* msg    = [[error userInfo] objectForKey:kDropIOErrorMessage];
            NSString* action = [[error userInfo] objectForKey:kDropIOErrorAction];
            NSString* result = [[error userInfo] objectForKey:kDropIOErrorResult];
            NSString* desc   = [error localizedDescription];
            
            // Use error strings here...
        }
    

  3. Get a reference to existing assets, or create new assets on the drop.
    1. To load all assets in the drop, call , like so:
          [myDrop loadAllAssets];
      
      * Note that in DropKit 1.1 you must first check to see if the drop is small enough to load all the assets. Some drops may contain thousands of assets and thus loading all assets is not an option. Call the new method [DropIODrop canLoadAllAssets] to check if loading all assets is feasible.

      If you cannot load all assets at once, call [DropIODrop loadAssetPages:] instead, passing a Cocoa NSIndexSet object as the parameter. In the drop.io API, assets are loaded from a drop in "pages". Currently the API defines a "page" as a set of 30 assets. An NSIndexSet object specifies the first and last page index to load into memory.

      To determine the number of pages in a drop, call [DropIODrop lastAssetPageIndex].


    2. To get a reference to a specific asset in the drop, call [DropIODrop findAssetNamed:loadIfMissing:], like so:
          DropIOImage* asset = (DropIOImage*)[myDrop findAssetNamed:@"My Portrait" loadIfMissing:YES];
          if (asset == nil)
          {
              NSError* error = [DropIO lastError];
              // Handle error here...
          }
          // Use asset here...
      
      * Again in DropKit 1.1 this method is deprecated in favor of the new method [DropIODrop findAssetNamed:inAssetPages:loadIfMissing] which lets you specify a range of asset pages over which to search using an NSIndexSet, instead of loading all assets.

    3. To create a new asset on the drop, you must call one of the DropIODrop asset creation methods listed below.
         - (DropIONote*)noteWithTitle:(NSString*)noteTitle
                             contents:(NSString*)text;
      
         - (DropIOLink*)linkWithTitle:(NSString*)linkTitle
                                  url:(NSURL*)linkURL
                          description:(NSString*)linkDesc;
      
         - (DropIODocument*)docWithFilename:(NSString*)fileName
                                       data:(NSData*)docData
                                   mimeType:(NSString*)docMimeType;
      
         - (DropIOImage*)imageWithName:(NSString*)imgName
                                  data:(NSData*)imgData
                                format:(NSString*)imgDataFormat;
      

      The docWithFilename... method can be used to upload any type of file to drop.io. For movie and audio files, you may simply typecast the returned object to either a DropIOMovie or DropIOAudio object.

After that, it is a matter of reading the DropKit documentation and source code along with the Drop.io API documentation and figuring things out from there. I have tried to make the classes and methods as obvious as possible. Please let me know what you think... 

License

The DropKit source code is released as open-source software under the terms of the Apache License 2.0.


Help Me Out

I work a day job as a Java developer. Writing software for the iPhone is my passion and a second job for me, for which I am currently getting paid very little. DropKit is an attempt to generate some extra revenue for me and my family.

Please consider making a donation if you have found DropKit useful in any way, whether you are using it in your own projects, or if you just browsed my code for help with some other problem you may be having. Your payments help me to gauge the level of interest in this project, and encourage further support and development.

I have set up a PayPal account to accept payments. Just click the link below... and if you have already donated, thank you very much!

-- Chris Patterson, DropKit author

 


Generated on Thu May 21 13:52:19 2009 for DropKit by  doxygen 1.5.8