I'm trying to post userid and password and retrieve user information using HttpRequest. I'm getting expected result, but client had reported the app is crashing after authentication. He had sent a video which shows how the app crashes. From that i concluded the app is crashing after displaying nserror message in uialertview from
- (void)parser:(NSXMLParser *)parser parseErrorOccurred:(NSError *)parseError
The error message i'm getting is "The operation couldn't be completed. (NSXMLParserErrorDomain error 39.)"
After showing this message in alert view the app is crashing suddenly. I'm not facing this crash anyhow. Can anyone help me to sort out this. Thanks in advance.
The code i have used in parseErrorOccured is
NSString *errorMessage = [error localizedDescription];
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Connection Error!" message:errorMessage
delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alertView show];
[alertView release];
From experience, [error localizedDescription] or [error localizedFailureReason] may return a nil NSString.
In your code, you should check to see if errorMessage is nil, if it is try setting errorMessage to [error localizedFailureReason]. I'd check for a NULL value again.
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
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.
I'm trying to show an alert from my app. When my app is successfully connected with zebra printer and then if the printer doesnot have paper at the time of printing.. i want to show an alert in my app about the paper out error... please sunbmit your answers if anybody knows...
What exactly you are looking for? Do you want to know the code for how to create and show an alert? or do you want to interact with printer and get the status so as to show alert?
If you are looking for code that shows an alert here you go..
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Printer Warning" message:#"Printer running out of paper" delegate:self cancelButtonTitle:#"OK" otherButtonTitles: nil];
[alertView show];
have u used this block?
void (^completionhandler)(UIPrintInteractionController *, BOOL, NSError *) = ^(UIPrintInteractionController *print, BOOL completed, NSError *error)
{
if (!completed && error)
{
NSLog(#"%#", error.localisedDescription);
}
};
if any error occurs, the error will be logged and u can also use it in AlertView.
if(!completed && error)
{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:nil message:error.localisedDescription cancelButtonTitle:nil otherButtons:#"OK", nil];
[alertview show];
}
I am getting a crash on a iOS 7 app with the following error:
-[NSError release]: message sent to deallocated instance 0x3c443fe0
The error is initiated when I add a call to the following method:
-(void)loadMessages:(NSString*)customerUID {
NSString *formatUID = [NSString stringWithFormat:#"%s%#%s", "'", customerUID, "'"];
formatUID = [formatUID stringByReplacingOccurrencesOfString:#"'" withString:#"%27"];
NSString *servicePath = [NSString stringWithFormat:#"/api/messagerecipient?messageid=null&customeruid=%#", formatUID];
[[RKObjectManager sharedManager] getObjectsAtPath:servicePath parameters:nil success:^(RKObjectRequestOperation *operation, RKMappingResult *messagesResult)
{
NSArray *messageResults = messagesResult.array;
if (messageResults != nil || [messageResults count] != 0)
{
//Add some code here
}
} failure:^(RKObjectRequestOperation *operation, NSError *error) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"An Error Has Occurred" message:[error localizedDescription] delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alertView show];
}];
}
I added multiple breakpoints into the code at various points, and it's not returning any error details. Also, nothing in the console log indicates what the problem is (I have added full RestKit logging), just the above NSError release message.
I have also run a Zombie scan in Instruments. It shows the following.
I'm confused because this shows that the zombie is being created by a GSEventRunModal call. When I go to Extended Detail and select the call, it shows the following:
Any pointers would be gratefully appreciated, thanks.
Update: Instrument Extended Details stack trace
I've seen this a lot as well and the root of the problem appears to be in Core Data. I use the MagicalRecord database library (so does RestKit) and we thought the error was there. You can see a discussion here. After all of our investigation it seemed like MagicalRecord was right and Core Data was at fault.
This had actually been filed as a bug that Apple claimed to have fixed, but we are still seeing it. The only way I've been able to work around this is by preventing every instance where I might not be able to save data so no error is reported. You can see some of those tips in the discussion thread linked to above.
Could it be that you are trying to display an AlertView from inside a block? Interaction with the UI has to be on the main thread?
How do display a UIAlertView from a block on iOS?
Can you try to replace:
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"An Error Has Occurred" message:[error localizedDescription] delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alertView show];
With:
NSString * message = [error localizedDescription];
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"An Error Has Occurred" message:message delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alertView show];
Although I guess that the init method is getting a string anyway.
i think your problem is not with the method it self.
the error message says that you are sending a release call to an object of the type NSERROR.
please check the instance of the class which contains the method you are calling and make sure it's not deallocated.
or add the calling method to the question in order for us to check it.
In my case threading the database to a separate context helped. I used the following constructor on the class that was receiving the message:
-(id)init {
self = [super init];
if (self) {
self.managedObjectContext = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSPrivateQueueConcurrencyType];
self.managedObjectContext.parentContext = [(AppDelegate *)[[UIApplication sharedApplication] delegate] managedObjectContext];
self.managedObjectContext.retainsRegisteredObjects = YES;
}
return self;
}
I am trying to check if an Email message was sent and display an Alert allowing the user know.
I tried the delegate method below , but sadly will display the alert message if user cancels as well. Any help will be appreciated and rewarded.
- (void)mailComposeController:(MFMailComposeViewController*)controller
didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error{
if (error) { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Error" message:
[NSString stringWithFormat:#"Error %#", [error description]] delegate:self
cancelButtonTitle:#"Dismiss" otherButtonTitles:nil];
[alert show];
}
NSLog(#"email sent");
}
}
All that it means when that function is called is that something happened with the email because the MFMailComposeViewController is finished. To know what did actually happen, you have to take a look at the value of result, which can be any of the following:
MFMailComposeResultCancelled
MFMailComposeResultSaved
MFMailComposeResultSent
MFMailComposeResultFailed
As rmaddy says in comments, you can't be 100% sure that the email was actually sent (it could be stuck in the outbox). What MFMailComposeResultSent signifies, then, is that the email has been sent over to the Mail app, which will send it as soon as it can.