Can't read or create UIManagedDocuments anymore - ios

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...

Related

Error initialize AZSCloudStorageAccount Swift 3

I tried link to my account with this code
let storageAccount : AZSCloudStorageAccount;
try! storageAccount = AZSCloudStorageAccount(fromConnectionString: config.getAzureConnection())
let blobClient = storageAccount.getBlobClient()
var container : AZSCloudBlobContainer = (blobClient?.containerReference(fromName: config.getContainer()))!
the "config.getAzureConnection()" contains the right path because i used the same for android app.
In this line try! storageAccount = AZSCloudStorageAccount(fromConnectionString: config.getAzureConnection()) the app crash without error, only (lldb) .
Can someone help me.
Does your error look like this?
fatal error: 'try!' expression unexpectedly raised an error: Error Domain=com.Microsoft.AzureStorage.ErrorDomain Code=1 "(null)": file /Library/Caches/com.apple.xbs/Sources/swiftlang/swiftlang-802.0.53/src/swift/stdlib/public/core/ErrorType.swift, line 182
(lldb)
Code=1 is AZSEInvalidArgument, which means that your connection string is invalid. I am a bit confused why you said "the right path", since fromConnectionString takes the string directly, not the path to a file. To see an example of what a correct connection string looks like, please refer to the Getting Started Guide. Basically it looks like this:
"DefaultEndpointsProtocol=https;AccountName=your_account_name_here;AccountKey=your_account_key_here"
We will document the error codes properly very soon. Sorry for the confusion!
the app crash without error, only (lldb) .
I am sorry for that SWIFT blob client haven't provide error-handling code whatsoever currently. I will provide some clues to track your issue based on your code.
Before building the storage code, make one change in the project. Go to 'Azure Storage Client Library' -> Build Settings, search for the "Defines Module" setting, and change it to 'YES'.
Please check whether the issue is caused by bad network connection.
You could get error code of this issue by putting your code in a do-catch code block.
do {
//put your code here
} catch let error as NSError {
print("Error code = %ld, error domain = %#, error userinfo = %#", error.code, error.domain, error.userInfo);
}
The SWIFT blob sample has been tested and work well targeting iOS 9.0 and using XCode 7. If you have a different setup, the sample may not run properly. I suggest you use Blob Storage REST API as a workaround.

How can I use OpenEars in a tweak?

I'm trying to include OpenEars in a theos project I'm making, a tweak for jailbroken iDevices, as I need speech recognition for my tweak. I was able to link the OpenEars framework by putting it in the same folder as my private frameworks, and I'm currently trying to get the tutorial code to work. Here's my current code:
#import <OpenEars/LanguageModelGenerator.h>
#import <OpenEars/PocketsphinxController.h>
#import <OpenEars/AcousticModel.h>
%hook SBLockScreenView
-(void)setCustomSlideToUnlockText:(id)arg1 {
LanguageModelGenerator *lmGenerator = [[LanguageModelGenerator alloc] init];
NSArray *words = [NSArray arrayWithObjects:#"WORD", #"STATEMENT", #"OTHER WORD", #"A PHRASE", nil];
NSString *name = #"NameIWantForMyLanguageModelFiles";
NSError *err = [lmGenerator generateLanguageModelFromArray:words withFilesNamed:name forAcousticModelAtPath:[AcousticModel pathToModel:#"AcousticModelEnglish"]];
//NSError* err = [lmGenerator generateLanguageModelFromArray:words withFilesNamed:name forAcousticModelAtPath:imagePath];
//NSError* err = [[NSError alloc] init];
NSDictionary *languageGeneratorResults = nil;
NSString *lmPath = nil;
NSString *dicPath = nil;
if([err code] == noErr) {
languageGeneratorResults = [err userInfo];
lmPath = [languageGeneratorResults objectForKey:#"LMPath"];
dicPath = [languageGeneratorResults objectForKey:#"DictionaryPath"];
}
else {
NSLog(#"Error: %#",[err localizedDescription]);
}
%orig;
}
%end
This compiles fine, but when it runs, I get these error messages and my device crashes: "While trying to reference the requested acoustic model bundle which is expected to be at the path (null), no bundle was found. This means that when the listening loop begins, it will crash due to the missing required resources. The problem finding the acoustic model bundle could be because the name of the bundle was not given to this method in a way it can use; for instance, if you are trying to use the English acoustic model and you have added that bundle to your app project, you would invoke this method by passing [AcousticModel pathToAcousticModel:#"AcousticModelEnglish"] (or [AcousticModel pathToAcousticModel:#"AcousticModelSpanish"] for the Spanish bundle), without appending ".bundle" to the end, and making sure that the bundle name is spelled exactly as it appears in the actual bundle name (the bundle can be seen in this distribution's folder "Framework".
If this doesn't fix the problem, it is very likely to be due to the fact that the acoustic model bundle wasn't imported successfully into the root level of your app project and its mainBundle. This usually happens either because the acoustic model bundle was never dragged into your app project when the "Framework" folder was originally supposed to be dragged in, or because it was dragged in but instead of using the setting "Create groups for any added folders" in Xcode's "Add Files" dialog, the option "Create folder references for any added folders" was unintentionally chosen. To fix this, just remove the acoustic model bundle or the "Framework" folder from your app and add it again to your app project with the correct setting of "Create groups for any added folders" in Xcode's "Add Files" dialog."
I also get these messages in my syslog:
May 27 00:54:49 Phillips-iPhone SpringBoard[17785] <Warning>: acousticModelPath is (null)
May 27 00:54:49 Phillips-iPhone SpringBoard[17785] <Warning>: Error: the default phonetic dictionary (null)/LanguageModelGeneratorLookupList.text can't be found in the app bundle but the app is attempting to access it, most likely there will be a crash now.
May 27 00:54:49 Phillips-iPhone SpringBoard[17785] <Warning>: Error while trying to load the pronunciation dictionary: Error Domain=NSCocoaErrorDomain Code=260 "The operation couldn’t be completed. (Cocoa error 260.)" UserInfo=0x1883cbb0 {NSFilePath=(null)/LanguageModelGeneratorLookupList.text, NSUnderlyingError=0x1883cb40 "The operation couldn’t be completed. No such file or directory"}
May 27 00:54:49 Phillips-iPhone SpringBoard[17785] <Error>: *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Invalid domain=nil in -[NSError initWithDomain:code:userInfo:]'
Any help in getting this working is greatly appreciated. Thanks!
I recently made an OpenEars based iOS tweak and I went through the same problem. Because your tweak is not a normal app, the location that pathToAcousticModel gives will not be correct. The easiest solution is to place the acoustic model bundle in a known location and hard code it.
For example, if you are using theos you can place AcousticModelEnglish.bundle in the folder "layout/Library/OpenEars/". Then replace
[AcousticModel pathToAcousticModel:#"AcousticModelEnglish"]
with
#"/Library/OpenEars/AcousticModelEnglish.bundle"
The easiest solution that I found was dragging the "Framework" folder from the OpenEars library that contains the bundle files to the "Frameworks" folder inside the Xcode project. After dragging, mark the option "copy items if needed".
It sounds strange in the first look but this solution works and you won't change the code.
You will get a file structure like that:
You can also remove the oldest references of these libraries under the "Framework" folder to keep your project clean.
Cheers,
David

All of a sudden: -[__NSArrayM popObjectForKey:]: unrecognized selector sent to instance

I was developing an app, at some stage this error came out:
-[__NSArrayM popObjectForKey:]: unrecognized selector sent to instance
I've undone the latest edits to see what was wrong...but the error was still there.
So I've undone even more edits, but the error was still there.
Tried to delete and add back the framework where I thought the error could come from, error still there. (it's KinveyKit framework)
Tried to substitute the line of code where the app would throw the error with another one that was surely working: even that one was throwing the error.
I downloaded an older Git of the app (that was definitely working a few days ago) on a different folder, run that and: same error.
Uninstalled and reinstalled Xcode: error still there.
But: if I run other apps with similar code, nothing goes wrong.
Does anybody have any idea?
I post here the code, that throws me the error, just to give you an idea...but I don't think there's anything wrong in the code since it's always been working before.
.h
#property (strong, nonatomic) KCSAppdataStore *store;
.m
- (void)viewDidLoad
{
...
_store = [KCSAppdataStore storeWithOptions:#{ KCSStoreKeyCollectionName : #"AnEntity",
KCSStoreKeyCollectionTemplateClass : [AnEntity class]}];
[_store queryWithQuery:[KCSQuery query]
withCompletionBlock:^(NSArray *objectsOrNil1, NSError *errorOrNil) { ... }];
...
}
Cool -- being sarcastic
I spent the afternoon rebuilding the app from a new project, copy pasting the code...
Now I opened the older one once again, tried to run it just...just to try once again, knowing it would crash cause I haven't change a word it already crashed every other time I tried earlier this morning, and.... surprise: runs again. No errors.
-.-'' Solution to my question then? No idea. Still thinking it was some cache problem that eventually got solved through out the day but not while I was trying to solve it.
If anybody has had similar experiences or has some further idea, feel free to add something, always good to be prepared for next time something like this happens.
I had a similar issue that appeared to be caused by a corrupted KCSUser object written to the keychain. The popObjectForKey method appears to get called any time you call [KCSUser activeUser]. I was able to get this fixed by adding the code below first thing in application DidFinishLaunchingWithOptions:. Be sure you aren't calling [KCSUser activeUser] at any point before the following code has a chance to run.
NSArray *secItemClasses = #[(__bridge id)kSecClassGenericPassword,
(__bridge id)kSecClassInternetPassword,
(__bridge id)kSecClassCertificate,
(__bridge id)kSecClassKey,
(__bridge id)kSecClassIdentity];
for (id secItemClass in secItemClasses) {
NSDictionary *spec = #{(__bridge id)kSecClass: secItemClass};
SecItemDelete((__bridge CFDictionaryRef)spec);
}
This appears to clear/reset the keychain. After you run it once, remove it and you app should operate normally.

NSFileCoordinator error when using UIManagedDocument in iOS 5.0 simulator

I am using a UIManagedDocument in iOS 5.0, running the app on the simulator, using XCode 4.2 under OSX 10.6. The code in question looks as follows:
if (![[NSFileManager defaultManager] fileExistsAtPath:[self.photoDatabase.fileURL path]]) {
// does not exist on disk, so create it
[self.photoDatabase saveToURL:self.photoDatabase.fileURL forSaveOperation:UIDocumentSaveForCreating completionHandler:^(BOOL success) {
[self setupFetchedResultsController];
[self fetchFlickrDataIntoDocument:self.photoDatabase];
}];
} else if (self.photoDatabase.documentState == UIDocumentStateClosed) {
// exists on disk, but we need to open it
// *** the following line generates the message ***
[self.photoDatabase openWithCompletionHandler:^(BOOL success) {
//[self setupFetchedResultsController];
}];
} else if (self.photoDatabase.documentState == UIDocumentStateNormal) {
// already open and ready to use
[self setupFetchedResultsController];
}
Running the marked line creates the following message on the log:
2012-01-10 22:33:17.109 Photomania[5149:4803] NSFileCoordinator: A surprising server error was signaled. Details: Connection invalid
After the message is sent, the UIManagedDocument may or may not work—I have not found the circumstances that determine this, yet.
I am pretty sure that the code is correct, as it's actually one of the code examples in the CS193p course from Stanford. The whole example can be downloaded at their website under
http://www.stanford.edu/class/cs193p/cgi-bin/drupal/
Direct link to the code:
http://www.stanford.edu/class/cs193p/cgi-bin/drupal/system/files/sample_code/Photomania_0.zip
Additionally, the code runs fine on the device itself, without generating the "surprising" message, and running all the code that comes afterwards just fine.
I have not found anything on Google, neither on the Apple Developer pages. Restarting the simulator, or XCode, or reinstalling both of them does not change the behaviour.
Any ideas?
I can only say that I've had this happen to me several times. For me, I'm lazy after I update my dataModel and so far, each time I've gotten this error it was because I had changed my data model. Usually, all I need to do is delete my app from the simulator and re-run it and it has always turned out fine. Hope this helps someone out there.
I think I have found the answer. It looks like the automatic saving for UIManagedDocument kicks in only after a few seconds on the simulator.
So I minimized the app on the simulator, by pressing the home button, and then clicked on the icon to maximize it again. And then I terminated the app in simulator.
When I re-launched the app, the database was loaded. The error still shows up - it comes because the document is in "closed" state (that's normal - that's why CS193P asked to call openWithCompletionHandler), but my data across launches is preserved. Unfortunately I have to do the minimize/maximize routine before terminating the app, or the changes are discarded at next launch.
Can you verify that this is the behavior you are able to recreate? At least for testing purposes this should be a good enough trick to use.
Try upgrading to the latest iOS 5.1. I don't think UIManagedDocument with iCloud works reliably in 5.0. This has been my experience.
I love the Stanford iTunes class. However, I think the sample code for using UIManagedDocument is wrong. In fact, he notes in the demo that he is only doing it that way because he wants to just fetch the information right then. In the code comments, he says not to use the auto-save features because the data will not be saved if the app quits. however, UIManagedDocument will save anything that's necessary before quitting. It has all pertinent handlers for quitting/multitasking/etc to make sure the data is saved.
So, if you are using that code as your example, here's a version that should work, and does not use saveToURL (I don't have a flickr account, so I didn't actually run it - but this is how the class is designed to work). Please let me know if it does not work.
- (void)fetchFlickrDataIntoDocument:(UIManagedDocument *)document
{
NSManagedObjectContext *ctx = [[NSManagedObjectContext alloc] initWithConcurrencyType: NSPrivateQueueConcurrencyType];
ctx.parentContext = document.managedObjectContext;
[ctx performBlock:^{
NSArray *photos = [FlickrFetcher recentGeoreferencedPhotos];
for (NSDictionary *flickrInfo in photos) {
[Photo photoWithFlickrInfo:flickrInfo inManagedObjectContext:ctx];
// Push changes to document MOC
[ctx save:0]; // propagates changes to parent MOC
// and tell the document it is dirty and needs to be saved
// It will be saved when the document decides its time to save
// but it *will* be saved.
[document updateChangeCount:UIDocumentChangeDone]
}
}];
}
Still had errors when the last path component for document file url was #"Database". Adding an extension #"Database.db" seems to have fixed it, everything running fine now. Have also upgraded to Lion though.
NSURL *url = [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject];
url = [url URLByAppendingPathComponent:#"Database.db"];

Google Analytics: GANTrackerError 195946409 - reason?

I'm using the Google Analytics library in my iPhone/iPad app; one part of the code sometimes throws an error, the [error localizedDescription] shows the following:
The operation couldn’t be completed. (com.google.googleanalytics.GANTrackerError error 195946409.
I didn't find any information about this error code; the app doesn't crash there, but I'm assuming that the tracking also doesn't work in that case. Does someone know the reason?
Thanks a lot!
Edit: the code in question:
[[GANTracker sharedTracker] setCustomVariableAtIndex:0
name:#"article"
value:[model name]
withError:&error];
got it: customVariableAtIndex must not be 0; it seems like it has to start at 1...
It appears this error 195946409 can appear for a number of reasons, not limited to just setting an incorrect index. For example, If your value is too long, you will get the same error.

Resources