UIAlertview not accepting string as message - ios

I have this response from my webservice but UIAlertview is giving an strange error
I have printed the respnse and just below I called
2013-08-13 15:40:27.463 Ipad Qld[1459:907] Result {
msg = "Form has been sent successfully.";
status = SUCCESS;
}
2013-08-13 15:40:27.465 Ipad Qld[1459:907] -[__NSDictionaryM isEqualToString:]: unrecognized selector sent to instance 0x1f1168e0
2013-08-13 15:40:27.467 Ipad Qld[1459:907] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSDictionaryM isEqualToString:]: unrecognized selector sent to instance 0x1f1168e0'
*** First throw call stack:
(0x32dad2a3 0x3ac1197f 0x32db0e07 0x32daf531 0x32d06f68 0x34bb9375 0x34d05c95 0x34d05741 0x6a25b 0x32cfe037 0x336ae2cb 0xa013f 0x9fe35 0x8d1e7 0x336e86fd 0x336281f9 0x33628115 0x32a8a45f 0x32a89b43 0x32ab1fcb 0x32cf374d 0x32ab242b 0x32a1603d 0x32d82683 0x32d81f7f 0x32d80cb7 0x32cf3ebd 0x32cf3d49 0x368aa2eb 0x34c09301 0x43a85 0x3b048b20)
libc++abi.dylib: terminate called throwing an exception
the code is
- (void) contactUsNotificationReceived:(NSNotification *) notification
{
[[ActivityIndicator currentIndicator] hide];
NSDictionary *alertMessage = [notification userInfo];
NSString * alertMessageString = alertMessage[#"NSLocalizedString"];
NSLog(#"Result is waga %#",alertMessageString);
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Result" message:alertMessageString delegate:nil cancelButtonTitle:#"Ok" otherButtonTitles:nil, nil];
[alert show];
}

Looks like you are passing a NSDictionnary.
A guess, try to change :
NSString * alertMessage; // the object that you think is a NSString
to
NSDictionary * alertMessage;
NSString * alertMessageString = alertMessage[#"msg"];
Good luck.

Your code seems like problem in isEqualToString. The source string is not valid or it is released or its now pointing to Dictionary.
May be your alert string (that you want to describe) it is not NSString but it may be NSDictionary, so check it.

First get your alert message from NSDictionary to NSString...
NSString *alertMessage = [yourDict objectForKey:#"yourKey"];
Now, show your alert Message in Alert...
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:[NSString stringWithFormat:#"%#",alertMessage] message:nil delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
I hope this will help you.

Related

How to display date & time on alert box

I am facing error , when alert box clicked. Error is incompatible array pointer with String .
2015-10-14 12:41:06.235 snadwitch2[1974:56154] -[__NSArrayI length]: unrecognized selector sent to instance 0x7f954e918e60
2015-10-14 12:41:06.239 snadwitch2[1974:56154] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayI length]: unrecognized selector sent to instance 0x7f954e918e60'
The alert box code is
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Wait" message:# [#"The current date and time is: %#", [NSDate date]] delegate:self cancelButtonTitle:#"Delete" otherButtonTitles:#"Cancel",nil];
[alert show];
You are passing an array instead of a string. You need:
NSString *message = [NSString stringWithFormat:#"The current date and time is: %#", [NSDate date]];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Wait"
message:message
delegate:self
cancelButtonTitle:#"Delete"
otherButtonTitles:#"Cancel",nil];
[alert show];

Terminating App due to uncaught exception iOS

using Parse and just upgraded to XCode 6 (installed Yosemite). My app worked fine until then, now it doesn't even load the first screen (login view controller).
Here's the error message:
2014-10-21 00:30:34.754 Hi App[393:143637] *** Terminating app due to uncaught exception
'NSInvalidArgumentException', reason: 'Cannot do a comparison query for type: (null)'
*** First throw call stack:
(0x25e03e3f 0x334b1c8b 0x25e03d85 0x8d173 0x785fd 0x5fee3 0x292b785f 0x2934b51f 0x2934aff3
0x2934ad5d
0x2934acf1 0x2929f677 0x28cc7ccd 0x28cc36b5 0x28cc353d 0x28cc2f21 0x28cc2d25 0x29503395 0x2950413d
0x2950e549 0x29502557 0x2c5450e9 0x25dca5b5 0x25dc9879 0x25dc83b3 0x25d16621 0x25d16433
0x2930656f
0x29301359 0x5d1b5 0x33a31aaf)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
Here's my loginviewcontroller.m:
- (void)viewDidLoad
{
[super viewDidLoad];
self.navigationItem.hidesBackButton = YES;
}
- (IBAction)login:(id)sender {
NSString *username = [self.enterUsername.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
NSString *password = [self.enterPassword.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
if ([username length] == 0 || [password length] == 0) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Oops!"
message:#"Please enter a username, password."
delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alertView show];
}
[PFUser logInWithUsernameInBackground:username password:password block:^(PFUser *user, NSError
*error) {
if (error) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Sorry!"
message:[error.userInfo
objectForKey:#"error"]
delegate:nil cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alertView show];
}
else {
[self.navigationController popToRootViewControllerAnimated:YES];
}
}];
}
I would first double check to make sure that username and password are not nil. Of course I see you have a check to make sure password and username length is not equal to 0.
The problem with this check is that you are checking, displaying a UIAlert and then the rest of the code is still being executed.
Either return to exit the function or stick the rest of the execution in an else statement.
Try this out:
if ([username length] == 0 || [password length] == 0) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Oops!"
message:#"Please enter a username, password."
delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alertView show];
return;
}
I technically solved it by rebuilding part of the project. I don't know what the problem was, but it probably has something to do with the old files mixing with iOS 8 (not sure what made it fail like that). I compiled the new project in iPhone 5 7.1 and it works.

ios segue unrecognized selector sent to instance

I'm working on an iOS app and I've encountered a problem during testing: the app crashes when I try to enter my next ViewController and I get these messages:
2014-06-29 14:22:46.674 IOS2 Practica[55472:60b] -[Logger login:]: unrecognized selector sent to instance 0x9242230
2014-06-29 14:22:46.679 IOS2 Practica[55472:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Logger login:]: unrecognized selector sent to instance 0x9242230'
From other cases I've looked up, it might be possible that something happens when I attempt to use "segue" to switch to the next ViewController but I can't pinpoint the exact source.
I append the code segment where I define the segue in my main View Controller:
- (void)logger:(id)sender {
NSString *user = self.username.text;
NSString *pass = self.password.text;
NSString * urlBase = #"http://www.v2msoft.com/clientes/lasalle/curs-ios/login.php?username=lluis&password=seguro";
[JSONHTTPClient getJSONFromURLWithString:urlBase completion:^(id json,JSONModelError *err){
JsonUser * user = [[JsonUser alloc]initWithDictionary:json error:nil];
if(user.succeed) {
self.user_id = user.user_id;
[self performSegueWithIdentifier:#"Login" sender:self];
} else {
NSLog(#"error");
}
}];
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if (_username.text.length == 0 || _password.text.length == 0) {
[[[UIAlertView alloc] initWithTitle:#"Error"
message:#"Algun dels camps és incorrecte o està buit!"
delegate:self
cancelButtonTitle:#"Cancel"
otherButtonTitles:nil, nil]
show];
} else {
Supermarket * supermercat = segue.destinationViewController;
supermercat.user_id = self.user_id;
}
}
Thank you in advance for any insight on this topic.
Somewhere in your code (not the bit you posted), you should be calling a login: method on a Logger instance. That method is not defined in Logger and that is why the app crashes.
Pay attention to the : at the end of Login:: possibly you have defined a login method (which does not take any argument), but you are calling it with an argument. Or maybe you would have liked to call logger:.
You can try 2 things out: either you find out where the login: method is called (some button bound to it in Storyboard?) or you rename logger: into login:.

NSMetadataQueryDidUpdateNotification Not Working

Can someone tell me what is wrong with the following code which I adapted from iOS 5 Developer's Cookbook
- (void) startMonitoringUbiquitousDocumentsFolder
{
// Remove any existing query – stored in local instance variable
if (alertQuery) [alertQuery stopQuery];
// Search for all file names
alertQuery.predicate = [NSPredicate predicateWithFormat: #"NSMetadataItemFSNameKey == '*'"];
alertQuery.searchScopes = [NSArray arrayWithObject:
NSMetadataQueryUbiquitousDocumentsScope];
// Subscribe to query updates
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:#selector(alertUserToUpdates:)
name:NSMetadataQueryDidUpdateNotification
object:nil];
[alertQuery startQuery];
}
- (void) alertUserToUpdates
{
NSLog(#"Contents changed in ubiquitous documents folder");
UIAlertView *alertView = [[UIAlertView alloc]
initWithTitle:#"Home Monitor"
message:#"Something's going on."
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:#"Check Recording", nil];
[alertView show];
[self stopMonitoringUbiquitousDocumentsFolder];
}
I get an exception which says the selector alertUserToUpdates: is unrecognized. Why can't it recognize the method which is obviously right next to it?
2013-04-29 18:07:22.458 eyeFun[8231:907] -[RGPViewController alertUserToUpdates:]: unrecognized selector sent to instance 0x1fd506a0
2013-04-29 18:07:22.462 eyeFun[8231:907] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[RGPViewController alertUserToUpdates:]: unrecognized selector sent to instance 0x1fd506a0'
*** First throw call stack:
(0x337eb3e7 0x3b4e6963 0x337eef31 0x337ed64d 0x33745208 0x3373c349 0x34053b7f 0x340ab327 0x3373c349 0x337b810f 0x37880de9 0x340fa657 0x337c0857 0x337c0503 0x337bf177 0x3373223d 0x337320c9 0x3731133b 0x3564e2b9 0x465b5 0x3b913b20)
libc++abi.dylib: terminate called throwing an exception
Because it isn't right next to it.
You're telling it to use a selector named alertUserToUpdates:. You have a method named alertUserToUpdates. The : is significant-- it says that the method takes one argument, but the actual method doesn't take arguments.
Your method should take an argument of type NSNotification.

When I create an Alert from another Alert, I get wait_fences: failed to receive reply

I want to create a alert from a alert. but it crashes.
I use under code to create a alert:
{
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:nil message:inMessage delegate:self cancelButtonTitle:nil otherButtonTitles:#"OK", nil];
[alert show];
}
error message is :
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSError isEqualToString:]: unrecognized selector sent to instance 0x88b84c0'
it looks like inMessage has been release. so I change inMessage to #"test test". It works but get out wait_fences: failed to receive reply:10004003
How can i do for creating a alert in a alert ?
As others have pointed out in the comments, the issue here is that you have an NSError that is being treated mistakenly as an NSString.
inMessage seems to be your NSError object. This slips through the type system at compile time because userInfo has no knowledge of the types of its elements.
To fix this, you probably want to get the description of the error message and display that instead with something like
NSString *inMessage = [[userInfo objectForKey:#"NSUnderlyingError"] localizedDescription];

Resources