iCloud+CoreData - "Ubiquity: Librarian" error log - ios

I'm using iCloud+CoreData as a persistent stack for my app.
The issue comes out when my app is being installed on the second device.
I see the error log during the on-boarding phase and the error seems to affect both devices.
During the on-boarding I perform the "addPersistentStoreWithType" on my NSPersistentStoreCoordinator that triggers the iCloud Initial Seed download (if exists).
The "options" parameter for the iCloud store are the following:
NSDictionary *options =#{NSMigratePersistentStoresAutomaticallyOption: #YES,
NSInferMappingModelAutomaticallyOption: #YES,
NSPersistentStoreUbiquitousContentNameKey: "PersistentStore_iCloud",
NSSQLitePragmasOption: #{#"journal_mode" : #"DELETE"}};
The "URL" parameter used in the "addPersistentStoreWithType" method is the following:
NSURL *docUrl = [[[NSFileManager defaultManager]
URLsForDirectory:NSDocumentDirectory
inDomains:NSUserDomainMask]lastObject];
NSURL *cloudStore = [[docUrl URLByAppendingPathComponent:"PersistentStore_iCloud"]
URLByAppendingPathExtension:#"sqlite"];
After that I see the following error in the XCode logged for both devices (on the first device appears a bit later):
2015-07-03 11:14:37.362 Quadro[4110:1837886]
__45-[PFUbiquityFilePresenter processPendingURLs]_block_invoke(439): CoreData: Ubiquity: Librarian returned a serious error for starting
downloads Error Domain=BRCloudDocsErrorDomain Code=5 "The operation
couldn’t be completed. (BRCloudDocsErrorDomain error 5 - No document
at URL)" UserInfo=0x171276940 {NSDescription=No document at URL,
NSFilePath=/var/mobile/Library/Mobile
Documents/iCloud~me~actions~Quadro/CoreData/PersistentStore_iCloud/.baseline/PersistentStore_iCloud/Le0RVMmU~RX4wGSl7Dd6sM81tBZId1iVh~Wp_~6U~4U=/baseline.zip,
NSUnderlyingError=0x171258600 "The operation couldn’t be completed. No
such file or directory"} with userInfo {
NSDescription = "No document at URL";
NSFilePath = "/var/mobile/Library/Mobile Documents/iCloud~me~actions~Quadro/CoreData/PersistentStore_iCloud/.baseline/PersistentStore_iCloud/Le0RVMmU~RX4wGSl7Dd6sM81tBZId1iVh~Wp_~6U~4U=/baseline.zip";
NSUnderlyingError = "Error Domain=NSPOSIXErrorDomain Code=2 \"The operation couldn\U2019t be completed. No such file or directory\"
UserInfo=0x171278800 {NSDescription=No such file or directory}"; } for
these urls: (
"file:///var/mobile/Library/Mobile%20Documents/iCloud~me~actions~Quadro/CoreData/PersistentStore_iCloud/.baseline/PersistentStore_iCloud/Le0RVMmU~RX4wGSl7Dd6sM81tBZId1iVh~Wp_~6U~4U=/baseline.zip"
)
Conclusion
Sometimes, when the error comes out, Data is not synced completely, sometimes yes.
Both devices use a really reliable WiFi
I noticed that the system is trying to retrieve the "baseline.zip” using this directory:
"/var/mobile/Library/Mobile
Documents/iCloud~me~actions~Quadro/CoreData/PersistentStore_iCloud/.baseline/PersistentStore_iCloud/38Bj4gxLeIZNVMjIuPeKljVslTu~kP0UhpAvrkvKXOM=/baseline.zip"
Browsing the device file system folders (with iExplorer or similar utility tool) I found out that this directory does not exist in the device file system.
I use iOS Version 8.3 (12F69) with an Apple iPad mini 2 (A1489) and an iPhone6 (A1586).
--
Any suggestion would be appreciated, I'm struggling on this.
Thanks.

Related

iOS - Can't Read File Located In Documents Directory

I am trying to read a file in which I successfully downloaded and saved in the Documents directory. However, when I try to read it, if fails.
Here is the error:
2016-03-28 21:00:26.585 App[569:4103] Path is /var/mobile/Applications/3AFA2430-C0DC-44CD-95F8-A89D82B2C348/Documents/combo.bin
2016-03-28 21:00:26.603 App[569:4103] Error in reading Error Domain=NSCocoaErrorDomain Code=257 "The operation couldn’t be completed. (Cocoa error 257.)" UserInfo=0x17df29d0 {NSFilePath=/var/mobile/Applications/3AFA2430-C0DC-44CD-95F8-A89D82B2C348/Documents/combo.bin, NSUnderlyingError=0x17df90b0 "The operation couldn’t be completed. Permission denied"}
Here is my code:
NSError *error;
NSData *firmwareContentData = [NSData dataWithContentsOfFile:FIRMWARE_LOCAL_PATH options:NSDataReadingMappedIfSafe error:&error];
NSLog(#"Path is %#", FIRMWARE_LOCAL_PATH);
if(error)
{
NSLog(#"Error in reading %#", error);
return;
}
local path is
#define FIRMWARE_LOCAL_PATH [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingPathComponent:#"combo.bin"]
I tried using NSTemporaryDirectory(), using NSFileManager to get the contents of the file, but none of them works. Any idea why? Thanks in advance!
You have a permissions error. You don't have the right permissions to open the file. Wherever you got it from, you're locked out. You might try to download it in the simulator, and check it through Apple's file system to see what permissions it actually downloaded with. The path is:
~/Library/Developer/CoreSimulator/Devices//data/Containers/Data/Application//Documents.
Replace the two big random strings with the directories that show a mod date of today, or NSLog the real path from your iOS app.

Error Domain=NSCocoaErrorDomain Code=256 "The file “...” couldn’t be opened."

When I open a URL (like this http://webserver/index.php/feeds/1.2/3.4/5/1000/) in my app via Xcode I get a nil JSON string returned. It doesn't even seem to be talking to the server.
The exact same URL works when I paste it into a browser.
Reading up on similar problems, I tried restarting my Mac and iPhone but I get the same problem.
e.g. looking at the error object I see:
Error Domain=NSCocoaErrorDomain Code=256 "The file “1000” couldn’t be opened." UserInfo={NSURL=http://webserver/index.php/feeds/1.2/3.4/5/1000/}
The webserver does not show any entries in the logs (it does if I paste the URL in the browser) when I'm running the app and go past that line of code.
==== UPDATE
I'm assuming it's something to do with this NSURLSession/NSURLConnection HTTP load failed on iOS 9
However, after adding the webservice domain to the plist (under NSExceptionDomains) I get a crash in CJSONDserializer in this method:
- (id)deserializeAsDictionary:(NSData *)inData error:(NSError **)outError;
{
if (inData == NULL || [inData length] == 0)
as follows:
Thread 4: EXC_BAD_ACCESS (code=1,address=0x10)
and, after updating TouchJSON, I now have a crash here:
if (theData.length >= 4)
==== UPDATE 2
Interestingly, if I click the QuickLook icon in Xcode whilst on the breakpoint, it loads up the content just fine. And I can see a request at the server.
Any suggestions?

Remove Core Data from iCloud fails

I'm trying to remove Core Data from iCloud using [NSPersistentStoreCoordinator removeUbiquitousContentAndPersistentStoreAtURL:options:error:].
But I get strange output:
__93+[NSPersistentStoreCoordinator removeUbiquitousContentAndPersistentStoreAtURL:options:error:]_block_invoke(1982):
CoreData: Ubiquity: Unable to move content directory to new location:
file:///private/var/mobile/Library/Mobile%20Documents/<UBIQUITY_ID>/
New: file:///private/var/mobile/Library/Mobile%20Documents/OldUbiquitousContent-mobile~C9439AD0-1E87-4977-9C68-0674F5E2E93B
Error Domain=NSCocoaErrorDomain Code=513 "The operation couldn’t be completed.
(Cocoa error 513.)" UserInfo=0x181ab790 {NSSourceFilePathErrorKey=/private/var/mobile/Library/Mobile Documents/<UBIQUITY_ID>,
NSUserStringVariant=(
Move
), NSFilePath=/private/var/mobile/Library/Mobile Documents/<UBIQUITY_ID>,
NSDestinationFilePath=/private/var/mobile/Library/Mobile Documents/OldUbiquitousContent-mobile~C9439AD0-1E87-4977-9C68-0674F5E2E93B,
NSUnderlyingError=0x181aab50 "The operation couldn’t be completed. Operation not permitted"}
What does it mean?
How to avoid it? I'm working on iCloud disable/enable feature. Details HERE
UPDATE:
NSDictionary *iCloudOptions =
[NSDictionary dictionaryWithObjectsAndKeys:kICloudContentNameKey, NSPersistentStoreUbiquitousContentNameKey,
iCloudURL, NSPersistentStoreUbiquitousContentURLKey, nil];
// self.lastICloudStoreURL stores NSPersistentStore.URL after stack setup
BOOL result = [NSPersistentStoreCoordinator removeUbiquitousContentAndPersistentStoreAtURL:self.lastICloudStoreURL
options:iCloudOptions
error:&error];
Normally (before iOS7), you take the ubiquitousContentURL value from [fileManager URLForUbiquityContainerIdentifier:nil];
and pass it as an option called NSPersistentStore UbiquitousContentURLKey, and this is how iCloud know where to keep all of your data in the iCloud account.
In iOS 7 and Mac OS X we don't need to pass a value for that at all, and Apple call URLForUbiquitous ContainerIdentifier automatically under the hood for you.
So the solution looks like this:
NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:kICloudContentNameKey, NSPersistentStoreUbiquitousContentNameKey, nil];
NSURL *storeURL = [NSPersistentStore MR_urlForStoreName:[MagicalRecord defaultStoreName]];
BOOL result = [NSPersistentStoreCoordinator removeUbiquitousContentAndPersistentStoreAtURL:storeURL options:options error:&error];
I suggest you to check WWDC 2013 session 207 to get this things clearly.
NSCocoaErrorDomain error 513 is defined in FoundationErrors.h as NSFileWriteNoPermissionError. You don't have the required permissions to write to the location.
This can happen if a managed object context is still using objects that are backed by this store. The context is actively using the file that is being moved, which results in a NSFileCoordinator conflict. Two things are trying to access the file with write permission at the same time.
The removeUbiquitousContentAndPersistentStoreAtURL:options:error: method deletes all of the user's local and cloud data—this is probably not what you want. Instead, migrate your store to a new location on disk and use the NSPersistentStoreRemoveUbiquitousMetadataOption option with the migratePersistentStore:toURL:options:withType:error: method.
See Disabling iCloud Persistence at Removing an iCloud-enabled Persistent Store in the iCloud Programming Guide for Core Data.

Save UIDocument to iCloud give me NSCocoaErrorDomain Code=4

in my app i want write document on iCloud, but i have a problem with one iCloud account, this is the scenario:
iCloud Account A, all works perfectly, i can write and read, with iPad and iPhone.
iCloud Account B, same as above, i can write and read.
iCloud Account C, doens't work, i can't write and read and give me the error.
This is a scratch of code:
NSURL *ubiqContainer = [[NSFileManager defaultManager]
URLForUbiquityContainerIdentifier:nil];
NSURL *ubiquitousPackage = [[ubiqContainer
URLByAppendingPathComponent:#"Documents"]
URLByAppendingPathComponent:kFILENAME];
MyDocument *mydoc = [[MyDocument alloc]
initWithFileURL:ubiquitousPackage];
self.mydoc = mydoc;
[mydoc saveToURL:[mydoc fileURL]
forSaveOperation:UIDocumentSaveForCreating
completionHandler:
^(BOOL success) {
//success is always FALSE for the Account C
}];
then i have implemented this method:
- (void) handleError:(NSError *)error userInteractionPermitted:(BOOL)userInteractionPermitted{
NSLog(#"error: %#", [error description]);
NSLog(#"permitted: %d", userInteractionPermitted);
}
and this is the log:
error: Error Domain=NSCocoaErrorDomain Code=4 "The operation couldn’t be completed. (Cocoa error 4.)" UserInfo=0x15ef24f0 {NSFileNewItemLocationKey=file:///private/var/mobile/Applications/2A1F6A00-AA50-4D44-AFA1-89D0CA747EBB/tmp/(A%20Document%20Being%20Saved%20By%20My%20App)/MyApp.esd, NSFileOriginalItemLocationKey=file:///private/var/mobile/Library/Mobile%20Documents/EAYDD3QH5Q~com~mycompany~My-App/Documents/MyApp.esd, NSUnderlyingError=0x15e3c870 "The operation couldn’t be completed. (Cocoa error 4.)", NSURL=file:///private/var/mobile/Library/Mobile%20Documents/EAYDD3QH5Q~com~mycompany~My-App/Documents/MyApp.esd}
2013-10-20 16:53:24.358 My App[222:3707] permitted: 1
i can't understand why doens't work on this account, and on the other works...what is wrong? i have reinstalled all profiles in the device with the account problem, but doesn't work, any idea?
I fix the problem deleting the iCloud folder of the app, using the command go to Folder in the Finder:
Users/"username"/.Library/Mobile Documents/"app folder"
and then here i delete the folder, in this way i fix the problem.

UIDocument opening is never finished

I have an iOS 5.1 app, and I'm trying to optimize it for iOS 6. The problem is that openWithCompletionHandler: is never finished. As I see, second device can't download this file. But device-owner works with file fine.
My app uses 2 file types: the first is only text data, and the second is text with picture data. Everything is completely cool with text files. I suppose the problem is in file size, but delay (I tried 40 seconds) doesn't help for me.
I try to use dataWithContentsOfFile: instead of UIDocument and the result is
Data: (null) WithError: Error Domain=NSCocoaErrorDomain Code=256 "The operation couldn’t be completed. (Cocoa error 256.)"
I'm using the following code to open the document
[currentFile openWithCompletionHandler:^(BOOL success) {
NSLog(#"File Opened"); // <<--- Not processed, never reached
}];
I added the following right before opening, but it has no effect:
[[NSFileManager defaultManager] URLForUbiquityContainerIdentifier:nil];

Resources