Skip to content

Commit

Permalink
Merge pull request #13 from iRareMedia/feature
Browse files Browse the repository at this point in the history
Version 6.3
  • Loading branch information
iRare Media committed Oct 11, 2013
2 parents 950e0df + edcc867 commit e623297
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 8 deletions.
18 changes: 10 additions & 8 deletions README.md
@@ -1,7 +1,7 @@
iCloud Document Sync
==================

iCloud Document Sync helps integrate iCloud into iOS (OS X coming soon) Objective-C document projects with one-line code methods. Sync, upload, manage, and remove documents to and from iCloud with only a few lines of code (compared to the 400+ lines that it usually takes).
iCloud Document Sync helps integrate iCloud into iOS (OS X coming soon) Objective-C document projects with one-line code methods. Sync, upload, manage, and remove documents to and from iCloud with only a few lines of code (compared to the hundreds of lines that it usually takes).

If you like the project, please [star it](https://github.com/iRareMedia/iCloudDocumentSync) on GitHub!

Expand Down Expand Up @@ -95,6 +95,14 @@ You can also check whether or not a file actually exists in iCloud or not by usi
// File Exists in iCloud
}

### Sharing Documents
You can upload an iCloud document to a public URL by using the method below. The completion block is called when the public URL is created.

NSURL *publicURL = [iCloud shareDocumentWithName:@"docName.ext" completion:^(NSURL *sharedURL, NSDate *expirationDate, NSError *error) {
// Completion handler that passes the public URL created, the expriation date of the URL, and any errors. Could be used to update your UI and tell the user that the document was uploaded
}];


Delegates
-----
iCloud Document Sync delegate methods notify you of the status of iCloud and your documents stored in iCloud. There are no required delegate method for iOS, however it is recommended that you utilize all available delegate methods.
Expand All @@ -115,15 +123,9 @@ iCloud Document Sync delegate methods notify you of the status of iCloud and you
<li><tt>fileURL</tt> contains the NSURL pointing to the file. This could possibly be used to gather more information about the file. </li>
<li><tt>modifiedDate</tt> contains the NSDate representing the last modified date of the file. </li>
</ul>
<br /><br />
<br />
<tt> - (void)iCloudFileUploadConflictWithCloudFile:(NSDictionary *)cloudFile andLocalFile:(NSDictionary *)localFile;</tt></td>
</tr>
<tr>
<td>iCloud Error <span style="color:#FF0000"><b>Deprecated</b></span></td>
<td> This delegate method was previously used to report errors when reading or writing files. Please use the NSError object provided in all method completion blocks instead of this delegate method. This delegate method is no longer called and may break in future versions.
<br /><br />
<tt> - (void)iCloudError:(NSError *)error</tt></td>
</tr>
</table>

Extra Features
Expand Down
Binary file not shown.
15 changes: 15 additions & 0 deletions iCloud/iCloud.h
Expand Up @@ -127,6 +127,21 @@ NS_CLASS_AVAILABLE_IOS(5_0) @interface iCloud : NSObject
+ (void)uploadLocalOfflineDocumentsWithDelegate:(id<iCloudDelegate>)delegate repeatingHandler:(void (^)(NSString *fileName, NSError *error))repeatingHandler completion:(void (^)(void))completion;


/** @name Sharing iCloud Content */

/** Share an iCloud document by uploading it to a public URL.
@discussion Upload a document stored in iCloud for a certain amount of time.
@param name The name of the iCloud file being uploaded to a public URL
@param handler Code block called when the document is successfully uploaded. The completion block passes NSURL, NSDate, and NSError objects. The NSURL object is the public URL where the file is available at. The NSDate object is the date that the URL expries on. The NSError object contains any error information if an error occurred, otherwise it will be nil.
@return The public URL where the file is available at
*/

+ (NSURL *)shareDocumentWithName:(NSString *)name completion:(void (^)(NSURL *sharedURL, NSDate *expirationDate, NSError *error))handler;


/** @name Deleting content from iCloud */

/** Delete a document from iCloud.
Expand Down
24 changes: 24 additions & 0 deletions iCloud/iCloud.m
Expand Up @@ -398,6 +398,30 @@ + (NSArray *)getListOfCloudFiles {
return directoryContent;
}

//---------------------------------------------------------------------------------------------------------------------------------------------//
//------------ Share --------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------//
#pragma mark - Share

+ (NSURL *)shareDocumentWithName:(NSString *)name completion:(void (^)(NSURL *sharedURL, NSDate *expirationDate, NSError *error))handler {
// Get the URL to get the file from
NSURL *folderURL = [[NSFileManager defaultManager] URLForUbiquityContainerIdentifier:nil];
NSURL *fileURL = [[folderURL URLByAppendingPathComponent:DOCUMENT_DIRECTORY] URLByAppendingPathComponent:name];

// Create the Error Object and the Date Object
NSError *error;
NSDate *date;

// Create the URL
NSURL *url = [[NSFileManager defaultManager] URLForPublishingUbiquitousItemAtURL:fileURL expirationDate:&date error:&error];

// Pass the data to the handler
handler(url, date, error);

// Return the URL
return url;
}

//---------------------------------------------------------------------------------------------------------------------------------------------//
//------------ Delete -------------------------------------------------------------------------------------------------------------------------//
//---------------------------------------------------------------------------------------------------------------------------------------------//
Expand Down

0 comments on commit e623297

Please sign in to comment.