ICloud: Retrieving a pre-existing public url for a file

my OS X Lion app allows the user to make iCloud files available to the public. For this I use URLForPublishingUbiquitousItemAtURL

.

I can present this url to the user after calling this method. But is there a way to get the same url after the file has been published (and not modified)? For example, if a user wants to see this URL on another device?

Yes, I could call again URLForPublishingUbiquitousItemAtURL

, but how do I know if a file has already been published or not?

My first idea was to create some kind of keyed data in iCloud containing this url for all files (having a public url). But I can't believe there is no easier way ...

Thank! Daniel

+3


source to share


1 answer


If I understand your question correctly, you want to get or create a public url for a file in iCloud.

If so, use URLForPublishingUbiquitousItemAtURL: expirationDate: error:

It returns a URL that can be emailed to users to download files.

- (NSURL *)URLForPublishingUbiquitousItemAtURL:(NSURL *)url expirationDate:(NSDate
**)outDate error:(NSError **)error

      

Parameters:

  • url - Provide the url of the item in the cloud that you want to share. The URL must be prefixed with the base URL returned from URLForUbiquityContainerIdentifier: (page 61) that matches the location of the elements.

  • outDate - on the input, a pointer to a variable for a date object. On output, this parameter contains the date after which there is no longer item available in the returned URL. You can specify nil for this if you are not interested in the date

  • error - On input, a pointer to a variable for the NSError object. If there is an error, this pointer is set to an NSError object containing information about the error. You can specify nil for this parameter if you do not want to receive error information.



Return value

A URL that users can use to download a copy of an item from a URL. Returns nil if the URL cannot be generated for some reason.

Discussion

This method takes a snapshot of the specified file and location, which is copied to a temporary iCloud location where other users can access it using the returned URL. The snapshot reflects the contents of the file at the time the URL was generated and is not updated when subsequent changes are made to the original file in iCloud users. The snapshot file remains available at the specified URL until the date specified in outDate, after which it is automatically deleted. Your application must have network access to successfully complete this call.

So, if, as you say, you need to check if it was posted successfully, check the error.

Source: NSFileManagerClass @ Developer.Apple.com

+2


source







All Articles