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.
Related
This question already has answers here:
Why isn't UIAlertView Showing?
(4 answers)
Closed 7 years ago.
I am using parse for sign-in/sign-up process.
Everything is working fine. Until user gives wrong details.
In else part of Parse Login I have written:
self.view.userInteractionEnabled = YES;
[SVProgressHUD dismiss];
// The login failed. Check error to see why.
NSString *message = [NSString stringWithFormat:#"%#",[error valueForKey:#"Error"]];
UIAlertView *myalert = [[UIAlertView alloc]initWithTitle:#"SO" message:message delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles: nil];
[myalert show];
I checked after putting breakpoints in every line.
After executing the 3rd Line i.e. NSSString *message the control doesn't go for alert it directly shows me UI without any alert box.
And In Log I am getting
[Error]: invalid login parameters (Code: 101, Version: 1.7.5)
I doesn't know what to do ? I have written only this code in else part.
I am using Parse Code :
[user signUpInBackgroundWithBlock:^(BOOL succeeded, NSError *error)
{
if (!error)
{
// Hooray! Let them use the app now.
}
else
{
NSString *errorString = [error userInfo][#"error"]; // Show the errorString somewhere and let the user try again.
}
}];
and In else part I want to show and alertView
Try this :
UIAlertView *myalert = [[UIAlertView alloc]initWithTitle:#"SO" message:message delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles: nil];
dispatch_async(dispatch_get_main_queue(), ^(void){
[myalert show];
});
Try this code
NSString *errorString;
UIAlertView *AV;
[user signUpInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if (!error) { // Hooray! Let them use the app now.
} else { errorString = [error userInfo][#"error"]; // Show the errorString somewhere and let the user try again.
AV = [[UIAlertView alloc]initWithTitle:#"SO" message:errorString delegate:nil cancelButtonTitle:#"Cancel" otherButtonTitles:nil, nil];
[AV show];
}
}];
try to call main thread first then create the UIAlert in it
coz mostly thats happen when you are not in the main thread
hope this solve your problem goodluck
I'm trying to build a login page for an app. Something went wrong when testing the login condition.
There are two textfields, username and password. When the Login button is clicked, alert shows when
1) either fields are empty
2) both filled.
The code reflects this below. But the result came out no matter that the textfield is empty or not, it only showed as textfields were filled ( only the else part run). So I assume there was something wrong with the if condition. But when I checked the if condition in other view, it worked.
Can anyone help?
if ([_pLoginIDField.text isEqualToString:#""] || [_pPasswordField.text isEqualToString:#""]) {
UIAlertView *error = [[UIAlertView alloc] initWithTitle:#"Yeah !" message:#"must complete all fields" delegate:self cancelButtonTitle:#"OK" otherButtonTitles: nil];
[error show];
}
else {
UIAlertView *error2 = [[UIAlertView alloc] initWithTitle:#"Oooops !" message:#"hhhhhhhhhh" delegate:self cancelButtonTitle:#"OK" otherButtonTitles: nil];
[error2 show];
}
Try this:
if (_pLoginIDField.text.length > 0 || _pPasswordField.text.length > 0)
NSString *text = [NSString stringWithString: nameUITextField.text];
if(text.length == 0){
}
You may try this,
you can count how many characters are in string, it is indirectly checking to null.
NSString *inputString = [NSString stringWithString: nameUITextField.text];
if(inputString.charachters.count == 0){
// inputString is Blank
// Do your stuff
}else{
//inputString is not blank, Do other Stuff.
}
the above condition satisfy if inputString is blank otherwise it will enter into else block.
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.
I am building an application which has a login through a mobile SAAS - Parse.
There are multiple error codes that could be returned from a login request. At the moment run an if statement for each error code and display a relevant alert view like this:
if (error == nil) {
// Something went wrong
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(#"LoginAlertErrorTitle", #"Login Error Alert View Title") message:NSLocalizedString(#"LoginStandardError", #"Login error message text - standard error") delegate:self cancelButtonTitle:nil otherButtonTitles:NSLocalizedString(#"GlobalOKButtonTitle", #"Global Ok button title"), nil];
[alertView show];
} else if ([error code] == kPFErrorObjectNotFound) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(#"LoginAlertErrorTitle", #"Login Error Alert View Title") message:NSLocalizedString(#"LoginErrorObjectNotFound", #"Login error message text - object not found") delegate:self cancelButtonTitle:nil otherButtonTitles:NSLocalizedString(#"GlobalOKButtonTitle", #"Global Ok button title"), nil];
[alertView show];
} else if ([error code] == kPFErrorConnectionFailed) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(#"LoginAlertErrorTitle", #"Login Error Alert View Title") message:NSLocalizedString(#"LoginAlertErrorConnection", #"Login error message text - connection failed") delegate:self cancelButtonTitle:nil otherButtonTitles:NSLocalizedString(#"GlobalOKButtonTitle", #"Global Ok button title"), nil];
[alertView show];
} else {
NSLog(#"A Login error occurred: %i",[error code]);
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(#"LoginAlertErrorTitle", #"Login Error Alert View Title") message:[[error userInfo] objectForKey:#"error"] delegate:self cancelButtonTitle:nil otherButtonTitles:NSLocalizedString(#"GlobalOKButtonTitle", #"Global Ok button title"), nil];
[alertView show];
}
Is there a more efficient way to do the same with case/switching?
The actual error codes are setup like this:
/*! #abstract 100: The connection to the Parse servers failed. */
extern NSInteger const kPFErrorConnectionFailed;
Which makes me think I can setup this in a case statement. Would this be the correct/best way to approach this? Should it be in a separate method like handleErrorAlert: possibly?
How would I code this switch in the example above?
Whether you use a switch statement or a series of if-else if is really just a matter of taste in this case. Yes, the switch statement is slightly more efficient, but in a case like this, it really doesn't matter (it's not like you call this thousands of times per second). Use what you find more readable.
You might want to refactor your alert view code a little though – you're doing the same thing in all cases with only the error message being different, so there's quite a bit of repeated code. You could refactor it like this:
NSString *errorMessage = nil;
if (error == nil) {
errorMessage = NSLocalizedString(#"LoginStandardError", #"Login error message text - standard error");
} else {
switch ([error code]) {
case kPFErrorObjectNotFound:
errorMessage = NSLocalizedString(#"LoginErrorObjectNotFound", #"Login error message text - object not found");
break;
case kPFErrorConnectionFailed:
errorMessage = NSLocalizedString(#"LoginAlertErrorConnection", #"Login error message text - connection failed");
break;
default:
errorMessage = [[error userInfo] objectForKey:#"error"];
}
}
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(#"LoginAlertErrorTitle", #"Login Error Alert View Title")
message:errorMessage
delegate:self
cancelButtonTitle:nil
otherButtonTitles:NSLocalizedString(#"GlobalOKButtonTitle", #"Global Ok button title"), nil];
[alertView show];
A typedef enum being used on a switch, I think it would be the cleanest way. Something like this:
typedef enum
{
kServerError,
kInternetError,
kUnknowError
} kTypeError;
switch (aTypeError)
{
.
.
.
}
In your specific case, you take care about the message inside the switch... The UIAlertView is a common part. So:
NSString *aTitle = nil;
NSString *aMessage = nil;
switch (aTypeError)
{
case kUnknowError:
{
aTitle = ...;
aMessage = ...;
}
break;
}
UIAlertView *alertView = [UIAlertView alloc] ...
if (!error) {
// Handle error (?).
}
switch ([error code]) {
case kPFErrorObjectNotFound:
// Handle error.
break;
case kPFErrorConnectionFailed:
// Handle error.
break;
default:
// Handle error.
}
This only works if the value returned by -code can be used in a switch test expression. AFAIK, int is supported—I don't know about other types.
I want the user to confirm the password he typed it... so I use two text fields.. But somehow even if both have the same password it seems to think that the 2 strin differ
if (![self.typePTextField.text isEqualToString:self.retypePLabel.text]) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(#"Error", #"Error") message:NSLocalizedString(#"Passwords do not match \n please retype", #"Passwords do not match \n please retype") delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil, nil];
[alert show];
self.typePTextField.text = #"";
self.retypePLabel.text = #"";
return;
}
The alert appears even if I type the same string twice... and only the first text field geets reset to #"" ...
What will fix this?
I'm guessing in the isEqual: method
self.retypePLabel.text
should be
self.retypePTextField.text
try
if (![self.typePTextField.text isEqualToString:self.sometextfield.text]) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(#"Error", #"Error") message:NSLocalizedString(#"Passwords do not match \n please retype", #"Passwords do not match \n please retype") delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil, nil];
[alert show];
self.typePTextField.text = #"";
self.sometextfield.text = #"";
return;
}
if([_txtPassword.text isEqual:_txtconfirmPassword.text])
{
NSLog(#"Password =%# , ConfirmPassword = %# ",_txtPassword.text,_txtconfirmPassword.text);
}
else {
//// code show alert////
}
self.retypePLabel.text? are you sure you ask about this, because I think it should be like self.retypePTextField.text