Re: App refuses to launch after adding iCloud Drive support
Re: App refuses to launch after adding iCloud Drive support
- Subject: Re: App refuses to launch after adding iCloud Drive support
- From: Graham Cox <email@hidden>
- Date: Fri, 01 Jan 2016 20:19:46 +1100
Hmmm, maybe I spoke too soon.
My app appears to be able to access iCloud Drive. Adding/removing the magic stuff to info.plist appears NOT to make any difference to this, though caching somewhere might be skewing the true picture, don’t know.
What I’d quite like to do is to follow the recommendation in the documentation and add a /<my App>/Documents/ folder to the user’s iCloud drive. So I tried the following code, run from -[<appDelegate> appDidFinishLaunching]:
- (void) prepareICloudDrive
{
// creates subfolders in the iCloud drive if needed
NSDictionary* ubiquityContainers = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"NSUbiquitousContainers"];
if( ubiquityContainers )
{
for( NSString* containerID in ubiquityContainers )
{
NSDictionary* container = [ubiquityContainers objectForKey:containerID];
if( container )
{
// need to do this on a thread
NSOperationQueue* opq = [[NSOperationQueue alloc] init];
[opq addOperationWithBlock:^
{
NSFileManager* fm = [[NSFileManager alloc] init];
NSURL* iCloudURL = [fm URLForUbiquityContainerIdentifier:containerID]; //<—— always returns nil
if( iCloudURL )
{
// append /<the app>/Documents/ to the URL
NSString* appContainerName = [[container objectForKey:@"NSUbiquitousContainerName"] stringByAppendingPathComponent:@"Documents"];
NSURL* iCloudDocFolderURL = [iCloudURL URLByAppendingPathComponent:appContainerName isDirectory:YES];
NSError* error = nil;
if( ![fm createDirectoryAtURL:iCloudDocFolderURL withIntermediateDirectories:YES attributes:nil error:&error])
{
NSLog(@"failed to create iCloud storage at %@, error = %@", iCloudDocFolderURL, error );
}
}
[fm release];
[opq release];
}];
}
}
}
}
The problem I have is that when the block runs, the result of -URLForUbiquityContainerIdentifier: is nil. The docs for this state that I have to pass a string in the form <TEAMID>.<CONTAINER>, which doesn’t seem to be the case for the string the other documentation has (‘iCloud.com.<my company>.<id>'. It’s unclear how this is supposed to work without having entitlements, but the docs state that 10.11 apps don’t need the entitlements, just the magic.
It’s not essential that I do this - presumably the user can add folders as they wish, but since iApps and other Apple apps do this, it would be nice to follow suit.
Since 10.11 changed how this works, I’d expect to see an explanation at least in the release notes, but I don’t see anything there. Is there any other info about this? The docs as usual are ambiguous and self-contradictory.
—Graham
> On 1 Jan 2016, at 5:59 PM, Graham Cox <email@hidden> wrote:
>
> Thank you Quincey!
>
> I was thinking that if Apple want this stuff adopted, they really ought to make it much easier. Turns out they did :)
>
>
> —Graham
>
>
>
>
>> On 1 Jan 2016, at 1:39 PM, Quincey Morris <email@hidden> wrote:
>>
>>
>> https://developer.apple.com/library/mac/documentation/General/Conceptual/iCloudDesignGuide/Chapters/DesigningForDocumentsIniCloud.html#//apple_ref/doc/uid/TP40012094-CH2-SW20
>>
>> at the end of the page under the heading "Enabling Document Storage in iCloud Drive”.
>>
>> In brief, for 10.11 non-Mac-App-Store access, do NOT set the entitlement, but DO add the magic thing to your info.plist.
>>
>
>
> _______________________________________________
>
> Cocoa-dev mailing list (email@hidden)
>
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden