UIDocument opening is never finished - ios

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];

Related

Can't read or create UIManagedDocuments anymore

I have a big issue in my app, which prevents creating new documents and reading them, whereas it worked well until now.
I didn't change anything, and it started bugging from a build to another.
This is the code I'm using:
CLProject *project = [[CLProject alloc] initWithFileURL:projectURL];
NSLog (#"Will save project at URL: %#", projectURL);
[project saveToURL:projectURL forSaveOperation:UIDocumentSaveForCreating completionHandler:^(BOOL success) {
NSLog (#"Project saved: %d", success);
[...]
}];
CLProject is a subclass of UIManagedDocument.
The first NSLog is called, but not the second one. Instead I get an error :
2018-02-14 19:21:03.597495+0100 CamList[2247:750786] Will save project
at URL:
file:///var/mobile/Containers/Data/Application/151E38F5-2214-4876-A188-2AB8B5E8CF6A/Documents/Projects/715A0087-F2EF-439B-A2DD-8E878EF8A973.camlist
2018-02-14 19:21:03.783397+0100 CamList[2247:750886] [default] [ERROR]
Could not get attribute values for item
/var/mobile/Containers/Data/Application/151E38F5-2214-4876-A188-2AB8B5E8CF6A/Documents/Projects/715A0087-F2EF-439B-A2DD-8E878EF8A973.camlist
(n). Error: Error Domain=NSFileProviderInternalErrorDomain Code=1 "The
reader is not permitted to access the URL."
UserInfo={NSLocalizedDescription=The reader is not permitted to access
the URL.}
But it doesn't crash, the app keeps running (but nothing happens because the completion block never gets called).
What I don't understand is that everything was working fine and I haven't changed anything...
Can you help me??
Thanks
Well, it seems to work fine again this morning... Nothing to understand. My iPhone had to be tired...

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?

iCloud+CoreData - "Ubiquity: Librarian" error log

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.

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.

Resources