SKProduct productIdentifier unrecognized selector sent to instance - iphone

I'm trying to implement in iPhone in app purchase in my app.
I have an IBAction on a button to buy a mini-game :
-(IBAction) buyGame:(id)sender {
SKProduct *product = [[InAppGameIAHelper sharedHelper].products objectAtIndex:0];
NSLog(#"Buying %#...", product.productIdentifier);
[[InAppGameIAHelper sharedHelper] buyProductIdentifier:product.productIdentifier];
self.hud = [MBProgressHUD showHUDAddedTo:self.navigationController.view animated:YES];
_hud.labelText = #"Buying...";
[self performSelector:#selector(timeout:) withObject:nil afterDelay:60*5];
}
[InAppGameIAHelper sharedHelper] allows to load the items from the store, and to load the list of product.
[InAppGameIAHelper sharedHelper].products is a NSArray :
products (
"com.me.myapp"
)
There when I am tapping the buy button my app getting crashed and getting the following error :
2013-03-04 20:24:50.314 isam[11922:c07] -[__NSCFConstantString productIdentifier]: unrecognized selector sent to instance 0x22ae30
2013-03-04 20:24:50.318 isam[11922:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFConstantString productIdentifier]: unrecognized selector sent to instance 0x22ae30'

is the
SKProduct *product = [[InAppGameIAHelper sharedHelper].products objectAtIndex:0]; line actually returning you a SKProduct?
My guess is your code is crashing before it can print the NSLog because your method is returning somehow an NSString.

Related

NSDictionary Error Handling

I am creating this application but I don't know how to handle the error when there is no value for a given entry in the NSDictionary. Here is the code that I have currently:
NSDictionary *entry = [self entries][indexPath.row];
NSDictionary *text = [self entries][indexPath.row];
NSString *user = entry[#"user"][#"full_name"];
NSString *caption = text[#"caption"][#"text"];
if (caption != nil && entry != [NSNull null] && text != nil && caption != [NSNull null]) {
RNBlurModalView *modal = [[RNBlurModalView alloc] initWithViewController:self title:user message:caption];
[modal show];
}
Here is the error response I receive when I tap on a cell without any caption:
2013-08-08 02:36:57.871 Floadt[5566:c07] -[NSNull objectForKeyedSubscript:]: unrecognized selector sent to instance 0x310b678
2013-08-08 02:36:57.872 Floadt[5566:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSNull objectForKeyedSubscript:]: unrecognized selector sent to instance 0x310b678'
*** First throw call stack:
(0x2fda012 0x260be7e 0x30654bd 0x2fc9bbc 0x2fc994e 0x5606b 0x1c7a42f 0x1c8c182 0x1c8c394 0x261f705 0x188693c 0x18869ac 0x261f705 0x188693c 0x18869ac 0x1a401d3 0x2fa2afe 0x2fa2a3d 0x2f807c2 0x2f7ff44 0x2f7fe1b 0x2bb77e3 0x2bb7668 0x1778ffc 0x2d2d 0x2c55)
libc++abi.dylib: terminate called throwing an exception
Not clear why entry and text are the same thing. That could be a typo that is causing you issues:
NSDictionary *entry = [self entries][indexPath.row];
NSDictionary *text = [self entries][indexPath.row];
Then, you should really use isEqual for your equality checks (even if only to prevent you getting into bad habits) and check the obtained values (you don't currently check user):
if (![user isEqual:[NSNull null]] && ![caption isEqual:[NSNull null]]) {
Your current checks are mostly redundant - you need to check things before you use them, not afterwards. Checking entry and text must be done earlier. Then check user and caption.
Why you are using two NSDictionary though they store same value [self entries][indexPath.row]?
Change your checking as follow
if (!caption && ([entry isKindOfClass:[NSDictionary class]]) && ([text isKindOfClass:[NSDictionary class]]))

MFMessageComposeViewController init crashes app when run through iphone

the following code:
-(void)sendSMS
{
NSUserDefaults *standardUserDefaults = [NSUserDefaults standardUserDefaults];
if ([MFMessageComposeViewController canSendText])
{
self.msgController = [[MFMessageComposeViewController alloc]init];
self.msgController.messageComposeDelegate = self;
self.msgController.body = [standardUserDefaults objectForKey:#"geoAlarmDistressFlareMsgText"];
self.msgController.recipients = [standardUserDefaults objectForKey:#"geoAlarmDistressFlareTelNumbers"];
[self presentModalViewController:self.msgController animated:YES];
}
}
...causes the app to crash when run on my iphone at the [[MFMessageComposeViewController alloc]init]; line with the following error:
* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString count]: unrecognized selector sent to instance
I don't understand why - the msgController is declared (and synthesized) as a MFMessageComposeViewController, and i have declared the delegate and delegate method. Any ideas? No other questions on here seem to be asking the same question...

confused as how to use componentsSeparatedByString on iphone

after nsXml pasring value of my NSMutable array AB
=\n\n\n\thttp://xyz.com/uploads/resto_6298__20091209#1621_250.JPG\n\thttp://xyz.com/uploads/resto_6298__200912099_2_250.JPG\n"
now i am doing this to make this url working
NSString *sw=AB;
NSArray *strings = [sw componentsSeparatedByString: #"\n\t"];
NSLog(#"what I have %#",strings);
but my app always crash and i am getting this error
[NSCFArray componentsSeparatedByString:]: unrecognized selector sent to instance 0x1b28b0
2010-10-05 10:17:31.382 Wat2Eat[2311:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSCFArray componentsSeparatedByString:]: unrecognized selector sent to instance 0x1b28b0'
how to parse this AB so that i can extract exact URL
NSString *sw=AB;
AB is an NSMutableArray?
the compiler should print a warning if you try to do this. You tried to assign an NSArray to an NSString. This will not work.
Did you mean NSString *sw = [AB objectAtIndex:foo]; ?

Searching an NSMutableArray with a String and returning the entire compared Array

it seems my Problem isn't a problem for anybody eles because I havend fount anything about it.
so it maybe isn't such a big Problem but for me it is.
I have this MutableArray filled with alot of data from an XML file.
-Name -Age -Address
The search goes for the Name, and the filtering works pretty fine so far.
what I do is search the array with rangeOfString but that only returns the String (-Name) and not the Array with it's content like the original Array because its only a string now.
can anyone tell me how do I accomplish this
That's my search so far
if ([[self searcher] length] != 0)
{
for (NSString *currentString in [self listOfContent])
{
if ([currentString rangeOfString:searchTerm options:NSCaseInsensitiveSearch].location != NSNotFound)
{
[[self filteredListOfContent] addObject:currentString];
}
searcher is the String in the SearchBar.
or is there any other more efficent way or is it possible to search for any value in the MutipleArry?!?
Any Ideas and suggestions are welcome
I changed the code to this
NSString *searchText = searchBar.text;
NSMutableArray *searchArray = [[NSMutableArray alloc] init];
for (NSDictionary *dictionary in listOfContent)
{
//NSArray *array = [dictionary objectForKey:LNAME];
[searchArray addObject:dictionary];
}
for (NSString *sTemp in searchArray)
{
NSLog(#"array %#", searchArray);
if ([sTemp rangeOfString:searchText options:NSCaseInsensitiveSearch].location != NSNotFound)
[filteredListOfContent addObject:searchArray];
}
the log shows that the filter seems to work but then I get this error
2010-10-22 16:18:09.708 TableView[6114:207] -[__NSCFDictionary rangeOfString:options:]: unrecognized selector sent to instance 0x5c3f540
2010-10-22 16:18:09.712 TableView[6114:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFDictionary rangeOfString:options:]: unrecognized selector sent to instance 0x5c3f540'
can anyone tell me what the problem is
And Still no solution found I changed the Code to this:
NSMutableArray *searchArray = [[NSMutableArray alloc] init];
for (NSDictionary *dictionary in contentsList)
{
NSArray *array = [dictionary allValues];
[searchArray addObjectsFromArray:array];
}
for (NSDictionary *dict in searchArray)
{
if ([[dict valueForKey:#"NAME"] rangeOfString:searchTerm options:NSCaseInsensitiveSearch].location != NSNotFound) {
NSLog(#"Filter %#", dict);
[searchResults addObject:dict];
}
now i Have the array with the values but still get the error
2010-10-28 16:23:46.124 TableViews[8373:207] *** Terminating app due to uncaught exception
'NSInvalidArgumentException', reason: '-[NSCFString objectForKey:]: unrecognized selector sent to instance 0x5a5eb00'
can anyone explain me waht taht that error means or waht I did wrong?!?
2010-10-28 16:23:46.124 TableViews[8373:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSCFString objectForKey:]: unrecognized selector sent to instance 0x5a5eb00'
That error means you treated an NSString as if it were an NSDictionary by sending the message -objectForKey: to it.

NSCFArray length]: error, array regex

StringReply = [[NSString alloc] initWithData:dataReply encoding:NSUTF8StringEncoding];
//Regex Out Artist Name
//NSString *regEx = ;
NSArray *iTunesAristName = [stringReply componentsMatchedByRegex: #"(?<=artistname\":\")([^<]+)(?=\")"];
if ([iTunesAristName isEqual:#""]) {
NSLog(#"Something has messed up");
//Regex Out Song Name
}else{
NSLog(iTunesAristName);
}
NSLog(iTunesAristName);
[stringReply release];
I just keep getting this error ?
2010-09-29 21:15:16.406 [2073:207] *** -[NSCFArray length]: unrecognized selector sent to instance 0x4b0b800
2010-09-29 21:15:16.406 [2073:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSCFArray length]: unrecognized selector sent to instance 0x4b0b800'
2010-09-29 21:15:16.407 [2073:207] Stack: (
please help its driving me crazy
The first argument to NSLog is supposed to be a format string. You're passing an NSArray. When the function tries to treat your array as a string, you get that error. Instead, use NSLog(#"%#", iTunesAristName);.
Chuck has answered your question, but I've noticed something else that is problematic.
NSArray is an array, not a string, so [iTunesArtistName isEqual:#""] will never return true, because they are different classes. Even if iTunesArtistName was a string, it should be compared using the isEqualToString: method, not isEqual:.
If you want to extract only the artist's name, you might be able to do this:
NSArray *matches = [stringReply componentsMatchedByRegex: #"(?<=artistname\":\")([^<]+)(?=\")"];
if ([matches count] == 0)
{
NSLog(#"Could not extract the artist name");
}
else
{
NSString *iTunesArtistName = [matches objectAtIndex:0];
NSLog(#"Artist name: %#", iTunesArtistName);
}
I see you're using RegexKitLite, make sure you import libicucore.dylib, i was getting the same error until i imported that library.