I am trying to create an app where each PFObject has categories Verifications and Verified_By.
Verifications consists of a number, and Verified_By is an array of strings
When I try to update the categories and save the PFObject, the data is correct and is saved locally, but when I call saveInBackground, it doesn't update in the data browser.
Here is my code for the updating:
if (![verifiedBy containsObject:[ViewController getUserName]]) {
//havent verified
NSMutableArray *newArray = [NSMutableArray arrayWithArray:verifiedBy];
[newArray addObject:[ViewController getUserName]];
[toModify setObject:newArray forKey:#"Verified_By"];
[toModify incrementKey:#"Verifications"];
[toModify saveInBackground];
[[[UIAlertView alloc] initWithTitle:#"Verified!" message:#"You have successfully verified this" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil, nil] show];
}
else {
[[[UIAlertView alloc] initWithTitle:#"Already Verified" message:#"You have already verified this" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil, nil] show];
It turns out that I didn't have the proper ParseACL needs (public read = true, public write = true)
Related
For the first time I am playing with APNS, I tried to run a proof of concept, with an iOS 5.0.1 device, and the didFailToRegisterForRemoteNotificationsWithError is fired. I know it has been fired because I show an UIAlertView to notify the error:
- (void)application:(UIApplication*)application
didFailToRegisterForRemoteNotificationsWithError:(NSError*)error
{
// Inform the user that registration failed
NSString* failureMessage = #"There was an error while trying to \
register for push notifications.";
UIAlertView* failureAlert = [[UIAlertView alloc] initWithTitle:#"Error"
message:failureMessage
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[failureAlert show];
[failureAlert release];
}
How can I get more info about the error?
Try doing something like NSLog(#"%#", error.userInfo");, that should output some info into the terminal.
I ended up with this code, which works and lets me progress a bit:
NSString* failureMessage = error.localizedDescription;
UIAlertView* failureAlert = [[UIAlertView alloc] initWithTitle:#"Error"
message:failureMessage
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[failureAlert show];
Sorry, iObjectiveC noob here.
my app has a button that checks whether an entered value is correct.
sometimes it causes it to crash, but the strange thing is that it happens at irregular intervals (sometimes on the third iteration, sometimes the tenth, sometimes never).
i get a EXC_BAD_ACCESS error in the debugger. so it seems like something is being released when it shouldn't be. the button calls this function:
- (IBAction)checkValue:(id)sender{
int actualDifference = [firstNumberString intValue] - [secondNumberString intValue];
actualDifferenceAsString = [NSString stringWithFormat:#"%d", actualDifference];
if ([answerTextField.text isEqualToString:actualDifferenceAsString])
{
UIAlertView *correctAlert = [[UIAlertView alloc] initWithTitle:#"matches"
message:#"next value."
delegate:nil
cancelButtonTitle:#"ok"
otherButtonTitles: nil];
[correctAlert show];
[correctAlert release];
}
else
{
UIAlertView *incorrectAlert = [[UIAlertView alloc]
initWithTitle:#"does not match"
message:#"next value."
delegate:nil
cancelButtonTitle:#"ok"
otherButtonTitles: nil];
[incorrectAlert show];
[incorrectAlert release];
}
using zombies pointed to the first statement:
int actualDifference = [firstNumberString intValue] - [secondNumberString intValue];
does anyone know what the problem might be?
If zombies are detected in the first line, that means some other part of your program is releasing firstNumberString or secondNumberString. That's where the problem starts, but it only shows up here, when you later try to access those values. Where else do you work with those strings? Do you ever release them?
For overall safety, they should probably be assigned properties, not member variables.
Change it into
NSInteger actualDifference = [firstNumberString intValue] - [secondNumberString intValue]; //change int to NSInteger
NSString *actualDifferenceAsString = [NSString stringWithFormat:#"%d", actualDifference];
if ([answerTextField.text isEqualToString:actualDifferenceAsString])
{
UIAlertView *correctAlert = [[UIAlertView alloc] initWithTitle:#"matches"
message:#"next value."
delegate:nil
cancelButtonTitle:#"ok"
otherButtonTitles: nil];
[correctAlert show];
[correctAlert release];
}
else
{
UIAlertView *incorrectAlert = [[UIAlertView alloc]
initWithTitle:#"does not match"
message:#"next value."
delegate:nil
cancelButtonTitle:#"ok"
otherButtonTitles: nil];
[incorrectAlert show];
[incorrectAlert release];
}
you get this code. It worked for me...
When you first try to access a user's ALAssetsLibrary, the OS will present them with a dialog asking for permission. If they do not allow this, a failureBlock will be called and will always be called in the future. Is there a way to force a prompt of this authorization request again?
I notice in the Maps app, that they inform the user to go to the Settings app to turn on location services with a button. However, there is no way that I know of to programmatically open the Settings app. Should I just display directions as to how to turn on the location services?
You can't open up the settings app in an Apple approved manner.
The best you can hope for is to trap the error and then display a UIAlertView or other view with instructions on how to do this. Take a look at the latest v. of the Dropbox app for an idea on how they instruct the user.
When you try to access the Library from your code, you can use the error handler to catch the error and display an alert specifying to the user what to do.
Example
failureBlock:^(NSError *error) {
// error handling
if (error.code == ALAssetsLibraryAccessGloballyDeniedError) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Error!"
message:#"Error loading image... \nEnable Location Services in 'Settings -> Location Services'."
delegate:self cancelButtonTitle:#"OK"
otherButtonTitles:nil, nil];
[alert show];
} else if (error.code == ALAssetsLibraryAccessUserDeniedError) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Error!"
message:[NSString stringWithFormat:#"Error loading image... \nEnable Location Services in 'Settings -> Location Services' for %#.", [[[NSBundle mainBundle] infoDictionary] objectForKey:#"CFBundleDisplayName"]]
delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil, nil];
[alert show];
} else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Error!" message:#"Error loading image..." delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil, nil];
[alert show];
}
}
I'm reading some content from database using SQLite.
It then will be shown in a UIAlertView.
The content contains some new line symbol "\n".
However, it doesn't create a new line in the alert. Instead, the "\n" is shown.
Following is portion of my code:
description = [[NSString alloc] initWithUTF8String:(char *)sqlite3_column_text(selectStatementE, 0)];
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:#"something" message:description delegate:nil cancelButtonTitle:#"Cancel" otherButtonTitles:nil];
[alert show];
Is there anything I can do to make it recognisable?
Thanks in advance!
string with new line character will work without any spl implementation
example
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:#"Print " message:#"line1\nline2\nline3\nline4" delegate:nil cancelButtonTitle:#"Ok" otherButtonTitles:nil];
[alert show];
[alert release];
just Print and check whether your description belongs to following format
In my app, I have a logs mechanism, which offer the possibility to the customer to send the logs via mail.For this, I integrated in my app the Apple MFMailComposeViewController. In case that the customer use a device with low OS version (2.x) or an e-mail account isn't presented on the device, I pushed some UIAlertsView with some suggestive messages for users. Can somebody please take a look over my below code, and reply if there is something that could lead to a rejection by Apple?
BOOL canSendmail = [MFMailComposeViewController canSendMail];
if (!canSendmail) {
NSMutableString* osVersion = [NSMutableString stringWithString:[[UIDevice currentDevice] systemVersion]];
EventsLog* logs = [EventsLog getInstance];
if ([osVersion characterAtIndex : 0] == '2' || [osVersion characterAtIndex : 0] == '1' ) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(#"Email", #"")
message:NSLocalizedString(#"Failed to send E-mail.For this service you need to upgrade the iPhone OS to 3.0 version or later", #"")
delegate:self cancelButtonTitle:NSLocalizedString(#"OK", #"") otherButtonTitles: nil];
[alert show];
[alert release];
[logs writeEvent : #"Cannot send e-mail - iPhone OS needs upgrade to at least 3.0 version" classSource:#"LogsSessionDetailViewController#sendEmail" details : (#" device OS version is %#",osVersion)];
return;
}
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(#"Email", #"")
message:NSLocalizedString(#"Failed to send E-mail.Please set an E-mail account and try again", #"")
delegate:self cancelButtonTitle:NSLocalizedString(#"OK", #"") otherButtonTitles: nil];
[alert show];
[alert release];
[logs writeEvent : #"Cannot send e-mail "
classSource:#"LogsSessionDetailViewController#sendEmail" details : #"- no e-mail account activated"];
return;
}
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(#"Email", #"")
message:NSLocalizedString(#"The data you are sending will be used to improve the application. You are free to add any personal comments in this e-mail", #"")
delegate:self cancelButtonTitle:NSLocalizedString(#"Cancel", #"") otherButtonTitles: nil];
[alert addButtonWithTitle:NSLocalizedString(#"Submit", #"")];
[alert show];
[alert release];
Many thanks,
Alex.
I won't say about appstore admission/rejection but your code must crash on iPhone OS 2.x - you call
BOOL canSendmail = [MFMailComposeViewController canSendMail];
without checking if this call is possible (MFMailComposeViewController class is not available on 2.x system). Also manual checking of OS version is not a good practice. Instead you must at first check if MFMailComposeViewController present in current runtime:
if ( !NSClassFromString(#"MFMailComposeViewController") ){
// Put code that handles OS 2.x version
return;
}
if (![MFMailComposeViewController canSendMail]){
// Put code that handles the case when mail account is not set up
return;
}
//Finally, create and send your log
...
P.S. Do not forget that you must set linkage type for MessageUI framework as 'weak' in target settings - you application will crash on old systems on start if you linkage type will be 'required' (default value).