Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

newtoiphonesdk

macrumors 6502a
Original poster
Jul 30, 2010
567
2
My app produces PDFs. I am testing out getting it to save it to iCloud Drive, so that people can get on the iCloud.com site or in Finder on Yosemite and instantly have access to what they've created. I get it to connect and upload, as I can go in on Yosemite and see the Folder for my app, but it only uploads a PLIST file. I have a Folder inside the app folder with the name of the PDF, but opening it only yields Metadata.plist. What am I missing here in code?

Code:
-(void)sendtoiCloud {
 [self initializeiCloudAccessWithCompletion:^(BOOL available) {
            
            _iCloudAvailable = available;
            
            NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
            
            NSString *documentsDirectory = [paths objectAtIndex:0];
            
            NSString *ubiquity = [self.ubiquityURL absoluteString];
            
            NSString *pdfPath = [ubiquity stringByAppendingPathComponent:[documentsDirectory stringByAppendingPathComponent:selectedCountry]];
        
           NSURL *fileURL = [[self.ubiquityURL URLByAppendingPathComponent:@"Documents" isDirectory:YES] URLByAppendingPathComponent:selectedCountry isDirectory:NO];
            NSLog(@"FILEURL%@", fileURL);
            UIManagedDocument* document = [[UIManagedDocument alloc] initWithFileURL:fileURL];
            
            document.persistentStoreOptions = @{NSMigratePersistentStoresAutomaticallyOption : @(YES),
                                                NSInferMappingModelAutomaticallyOption: @(YES),
                                                NSPersistentStoreUbiquitousContentNameKey: selectedCountry,
                                                NSPersistentStoreUbiquitousContentURLKey: [self.ubiquityURL URLByAppendingPathComponent:@"TransactionLogs" isDirectory:YES]
                                                };
            NSString *testing = [self.ubiquityURL absoluteString];
            UIAlertView *alerttest = [[UIAlertView alloc] initWithTitle:@"Test" message:testing delegate:self cancelButtonTitle:@"Ok" otherButtonTitles: nil];
            [alerttest show];
            [alerttest release];
            [document saveToURL:fileURL forSaveOperation:UIDocumentSaveForCreating completionHandler:^(BOOL success) {
                
            }];

            
            
        }];
}
- (void)initializeiCloudAccessWithCompletion:(void (^)(BOOL available)) completion {
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        self.ubiquityURL = [[NSFileManager defaultManager] URLForUbiquityContainerIdentifier:nil];
        if (self.ubiquityURL != nil) {
            UIAlertView *works = [[UIAlertView alloc] initWithTitle:@"Works" message:@"Kinda" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles: nil];
            [works show];
            [works release];
            dispatch_async(dispatch_get_main_queue(), ^{
                NSLog(@"iCloud available at: %@", self.ubiquityURL);
                completion(TRUE);
            });
        }
        else {
            dispatch_async(dispatch_get_main_queue(), ^{
                NSLog(@"iCloud not available");
                completion(FALSE);
            });
        }
    });
}
I have it pop up a UIAlertView so I can view on my phone the NSURL it gives and it looks like file:///var/mobile/Containers/Data/Application/43268BBD-BSSee-/Documents/File.pdf

From all I can tell, that should be uploaded, but I only get metadata. Please help.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.