I'm quite new to iOS development but this has got me absolutely baffled...
My app is doing a simple check if a file exists, like so:
if ([[NSFileManager defaultManager] fileExistsAtPath:[self.countDatabase.fileURL path]]) {....
This worked fine last week and it still works perfectly fine on the iOS device itself. But when the iPhone simulator gets to this line of code, it just... stops. No errors, it doesn't freeze, it just stops. I can start other actions in it but it never completes what was started before. I don't get it. The only thing on this macbook that's changed since last week is that I updated OSX to 10.8.2 and update to iTunes 10.7.
Has anyone ever encountered this or have some idea how I can further debug this? If I step through the code, I get to this line and it just stops stepping through things. It's as if the simulator thinks that it's done.
since I used lots of times:
[[NSFileManager defaultManager] fileExistsAtPath:[[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingPathComponent:[NSString stringWithFormat:#"file.pdf"]]]
It seems that [self.countDatabase.fileURL path] is returning wrong value as a path. I would NSLog it to see what is containing.
Related
I have an app built that uses the UIDocumentBrowser. It was working fine until I tried to add an ImagePickerController to allow the app to use the camera and take photos. The Documents folder is now no where to be found on the "Files" app or in the app I am developing. I could find it in the Finder on the Mac I am using for developing the app.
I tried deleting the entire app and data and installing a cleaned build.
I have this sitting at the top of the app launch method
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
_datapath=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0];
if (![NSFileManager.defaultManager fileExistsAtPath:_datapath])
[NSFileManager.defaultManager createDirectoryAtPath:_datapath withIntermediateDirectories:YES attributes:nil error:nil];
When I run it in debug, it finds the already created documents folder so skips over the createDirectoryAtPath method.
Any ideas what's happening and/or how I can fix it?
Note: I never got to the point in the app where I could test the ImagePicker before this problem happened and removing the code I added didn't fix the problem.
Must have been cached information. Powered down the iPad and restarted fixed the problem.
I have this kind of code in an iOS app of mine:
NSString *docNameString;
docNameString=#"https://www.mysite.php";
documentHTML=gethtml((char*)[docNameString UTF8String],
(char*)[#"UTF-8" UTF8String]);
It was working up to now (meaning last time I touched the app in Xcode).
But now it is no longer working. I get this message in the Xcode console:
I/O warning : failed to load external entity "https://www.mysite.php"
Document not parsed successfully.
I am currently using Xcode Version 10.0.
Anyone has an idea of how to deal with this issue?
When I'm trying to run my application on iOS 8 device or simulator it crashes with messages in console:
cwd:/dir=/Users/alexedunov/Library/Developer/CoreSimulator/Devices/B0F6F815-1209-48D8-8485- 5B5EB35686B9/data/Containers/Data/Application/65B6100A-22C8-43B3-A6E2-506571B92E66/Documents
cwd:/Users/alexedunov/Library/Developer/CoreSimulator/Devices/B0F6F815-1209-48D8-8485- 5B5EB35686B9/data/Containers/Data/Application/65B6100A-22C8-43B3-A6E2-506571B92E66/Documents
2014-09-18 22:57:39.581 BankApp[3943:45325] Wrong directory.
Run application from /var/mobile/Applications/<App id>/<App name>.app
I didn't find any solution to fix it.
My OS X version is Mac OS Yosemite beta 10.10.
XCode 6.0 (6A313)
I have the same problem. It resolves by removing CryptoPro (http://www.cryptopro.ru/) from project. Probably, in CryptoPro performs find some files in application`s Documents folder using incorrect path ([[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject] recommended). I will try to update CryptoPro to latest version, and I hope that helps.
Is your project contains CryproPro?
I catched the same error when running "Np Cades Browser". I figure out that it's because of iOS version. On iOS 10 error persists.
You need iOS 7 to make this work. Don't know about above versions. I assume paths different on different OS.
I got a real strange problem with an iOS app I'm currently working at. The effect only exists if I test the app using ad hoc distribution. After updating the app (it has to be installed before) it wasn't working correctly. I could track the error down and it is caused by following line of code:
[fileManager createDirectoryAtPath:folder withIntermediateDirectories:YES attributes:nil error:&error];
Now you could say, of course: Don't ever write to the app bundle itself, but the base path is the Documents folder via:
dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
docsDir = [dirPaths objectAtIndex:0];
imgDir = [docsDir stringByAppendingPathComponent:#"images"];
folder = [imgDir stringByAppendingPathComponent:md5]; // md5-Hash is created before
The complete error message (logged to iphone system log) is:
Error Domain=NSCocoaErrorDomain Code=513 "The operation couldn’t be completed. (Cocoa error 513.)" UserInfo=0x14d44f30 {NSFilePath=/var/mobile/Applications/280C6D36-3667-4589-A74F-42F3F17ABA71/Documents/images/39b6cd45a05a2276ef065b2ecf33b1eb, NSUnderlyingError=0x14d4e340 "The operation couldn’t be completed. Operation not permitted"}
The interesting thing is, as I noted, if I delete the app before installing via ad hoc distribution (Testflight to a iPhone 5 with iOS 7.0.4) the folder is created and the App works as expected. The only references I could find were developers not using stringByAppendingPathComponent or writing directly to the app bundle. Maybe anybody else got the problem or has an idea?
I finally found the reason why the folder could not be created. Afterwards it seems pretty simple and stupid, but if you could take a look at the complete source code you would unterstand how this could happen. In my defense I have to say that I came to this project for further development because the original developer left the project. For your better understanding I simplified the code a lot.
dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
docsDir = [dirPaths objectAtIndex:0];
imgDir = [docsDir stringByAppendingPathComponent:#"images"];
The imgDir was actually saved in userPreferences and a proxy class always returned the saved path, which is a really bad idea. During the update process the app gets a new guid which reflects in the apps documents path. So trying to create a folder in the previous version documents folder had to fail as it doesn't exist anymore. I corrected the code to never save the path and always return the current one with the code above.
In my iCloud-based app, I noticed that if a crash were to occur while a UIDocument is open (and has not yet been closed), the status of the document sometimes becomes UIDocumentStateSavingError and it never opens successfully again.
When I run [UIDocument openWithCompletionHandler:] after this, the document never opens, returning NO for success and 5 (UIDocumentStateClosed and UIDocumentStateSavingError) for documentState.
On iOS 5, I also observed that NSMetadataQueryDidUpdateNotification is constantly being called (every second) until the file is deleted and the app is restarted. This causes additional usability problems in the app.
One more thing, on developer.icloud.com I noticed that the file is showing a second, conflicted version existing. This conflict isn't found on any of my devices, though, not even if the app is restarted or reinstalled.
What do I do to get the UIDocument to open normally?
Here is what I tried so far:
Checking [NSFileVersion unresolvedConflictVersionsOfItemAtURL:] for conflicts and removing all older version using [NSFileVersion removeOtherVersionsOfItemAtURL:].
Calling [[NSFileManager defaultManager] evictUbiquitousItemAtURL:] before calling [UIDocument openWithCompletionHandler:] to re-download the file to the device.
Downloading the main and conflicted versions from developer.icloud.com to see if any of them are corrupt or partial files. Both open fine.
Banging my head against my desk. Preliminary results are unsuccessful.