Could the following code produce a crash on older devices? - iphone

I have this bit of code relating to my in app purchases for an SKProductRequest:
SKProductsRequest *request= [[SKProductsRequest alloc] initWithProductIdentifiers:...
request.delegate = self;
[request start];
[request release];
One of my users is getting a crash on an iPod4 and I think it might be from this, however, all other devices are able to run this code OK. Should request be saved in a property while its loading, could that be the issue? I would think with [request start], that request would be retained somewhere else.
Here is the crash log:
Last Exception Backtrace:
0 CoreFoundation 0x3275229e __exceptionPreprocess + 158
1 libobjc.A.dylib 0x3a3c597a objc_exception_throw + 26
2 CoreFoundation 0x3269ce88 -[__NSArrayI objectAtIndex:] + 160
3 AppsHappens Lite 0x000e43ac 0xd8000 + 50092
4 StoreKit 0x3450c22e __34-[SKProductsRequest _handleReply:]_block_invoke_0 + 378
5 libdispatch.dylib 0x3a7dd11a _dispatch_call_block_and_release + 6
6 libdispatch.dylib 0x3a7dc4b2 _dispatch_client_callout + 18
7 libdispatch.dylib 0x3a7dddc6 _dispatch_main_queue_callback_4CF$VARIANT$up + 222
8 CoreFoundation 0x32725f36 __CFRunLoopRun + 1286
9 CoreFoundation 0x32698eb8 CFRunLoopRunSpecific + 352
10 CoreFoundation 0x32698d44 CFRunLoopRunInMode + 100
11 GraphicsServices 0x362492e6 GSEventRunModal + 70
12 UIKit 0x345ae2fc UIApplicationMain + 1116
13 AppsHappens Lite 0x000e3a8e 0xd8000 + 47758
14 AppsHappens Lite 0x000dadb4 0xd8000 + 11700
Updated: A lot of folks below are saying that it's an array out of bounds error and I think they're right. Strange thing is though, it appears the product request is coming back successfully, and it's called ing [self loadFullVersionPrice] which simply extracts the price for one of my products. When it tries to retrieve the Full Version product from the products array, I think that's when it crashes. Is it possible the app store would only return some of my products and not all of them? Or some issue with an iPod4?
- (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response
{
self.products = response.products;
if (self.products)
{
[self loadFullVersionPrice];
}
}
- (void) loadFullVersionPrice
{
SKProduct *product = [[self.products objectAtIndex:[self.products count]-1] retain];
NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
[numberFormatter setFormatterBehavior:NSNumberFormatterBehavior10_4];
[numberFormatter setNumberStyle:NSNumberFormatterCurrencyStyle];
[numberFormatter setLocale:product.priceLocale];
self.fullVersionPrice = [numberFormatter stringFromNumber:product.price];
[numberFormatter release];
[product release];
}
Also, the iPod Touch 4 in question is jail broken.

Three reasons why this was occurring:
1) The user was on a jail broken phone
2) The version of my app he was installing was an ad hoc release
3) He was trying to access in app purchase
Apparently, jail broken phones are unable to access the sandbox (which is accessed when you try to do an app purchase on an ad hoc distribution).

Related

NSEntityDescription error while fetching the core data

here is my function for fetching core data
- (void)fetchRecords {
// Define our table/entity to use
NSEntityDescription *entity = [NSEntityDescription entityForName:#"Fugitive" inManagedObjectContext:managedObjectContext];
// Setup the fetch request
NSFetchRequest *request = [[NSFetchRequest alloc] init];
[request setEntity:entity];
// Define how we will sort the records
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:#"name" ascending:NO];
NSArray *sortDescriptors = [NSArray arrayWithObject:sortDescriptor];
[request setSortDescriptors:sortDescriptors];
[sortDescriptor release];
// Fetch the records and handle an error
NSError *error;
NSMutableArray *mutableFetchResults = [[managedObjectContext executeFetchRequest:request error:&error] mutableCopy];
if (!mutableFetchResults) {
NSLog(#"Error in Fetching Result");
// Handle the error.
// This is a serious error and should advise the user to restart the application
}
// Save our fetched data to an array
[self setFugitiveArray: mutableFetchResults];
[mutableFetchResults release];
[request release];
}
i got following error while running the program 'Program received signal: "SIGABRT"'
iBountyHunter[1013:207] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '+entityForName: could not locate an NSManagedObjectModel for entity name 'Fugitive''
*** Call stack at first throw:
(
0 CoreFoundation 0x011005a9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x01254313 objc_exception_throw + 44
2 CoreData 0x00e2aebb +[NSEntityDescription entityForName:inManagedObjectContext:] + 187
3 iBountyHunter 0x000030e6 -[FugitiveListViewController fetchRecords] + 86
4 iBountyHunter 0x00003411 -[FugitiveListViewController viewDidLoad] + 289
5 UIKit 0x00375f26 -[UINib instantiateWithOwner:options:] + 1556
6 UIKit 0x00377ab7 -[NSBundle(UINSBundleAdditions) loadNibNamed:owner:options:] + 168
7 UIKit 0x0017d17a -[UIApplication _loadMainNibFile] + 172
8 UIKit 0x0017dcf4 -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 291
9 UIKit 0x00188617 -[UIApplication handleEvent:withNewEvent:] + 1533
10 UIKit 0x00180abf -[UIApplication sendEvent:] + 71
11 UIKit 0x00185f2e _UIApplicationHandleEvent + 7576
12 GraphicsServices 0x01c48992 PurpleEventCallback + 1550
13 CoreFoundation 0x010e1944 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
14 CoreFoundation 0x01041cf7 __CFRunLoopDoSource1 + 215
15 CoreFoundation 0x0103ef83 __CFRunLoopRun + 979
16 CoreFoundation 0x0103e840 CFRunLoopRunSpecific + 208
17 CoreFoundation 0x0103e761 CFRunLoopRunInMode + 97
18 UIKit 0x0017d7d2 -[UIApplication _run] + 623
19 UIKit 0x00189c93 UIApplicationMain + 1160
20 iBountyHunter 0x00002519 main + 121
21 iBountyHunter 0x00002495 start + 53
)
terminate called after throwing an instance of 'NSException'
if you have declare in app delegate then you should check it like :
if (managedObjectContext == nil)
{
managedObjectContext = [(YourAppDelegate *)[[UIApplication sharedApplication] delegate] managedObjectContext];
NSLog(#" %#", managedObjectContext);
}

NSInternalInconsistencyException with NSUserDefaults when using method setValue: forPath

My code is as follows:
NSMutableDictionary *configure = [[NSUserDefaults standardUserDefaults] objectForKey:#"configure"];
if (!configure){
configure = [NSMutableDictionary dictionary];
[configure setValue:[NSMutableDictionary dictionary] forKeyPath:#"select"] ;
[configure setValue:[NSMutableDictionary dictionary] forKeyPath:#"select.around"];
[configure setValue: #"All" forKeyPath:#"select.around.name"];
[[NSUserDefaults standardUserDefaults] setObject:configure forKey:#"configure"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
NSString *keyPath = #"configure.select.around";
NSMutableDictionary *aroundConfigure = [[[NSUserDefaults standardUserDefaults] valueForKeyPath:keyPath] mutableCopy];
[aroundConfigure setObject:#"" forKey:#"name"];
[[NSUserDefaults standardUserDefaults] setValue:aroundConfigure forKeyPath:keyPath];
It's crashing every time with the error below:
** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[__NSCFDictionary setObject:forKey:]: mutating method sent to immutable object'
*** Call stack at first throw:
(
0 CoreFoundation 0x00daebe9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x00f035c2 objc_exception_throw + 47
2 CoreFoundation 0x00d67628 +[NSException raise:format:arguments:] + 136
3 CoreFoundation 0x00d6759a +[NSException raise:format:] + 58
4 CoreFoundation 0x00dad401 -[__NSCFDictionary setObject:forKey:] + 209
5 Foundation 0x0004b34d -[NSObject(NSKeyValueCoding) setValue:forKeyPath:] + 399
6 Foundation 0x0004b34d -[NSObject(NSKeyValueCoding) setValue:forKeyPath:] + 399
7 Untitled 0x00002429 -[UntitledAppDelegate application:didFinishLaunchingWithOptions:] + 774
8 UIKit 0x002b81fa -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 1163
9 UIKit 0x002ba55e -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 439
10 UIKit 0x002c4db2 -[UIApplication handleEvent:withNewEvent:] + 1533
11 UIKit 0x002bd202 -[UIApplication sendEvent:] + 71
12 UIKit 0x002c2732 _UIApplicationHandleEvent + 7576
13 GraphicsServices 0x016e4a36 PurpleEventCallback + 1550
14 CoreFoundation 0x00d90064 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
15 CoreFoundation 0x00cf06f7 __CFRunLoopDoSource1 + 215
16 CoreFoundation 0x00ced983 __CFRunLoopRun + 979
17 CoreFoundation 0x00ced240 CFRunLoopRunSpecific + 208
18 CoreFoundation 0x00ced161 CFRunLoopRunInMode + 97
19 UIKit 0x002b9fa8 -[UIApplication _run] + 636
20 UIKit 0x002c642e UIApplicationMain + 1160
21 Untitled 0x00002100 main + 102
22 Untitled 0x00002091 start + 53
)
terminate called after throwing an instance of 'NSException'
I know that setObject:forKey: should used with a mutable dictonary . Is there any problem using KVO with NSUserDefaults? By the way, the platform I use is iPhone.
Your code isn't doing what you think it is doing:
NSMutableDictionary *configure = [[NSUserDefaults standardUserDefaults] objectForKey:#"configure"];
This sets configure to be the value of your standard defaults to the value of the key configure
configure = [NSMutableDictionary dictionary];
This sets configure to a new, empty dictionary, not the one you got from User defaults
[configure setValue:[NSMutableDictionary dictionary] forKeyPath:#"select"] ;
You now put an empty dictionary as the value for the key select
[configure setValue:[NSMutableDictionary dictionary] forKeyPath:#"select.around"];
You are adding another empty dictionary for this key path
[configure setValue: #"All" forKeyPath:#"select.around.name"];
And you are setting a string value for this key path
[[NSUserDefaults standardUserDefaults] setObject:configure forKey:#"configure"];
You are now putting this odd dictionary into NSUserDefaults
[[NSUserDefaults standardUserDefaults] synchronize];
NSString *keyPath = #"configure.select.around";
NSMutableDictionary *aroundConfigure = [[[NSUserDefaults standardUserDefaults] valueForKeyPath:keyPath] mutableCopy];
This is just an empty mutable dictionary
[aroundConfigure setObject:#"" forKey:#"name"];
You are setting an empty string for some key in this dictionary
[[NSUserDefaults standardUserDefaults] setValue:aroundConfigure forKeyPath:keyPath];
And then you set this odd dictionary into the the user defaults.
Which is all very confusing.
What is it that you are trying to do?
Edited to add
There's no point providing code if you've "simplified" it we can't see what it's supposed to do.
Your app is crashing because you are trying to change a key value pair of a NSDictionary which is immutable instead of a NSMutableDictionary. See line 6 of your trace.
Since you've provided "simplified" code - I don't know where you are doing this.
Today i also faced this problem because i am making data in dictionary like this
NSMutableDictionary *Dic =[myMutableAry objectAtIndex:0];
after getting data when i am updating my dic value then getting crash
* Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[__NSCFDictionary
setObject:forKey:]: mutating method sent to immutable object'
Then i did got solution after a lot of research , so just do one thing
NSMutableDictionary *Dic = [NSMutableDictionary dictionaryWithDictionary:[myMutableAry objectAtIndex:0]];
The way you have used the NSUserDefaults is wrong, NSUserDefaults return a non mutable dictionary. That is the cause of this issue. Therefore, you have to request a mutable object explicitly from NSUserDefaults. Please use the code line below.
NSMutableDictionary *configure = [[[NSUserDefaults standardUserDefaults] objectForKey:#"configure"]mutableCopy];
This work with me.
Thanks Good luck :)

iPhone app crashes if view is swapped during data download

I have an iphone app that when the user clicks a row in a uitable, it takes the row value and downloads some data from the web to populate the next view. However if the user switches back to the first view when the data is being downloaded the app crashes. I think i've found the problem but need some help fixing it:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSManagedObject *selectedObject = [[self fetchedResultsController] objectAtIndexPath:indexPath];
BlogRssParser *blogRss = [[BlogRssParser alloc] init];
blogRss.terms = [[selectedObject valueForKey:#"data"] description];
RssFunViewController *rssFun = [[RssFunViewController alloc] initWithNibName:#"RssFunViewController" bundle:nil];
rssFun.rssParser = blogRss;
[blogRss release];
[self.navigationController pushViewController:rssFun animated:YES];
rssFun.navigationItem.title=blogRss.terms;
[rssFun release];
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
So where it says [self.navigationController pushViewController:rssFun animated:YES]; this is where it crashes because once it finishes the download this is the next line of code and it can push a view if its not on the right screen if that makes any sense!? Thanks for any advice anyway!
BlogRssParser:
-(BOOL)fetchAndParseRss{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
//To suppress the leak in NSXMLParser
[[NSURLCache sharedURLCache] setMemoryCapacity:0];
[[NSURLCache sharedURLCache] setDiskCapacity:0];
NSString *urlTerm = terms;
urlTerm = [urlTerm stringByReplacingOccurrencesOfString:#" " withString:#"+"];
urlTerm = [urlTerm stringByReplacingOccurrencesOfString:#"\t" withString:#""];
urlTerm = [urlTerm stringByReplacingOccurrencesOfString:#"&" withString:#""];
urlTerm = [urlTerm stringByReplacingOccurrencesOfString:#"'" withString:#""];
urlTerm = [urlTerm stringByReplacingOccurrencesOfString:#"-" withString:#""];
urlTerm = [urlTerm stringByReplacingOccurrencesOfString:#"_" withString:#""];
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:#"xxxxxxxxxxxxx/app.php?s=%#", urlTerm]];
NSLog(#"%#", url);
BOOL success = NO;
NSXMLParser *parser = [[NSXMLParser alloc] initWithContentsOfURL:url];
[parser setDelegate:self];
[parser setShouldProcessNamespaces:YES];
[parser setShouldReportNamespacePrefixes:YES];
[parser setShouldResolveExternalEntities:NO];
success = [parser parse];
[parser release];
[pool drain];
return success;
}
Console:
2010-12-06 19:15:09.826 Example[452:207] -[NSCFString processCompleted]: unrecognized selector sent to instance 0x6123d30
2010-12-06 19:15:09.855 Example[452:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSCFString processCompleted]: unrecognized selector sent to instance 0x6123d30'
*** Call stack at first throw:
(
0 CoreFoundation 0x02664b99 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x027b440e objc_exception_throw + 47
2 CoreFoundation 0x026666ab -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3 CoreFoundation 0x025d62b6 ___forwarding___ + 966
4 CoreFoundation 0x025d5e72 _CF_forwarding_prep_0 + 50
5 Foundation 0x000423ca __NSThreadPerformPerform + 251
6 CoreFoundation 0x02645faf __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
7 CoreFoundation 0x025a439b __CFRunLoopDoSources0 + 571
8 CoreFoundation 0x025a3896 __CFRunLoopRun + 470
9 CoreFoundation 0x025a3350 CFRunLoopRunSpecific + 208
10 CoreFoundation 0x025a3271 CFRunLoopRunInMode + 97
11 GraphicsServices 0x02f4300c GSEventRunModal + 217
12 GraphicsServices 0x02f430d1 GSEventRun + 115
13 UIKit 0x002d1af2 UIApplicationMain + 1160
14 Example 0x0000244a main + 84
15 Example 0x000023ed start + 53
)
terminate called after throwing an instance of 'NSException'
unrecognized selector means that you've attempted to send a message to an object that doesn't know how to handle it.
For example, suppose you had a class AlienParser and it had two methods: land and probe. You create an instance of it called myParser, and then tried to call [myParser destroyAllHumans]. The resulting object wouldn't know what to do, and you'd get an exception thrown. It compiles because you can send any message to anything with Obj-C, because at runtime it may know how to handle it even if the compiler couldn't detect so.
Somewhere (the hex is your clue, it doesn't show a full backtrace) you've got some code calling another object with a message it just plain doesn't support. It's probably worth mentioning that ANY message to nil does nothing and returns nil so you've obviously got an actual object there you are sending messages to.
Have you tried downloading the XML in a background thread? This may alleviate some of the issues as the main thread won't be blocked. You should be able to push on the RssFunViewController while the XML is/being downloaded.

iPad app works on most devices, gets EXC_CRASH (SIGABRT) on some

I created this awesome iPad game - clean and fun to play, and people that manage to play it more than once love it.
In some cases, however, it will not launch for the second time.
I can't debug it since it works perfect on my iPad, simulator and on all my friend's iPads.
One customer told me that it works on 32GB but not on 64GB iPads - could this be it?
Any help would be appreciated - this is sinking my ratings (and for a good reason, unfortunately)
Would love to give out promo code to anyone willing to look into this.
Thanks!!
Hanaan
From My AppDelegate, if helps:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.playerName = [[NSUserDefaults standardUserDefaults] objectForKey:#"player_name"];
if(self.playerName == nil){
self.playerName = #"nono";
self.pref_currentPuzzleNumberHintsString = #"";
self.pref_currentPuzzleFinishedSolutionString = #"";
self.pref_currentPlayerMarksString = #"";
self.pref_marksCompleteString = #"";
self.pref_currentPuzzleId = -1;
self.pref_gameInProgress = NO;
self.pref_soundOn = YES;
self.pref_buttonsOnLeft = NO;
self.pref_gameTimerValue = 0;
self.pref_gameSize = 0;
NSNumber *pref_gameInProgress_temp = [NSNumber numberWithInt:0];
NSNumber *pref_soundOn_temp = [NSNumber numberWithInt:1];
NSNumber *pref_buttonsOnLeft_temp = [NSNumber numberWithInt:0];
NSNumber *pref_gameNumber_temp = [NSNumber numberWithInt:self.pref_currentPuzzleId];
NSNumber *pref_gameSize_temp = [NSNumber numberWithInt:self.pref_gameSize];
NSNumber *pref_gameTimer_temp = [NSNumber numberWithInt:self.pref_gameTimerValue];
NSUserDefaults *standardUserDefaults = [NSUserDefaults standardUserDefaults];
[standardUserDefaults setObject:self.pref_currentPuzzleFinishedSolutionString forKey:#"game_string"];
[standardUserDefaults setObject:self.pref_currentPuzzleNumberHintsString forKey:#"hint_string"];
[standardUserDefaults setObject:self.pref_currentPlayerMarksString forKey:#"solution_string"];
[standardUserDefaults setObject:self.pref_marksCompleteString forKey:#"marks_complete_string"];
[standardUserDefaults setObject:pref_gameNumber_temp forKey:#"game_id"];
[standardUserDefaults setObject:pref_gameSize_temp forKey:#"game_size"];
[standardUserDefaults setObject:pref_gameTimer_temp forKey:#"game_timer_value"];
[standardUserDefaults setObject:pref_gameInProgress_temp forKey:#"game_in_progress"];
[standardUserDefaults setObject:pref_soundOn_temp forKey:#"sound_on"];
[standardUserDefaults setObject:pref_buttonsOnLeft_temp forKey:#"buttons_on_left"];
[standardUserDefaults setObject:self.playerName forKey:#"player_name"];
[[NSUserDefaults standardUserDefaults] synchronize];
[pref_gameInProgress_temp release];
[pref_gameSize_temp release];
[pref_soundOn_temp release];
[pref_gameTimer_temp release];
[pref_gameNumber_temp release];
[pref_buttonsOnLeft_temp release];
}else {
self.pref_currentPlayerMarksString = [[NSUserDefaults standardUserDefaults] objectForKey:#"game_string"];
self.pref_currentPuzzleNumberHintsString = [[NSUserDefaults standardUserDefaults] objectForKey:#"hint_string"];
self.pref_currentPuzzleFinishedSolutionString = [[NSUserDefaults standardUserDefaults] objectForKey:#"solution_string"];
self.pref_marksCompleteString = [[NSUserDefaults standardUserDefaults] objectForKey:#"marks_complete_string"];
self.pref_currentPuzzleId = [[[NSUserDefaults standardUserDefaults] objectForKey:#"game_id"]intValue];
self.pref_gameSize = [[[NSUserDefaults standardUserDefaults] objectForKey:#"game_size"]intValue];
self.pref_gameTimerValue = [[[NSUserDefaults standardUserDefaults] objectForKey:#"game_timer_value"]intValue];
int pref_gameInProgress_temp = [[[NSUserDefaults standardUserDefaults] objectForKey:#"game_in_progress"]intValue];
self.pref_gameInProgress = (pref_gameInProgress_temp == 1);
int pref_soundOn_temp = [[[NSUserDefaults standardUserDefaults] objectForKey:#"sound_on"]intValue];
self.pref_soundOn = (pref_soundOn_temp == 1);
int pref_buttonsOnLeft_temp = [[[NSUserDefaults standardUserDefaults] objectForKey:#"buttons_on_left"]intValue];
self.pref_buttonsOnLeft = (pref_buttonsOnLeft_temp == 1);
//NSLog(#"Saved game: %#",self.pref_currentPlayerMarksString);
}
// Add the view controller's view to the window and display.
[window addSubview:viewController.view];
[window makeKeyAndVisible];
return YES;
}
The log I got from a customer has this:
--
Incident Identifier: 1581089C-C02A-4155-9493-9E42B9AAB37D
CrashReporter Key: a913e5f82c7112b47b354f04909239bff1b39000
Hardware Model: iPad1,1
Process: Nonograms [193]
Path: /var/mobile/Applications/4F03245E-CFB8-4181-B881-859FDAEE18C7/Nonograms.app/Nonograms
Identifier: Nonograms
Version: ??? (???)
Code Type: ARM (Native)
Parent Process: launchd [1]
Date/Time: 2010-08-21 16:31:11.002 +0200
OS Version: iPhone OS 3.2.2 (7B500)
Report Version: 104
SYMBOLIZED:
Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x00000000, 0x00000000
Crashed Thread: 0
Thread 0 Crashed:
0 libSystem.B.dylib 0x000790a0 __kill + 8
1 libSystem.B.dylib 0x00079090 kill + 4
2 libSystem.B.dylib 0x00079082 raise + 10
3 libSystem.B.dylib 0x0008d20a abort + 50
4 libstdc++.6.dylib 0x00044a1c __gnu_cxx::__verbose_terminate_handler() + 376
5 libobjc.A.dylib 0x000057c4 _objc_terminate + 104
6 libstdc++.6.dylib 0x00042dee __cxxabiv1::__terminate(void (*)()) + 46
7 libstdc++.6.dylib 0x00042e42 std::terminate() + 10
8 libstdc++.6.dylib 0x00042f12 __cxa_throw + 78
9 libobjc.A.dylib 0x000046a4 objc_exception_throw + 64
10 CoreFoundation 0x00094174 -[NSObject doesNotRecognizeSelector:] + 108
11 CoreFoundation 0x00093afa ___forwarding___ + 482
12 CoreFoundation 0x000306c8 _CF_forwarding_prep_0 + 40
13 Nonograms 0x00003238 0x1000 + 8760
14 UIKit 0x00003e58 -[UIApplication _performInitializationWithURL:payload:] + 336
15 UIKit 0x00003b22 -[UIApplication _runWithURL:payload:launchOrientation:] + 394
16 UIKit 0x0004f8c4 -[UIApplication handleEvent:withNewEvent:] + 1336
17 UIKit 0x0004f242 -[UIApplication sendEvent:] + 38
18 UIKit 0x0004ec8c _UIApplicationHandleEvent + 4772
19 GraphicsServices 0x00003b2c PurpleEventCallback + 660
20 CoreFoundation 0x00022d96 CFRunLoopRunSpecific + 2214
21 CoreFoundation 0x000224da CFRunLoopRunInMode + 42
22 UIKit 0x0000340a -[UIApplication _run] + 342
23 UIKit 0x00001954 UIApplicationMain + 636
24 Nonograms 0x00002538 0x1000 + 5432
25 Nonograms 0x00002508 0x1000 + 5384
You need to find the line of code that frame 13 of your stack trace represents.
I would hope that you used the "Build and Archive" feature of the recent versions of Xcode. In this case, all you would need to do is drag and drop the crash log to the Xcode Organizer. This will "symbolicate" the crash log, meaning that it will convert the addresses to classes and methods.
Once you know the line that caused the error it will (hopefully) be relatively simple to figure out what went wrong. My guess would be memory corruption of some description -- a value you assumed you saved on the first run isn't there or something.
I think some object or UI element of yours is getting released (deallocated), but you expect it to still exist:
http://www.iphonedevsdk.com/forum/iphone-sdk-development/51235-crash-log-help.html
The problem was releasing unowned objects...
[pref_gameInProgress_temp release];
[pref_gameSize_temp release];
[pref_soundOn_temp release];
[pref_gameTimer_temp release];
[pref_gameNumber_temp release];
[pref_buttonsOnLeft_temp release];
I dont know the specifics of the iPad and obj-c development.
However, this looks like memory corruption and/or dangling pointers in some way.
For example, you could be modifying an array beyond its bounds. Double check all your loops and add debug asserts that verify the bounds.
Another possibility is that you could be using pointers to objects that have been deleted, and writing/interpreting this memory has undefined effects. Usually it just crashes.
Or you could have uninitialized pointers.
All of this falls into the category that I like to call The Insanity of Developing Applications in C/C++/etc. Unchecked buffer bounds, manual memory deallocation, and unguarded call stack memory are just nutty ideas w/r to modern application development.

Save and Retrieve of an UIImage on CoreData

In my app, I am trying to save and retrieval of an image in core data. I am able to save an image successfully after convention of UIimage into NSData, But when I am trying to get an image as NSData it shows output as given below,
case 1: When trying to display as a string from DB.
<Event: 0x5b5d610> (entity: Event; id: 0x5b5ce30 <x-coredata://F51BBF1D-6484-4EB6-8583-147E23D9FF7B/Event/p1> ; data: <fault>)
case 2: When trying to display as Data
[Event length]: unrecognized selector sent to instance 0x5b3a9c0
2010-07-28 19:11:59.610 IMG_REF[10787:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Event length]: unrecognized selector sent to instance 0x5b3a9c0'
My code,
to save:
NSManagedObjectContext *context = [self managedObjectContext];
newsObj = [NSEntityDescription insertNewObjectForEntityForName:#"Event" inManagedObjectContext:context];
NSURL *url = [NSURL URLWithString:#"http://www.cimgf.com/images/photo.PNG"];
NSData *data = [[NSData alloc] initWithContentsOfURL:url];
uiImage = [UIImage imageWithData:data];
NSData * imageData = UIImagePNGRepresentation(uiImage);
[newsObj setValue:imageData forKey:#"imgPng"];
NSError *error;
#try{
if (managedObjectContext != nil) {
if (![managedObjectContext save:&error]) {
NSLog(#"Unresolved error %#, %#", error, [error userInfo]);
NSString * infoString = [NSString stringWithFormat:#"Please check your connection and try again."];
UIAlertView * infoAlert = [[UIAlertView alloc] initWithTitle:#"Database Connection Error" message:infoString delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
[infoAlert show];
[infoAlert release];
}
}
}#catch (NSException *exception) {
NSLog(#"inside exception");
}
to retrieve,
NSManagedObjectContext *context = [self managedObjectContext];
NSFetchRequest * fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity1 = [NSEntityDescription entityForName:#"Event" inManagedObjectContext:context];
[fetchRequest setEntity:entity1];
NSError *error;
NSArray * array = [self.managedObjectContext executeFetchRequest:fetchRequest error:&error];
if (array == nil) {
NSLog(#"Testing: No results found");
}else {
NSLog(#"Testing: %d Results found.", [array count]);
}
NSData * dataBytes = [[array objectAtIndex:0] data];
image = [UIImage imageWithData:dataBytes];
[fetchRequest release];
}
#catch (NSException *exception) {
NSLog(#"inside exception");
}
Error:
Testing: 3 Results found.
2010-07-28 23:27:51.343 IMG_REF[11657:207] -[Event data]: unrecognized selector sent to instance 0x5e22ce0
2010-07-28 23:27:51.344 IMG_REF[11657:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Event data]: unrecognized selector sent to instance 0x5e22ce0'
*** Call stack at first throw:
(
0 CoreFoundation 0x02566919 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x026b45de objc_exception_throw + 47
2 CoreFoundation 0x0256842b -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3 CoreFoundation 0x024d8116 ___forwarding___ + 966
4 CoreFoundation 0x024d7cd2 _CF_forwarding_prep_0 + 50
5 IMG_REF 0x00003b06 -[IMG_REFViewController showAction] + 353
6 UIKit 0x002bae14 -[UIApplication sendAction:to:from:forEvent:] + 119
7 UIKit 0x004c214b -[UIBarButtonItem(UIInternal) _sendAction:withEvent:] + 156
8 UIKit 0x002bae14 -[UIApplication sendAction:to:from:forEvent:] + 119
9 UIKit 0x003446c8 -[UIControl sendAction:to:forEvent:] + 67
10 UIKit 0x00346b4a -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 527
11 UIKit 0x003456f7 -[UIControl touchesEnded:withEvent:] + 458
12 UIKit 0x002de2ff -[UIWindow _sendTouchesForEvent:] + 567
13 UIKit 0x002c01ec -[UIApplication sendEvent:] + 447
14 UIKit 0x002c4ac4 _UIApplicationHandleEvent + 7495
15 GraphicsServices 0x02dccafa PurpleEventCallback + 1578
16 CoreFoundation 0x02547dc4 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
17 CoreFoundation 0x024a8737 __CFRunLoopDoSource1 + 215
18 CoreFoundation 0x024a59c3 __CFRunLoopRun + 979
19 CoreFoundation 0x024a5280 CFRunLoopRunSpecific + 208
20 CoreFoundation 0x024a51a1 CFRunLoopRunInMode + 97
21 GraphicsServices 0x02dcb2c8 GSEventRunModal + 217
22 GraphicsServices 0x02dcb38d GSEventRun + 115
23 UIKit 0x002c8b58 UIApplicationMain + 1160
24 IMG_REF 0x00002aac main + 102
25 IMG_REF 0x00002a3d start + 53
)
terminate called after throwing an instance of 'NSException'
Note: Above error is coming when going to execute NSData * dataBytes = [[array objectAtIndex:0] data]; line.
Data Model http://www.freeimagehosting.net/uploads/7c286931cc.png
I spent a lot of time with this. Please help me out!
Not sure if you've gotten this straightened out yet, but I am able to save/retrieve UIImage objects in Core Data as follows:
To save:
NSData *imageData = UIImagePNGRepresentation(yourUIImage);
[newManagedObject setValue:imageData forKey:#"image"];
and to load:
NSManagedObject *selectedObject = [[self fetchedResultsController] objectAtIndexPath:indexPath];
UIImage *image = [UIImage imageWithData:[selectedObject valueForKey:#"image"]];
[[newCustomer yourImageView] setImage:image];
Hope this helps. I am using a UITableView with Core Data and pulling the image from the database in my tableView:didSelectRowAtIndexPath: method.
Here's the proper solution that works very well.
1) Storing UIImage with Core Data:
NSData* coreDataImage = [NSData dataWithData:UIImagePNGRepresentation(delegate.dancePhoto)];
Make sure that "coreDataImage" is of type NSData. You have to set type to "Binary data" for "coreDataImage" in your model.
2) Retrieving UIImage from Core Data:
UIImage* image = [UIImage imageWithData:selectedDance.danceImage];
That's all there's to it, works great.
When you retrieve the image, you're performing the fetch request and storing the results in the variable array, meaning array holds an NSArray of Event objects. Then, later, you assign:
dataBytes = [array objectAtIndex:0];
This means that dataBytes, which you declared as NSData, is now actually an instance of Event. Then when you go to initialize the image, part of the implementation of imageWithData: calls length on what it expects to be your NSData object, but is actually an Event object, hence the error message.
You should adjust your code to read:
dataBytes = [[array objectAtIndex:0] imgPng];
That way, you're getting the first Event object out of the array, then fetching its imgPng property (an instance of NSData, which is what you want).
As a side note, your declaration of dataBytes using the alloc-init on the line above may be extraneous, since you change dataBytes to be the data from your Event immediately afterwards.
The Solution I used was to create the category bellow. You just need it in your project for it to work. Using this storing images works just like you where storing an NSData
UIImage+NSCoding.h
#interface UIImage (UIImage_NSCoding) <NSCoding>
- (void)encodeWithCoder:(NSCoder *)aCoder;
- (id)initWithCoder:(NSCoder *)aDecoder;
#end
UIImage+NSCoding.m
#import "UIImage+NSCoding.h"
#implementation UIImage (UIImage_NSCoding)
- (void)encodeWithCoder:(NSCoder *)aCoder
{
NSData *imageData = UIImagePNGRepresentation(self);
[aCoder encodeDataObject:imageData];
}
- (id)initWithCoder:(NSCoder *)aDecoder
{
[self autorelease];
NSData* imageData = [aDecoder decodeDataObject];
self = [[UIImage alloc] initWithData:imageData];
return self;
}
#end
This sample code has example how to store UIImage in Core Data:
https://developer.apple.com/library/ios/#samplecode/PhotoLocations/Introduction/Intro.html