MFMessageComposeViewController init crashes app when run through iphone - ios5

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

Related

viewDidLoad using Persistence

I have problem with my Iphone project in viewDidLoad event the app crash on
NSKeyedUnarchiver *unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:data];
I am trying to store information from text Filed can someone help me to solve the problem
- (void)viewDidLoad{
NSString *filePath = [self dataFilePath];
if ([[NSFileManager defaultManager] fileExistsAtPath:filePath]) {
NSArray *array = [[NSArray alloc] initWithContentsOfFile:filePath];
for (int i = 0; i < 2; i++) {
UITextField *theField = self.lineFields[i];
theField.text = array[i];
}
NSData *data = [[NSMutableData alloc]
initWithContentsOfFile:filePath];
NSKeyedUnarchiver *unarchiver = [[NSKeyedUnarchiver alloc]
initForReadingWithData:data];
BIDThreeLines *threelines = [unarchiver decodeObjectForKey:kRootKey];
[unarchiver finishDecoding];
for (int i = 0; i < 2; i++) {
UITextField *theField = self.lineFields[i];
theField.text = threelines.lines[i];
}
}
UIApplication *app = [UIApplication sharedApplication];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:#selector(applicationWillResignActive:)
name:UIApplicationWillResignActiveNotification
object:app];
}
Error
2013-03-25 23:29:45.592 MobilePaymentsApp[1182:c07] -[__NSCFArray objectForKey:]: unrecognized selector sent to instance 0x8d0e8d0
2013-03-25 23:29:45.593 MobilePaymentsApp[1182:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFArray objectForKey:]: unrecognized selector sent to instance 0x8d0e8d0'
*** First throw call stack:
(0x1c96012 0x10d3e7e 0x1d214bd 0x1c85bbc 0x1c8594e 0x1c0ae18 0xb030e8 0x339c 0xf91c7 0xf9232 0x483d5 0x4876f 0x48905 0x51917 0x2cc5 0x15157 0x15747 0x1694b 0x27cb5 0x28beb 0x1a698 0x1bf1df9 0x1bf1ad0 0x1c0bbf5 0x1c0b962 0x1c3cbb6 0x1c3bf44 0x1c3be1b 0x1617a 0x17ffc 0x29fd 0x2925)
libc++abi.dylib: terminate called throwing an exception
(lldb)
https://github.com/a-elnajjar/MobilePaymentsApp
NSKeyedArchiver returns object that you have stored in it. eg. if you have stored an array then it will return an array. so be careful while unarchiveing objects.
in following example i have read an array from NSKeyedUnarchiver.
NSData *data = [[NSMutableData alloc] initWithContentsOfFile:filePath];
NSArray *arr = [NSKeyedUnarchiver unarchiveObjectWithData:data];
Look in the crash log's stack trace to see where exactly this call is
happening.
If the variable you're sending -row to isn't actually typed as an
NSArray, it's likely that you've failed to follow the memory
management rules for that variable. These same symptoms are very
commonly caused by that. Something that responds to -row could have
existed at one point, been deallocated because you didn't -retain it,
and then an NSArray was later allocated in that spot.
Run a "Build & Analyze," and re-re-review the memory management
guidelines until you know them in your sleep.
Source: [NSCFArray row]: unrecognized selector sent to instance 0x3953a20

SKProduct productIdentifier unrecognized selector sent to instance

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.

ios memory leak

I have a method that sets up NSXMLParser with the correct data that I am pretty sure is causing a memory leak.
This is my first time using instriments to try and solve a memory leak and have got it down to the offending method..
by looking at the response caller value in instruments memory leak testing.
I am hoping you can tell me where the memory leak is here... because I release both myDataArray and parser... im just not sure where I am going wrong.. do I need to assign them nil also?
- (void)startTheParsingProcess:(NSData *)parserData
{
[myDataArray release]; // clears array for next time it is used.
myDataArray = [[NSMutableArray alloc] init];
NSXMLParser *parser = [[NSXMLParser alloc] initWithData:parserData]; //parserData passed to NSXMLParser delegate which starts the parsing process
[parser setDelegate:self];
[parser parse]; // starts the event-driven parsing operation.
[parser release];
}
any help would be appreciated.
UPDATE:
I have made the changes to my application and when I run it on the simulator I do not get any memory leak errors..
however if I run it on my phone get this in the console...
2011-10-19 11:22:05.673 code[1299:707] -[__NSCFType section]: unrecognized selector sent to instance 0x1b9b80
2011-10-19 11:22:05.683 code[1299:707] CoreAnimation: ignoring exception: -[__NSCFType section]: unrecognized selector sent to instance 0x1b9b80
2011-10-19 11:22:07.949 code[1299:707] -[__NSCFType row]: unrecognized selector sent to instance 0x1b9b80
2011-10-19 11:22:07.951 code[1299:707] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFType row]: unrecognized selector sent to instance 0x1b9b80'
*** First throw call stack:
(0x35e9e8b3 0x366e61e5 0x35ea1acb 0x35ea0939 0x35dfb680 0x334a76cf 0x3353c713 0x30fd5 0x3352cd69 0x335a60ab 0x35cc32ab 0x35e72a57 0x35e726bd 0x35e71293 0x35df44e5 0x35df43ad 0x30fa4fed 0x334a7dc7 0x272f 0x26d8)
Try putting this in the .h
#property (nonatomic, retain) NSMutableArray *myDataArray
.m
#synthesize myDataArray
in the method...
- (void)startTheParsingProcess:(NSData *)parserData
{
self.myDataArray = [NSMutableArray arrayWithCapacity:8];
NSXMLParser *parser = [[NSXMLParser alloc] initWithData:parserData]; //parserData passed to NSXMLParser delegate which starts the parsing process
[parser setDelegate:self];
[parser parse]; // starts the event-driven parsing operation.
[parser release];
}

iPhone - UILocalNotification fireDate problem

I'm trying to get the fireDate from an already set notification
Heres my code:
NSArray *notificationArray = [[NSArray alloc] initWithObjects:[[UIApplication sharedApplication] scheduledLocalNotifications], nil];
if ([notificationArray count] > 0) {
NSDate *now = [NSDate date];
UILocalNotification *locNotification = [[UILocalNotification alloc] init];
locNotification = [notificationArray objectAtIndex:0];
NSDate *otherDate = locNotification.fireDate;
}
The locNotification has the values but the last line when I try to instantiate otherDate I'm getting
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayM fireDate]: unrecognized selector sent to instance 0x1e4e20'
* Call stack at first throw:
I really don't know what I'm doing wrong.
Thanks in advance
You're using the wrong init method. Instead of NSArray's -initWithObjects:, you want:
NSArray *notificationArray = [[ NSArray alloc ] initWithArray:
[[ UIApplication sharedApplication ]
scheduledLocalNotifications ]];
You get the exception because notificationArray only contains one object, the array returned by -scheduledLocalNotifications.

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.