diff --git a/README.md b/README.md index b7a1944..6b51fe9 100644 --- a/README.md +++ b/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! @@ -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. @@ -115,15 +123,9 @@ iCloud Document Sync delegate methods notify you of the status of iCloud and you
  • fileURL contains the NSURL pointing to the file. This could possibly be used to gather more information about the file.
  • modifiedDate contains the NSDate representing the last modified date of the file.
  • -

    +
    - (void)iCloudFileUploadConflictWithCloudFile:(NSDictionary *)cloudFile andLocalFile:(NSDictionary *)localFile; - - iCloud Error Deprecated - 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. -

    - - (void)iCloudError:(NSError *)error - Extra Features diff --git a/iCloud.xcodeproj/project.xcworkspace/xcuserdata/Spencers.xcuserdatad/UserInterfaceState.xcuserstate b/iCloud.xcodeproj/project.xcworkspace/xcuserdata/Spencers.xcuserdatad/UserInterfaceState.xcuserstate index 4786ea2..aceed9e 100644 Binary files a/iCloud.xcodeproj/project.xcworkspace/xcuserdata/Spencers.xcuserdatad/UserInterfaceState.xcuserstate and b/iCloud.xcodeproj/project.xcworkspace/xcuserdata/Spencers.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/iCloud/iCloud.h b/iCloud/iCloud.h index 243bdbb..3b0b3b8 100755 --- a/iCloud/iCloud.h +++ b/iCloud/iCloud.h @@ -127,6 +127,21 @@ NS_CLASS_AVAILABLE_IOS(5_0) @interface iCloud : NSObject + (void)uploadLocalOfflineDocumentsWithDelegate:(id)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. diff --git a/iCloud/iCloud.m b/iCloud/iCloud.m index 32291e3..68f7544 100755 --- a/iCloud/iCloud.m +++ b/iCloud/iCloud.m @@ -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 -------------------------------------------------------------------------------------------------------------------------// //---------------------------------------------------------------------------------------------------------------------------------------------//