Compare UITextField with PFQuery of parse.com - parse-platform

I have a small problem .. I hope you can help me ...
In my app I'm using Parse.com for data management.
I have a ViewController that contains a TextField called "Email".
With a query parse.com call all the registered user app and their email. Now I would like to try to compare the values of the textField and those of the query .. Let me give an example ..
The user enters their email in the textField but if this email is already present in the archive of the users (of course taken by the query parse.com) shows an alert that warns him that the Supplied in textField is already existing in parse.com.
I tried to do this but it does not always recognize the email in query..dove am I doing wrong?
P.S. the textField is not in viewController Main but is in another
ViewController called generalData.
-(void)query {
PFQuery *totalUser = [PFUser query];
[totalUser findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!error) {
for (PFObject *object in objects) {
[array addObject:object];
NSLog(#"%#", [object objectForKey:NPUserKey_EMAIL]);
// NSStrings
email = generalData.emailTextField.text;
compareEmail = [object objectForKey:NPUserKey_EMAIL];
}
}
}];
}
- (IBAction)presentNextViewController:(id)sender {
if ([generalData.emailTextField.text isEqualToString:compareEmail]) {
NSString *stringError = [NSString stringWithFormat:#"L'email %# รจ gia presente nei nostri archivi.",email];
NPUMessageView *alertMessage;
alertMessage= [[NPUMessageView alloc] showViewWithMessage:stringError withBackgroundColor:SECONDARY_COLOR];
[self.view addSubview:alertMessage];
[alertMessage showAnimatedView];
NSLog(#"email found in archive");
}
else {
NSInteger index = [controllersContainer indexOfObject:self.destinationViewController];
index = MIN(index+1, [controllersContainer count]-1);
[self presentCurrentViewController:self.currentViewController withPage:index];
}
}

I think you are getting ahead of yourself a little bit. Parse automatically checks for duplicate emails when you try to sign up a new user. Let the user enter their email into the field, and when they try to create the account, display the error Parse returns from the signup method, and let them try again!
https://www.parse.com/docs/ios_guide#users-signup/iOS

Related

Inconsistent results creating bidirectional relationship between PFUser and PFObjects

I am attempting to create a bidirectional relationship between a PFUser and some PFObjects using PFRelations.
First I create a Posting and save that in the background.
And in the completion block I add the new posting in the PFUser by appending to the list of Postings that are already related to this User and re-save the User with a synchronous save call.
The Posting is always saved correctly with the correct Relation to the User, however, the Relation back to the Posting in the User only works intermittently. Stepping through the code results in the correct outcome each time which leads me to believe it's some sort of race condition. What would cause this behavior? Is there a better way to achieve the desired relationships?
PFUser *currentUser = [PFUser currentUser];
PFObject *posting = [PFObject objectWithClassName:#"Postings"];
__weak HLReviewPostItemViewController *myself = self;
posting[#"title"] = self.createdItem[#"title"];
posting[#"price"] = self.createdItem[#"price"];
posting[#"owner"] = currentUser;
[posting saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if (!error) {
PFGeoPoint *currentGeoPoint = [myself.locationManager getCurrentGeoPoint];
[currentUser setObject:currentGeoPoint forKey:#"geoPoint"];
PFRelation *postingsForUser = [currentUser relationForKey:#"postings"];
[postingsForUser addObject:posting];
NSError *error;
[currentUser save:&error];
if (!error) {
[myself.dataManager fetchLocalUsers];
} else {
NSLog(#"Error saving Posting in user relation: %#", error);
}
} else {
NSLog(#"Error saving Posting: %#", error);
}
}];
When you save the posting, because the posting has a column that stores the owner, the owner - the parent, also gets saved automatically - very nice feature of Parse.
When you step through the code automatic save is executed and finished before your next re-save. But when you run the code, there is no guarantee which save to PFUser object would occur first.

PKPaymentAuthorizationViewController present as nil view controller

I am trying to integrate Apple Pay in my demo app following this link & I am facing this issue issue. I have updated my iphone 6+ os to 8.1.1 version but still not able to present PKPaymentAuthorizationViewController properly & I am getting this error "Application tried to present a nil modal view controller on target".Please suggest something since I am stuck on this.Here is the code which I have written :-
PKPaymentRequest *request = [[PKPaymentRequest alloc] init];
request.currencyCode = #"USD";
request.countryCode = #"US";
// This is a test merchant id to demo the capability, this would work with Visa cards only.
request.merchantIdentifier = #"merchant.com.procharge"; // replace with YOUR_APPLE_MERCHANT_ID
request.applicationData = [#"" dataUsingEncoding:NSUTF8StringEncoding];
request.merchantCapabilities = PKMerchantCapability3DS;
request.supportedNetworks = #[PKPaymentNetworkMasterCard, PKPaymentNetworkVisa, PKPaymentNetworkAmex];
request.requiredBillingAddressFields = PKAddressFieldPostalAddress|PKAddressFieldPhone|PKAddressFieldEmail;
request.requiredShippingAddressFields = PKAddressFieldPostalAddress|PKAddressFieldPhone|PKAddressFieldEmail;
///Set amount here
NSString *amountText = #"0.01"; // Get the payment amount
NSDecimalNumber *amountValue = [NSDecimalNumber decimalNumberWithString:amountText];
PKPaymentSummaryItem *item = [[PKPaymentSummaryItem alloc] init];
item.amount = amountValue;
//item.amount = [[NSDecimalNumber alloc] initWithInt:20];
item.label = #"Test Payment Total";
request.paymentSummaryItems = #[item];
PKPaymentAuthorizationViewController *vc = nil;
// need to setup correct entitlement to make the view to show
#try
{
vc = [[PKPaymentAuthorizationViewController alloc] initWithPaymentRequest:request];
}
#catch (NSException *e)
{
NSLog(#"Exception %#", e);
}
if (vc != nil)
{
vc.delegate = self;
[self presentViewController:vc animated:YES completion:CompletionBlock];
}
else
{
//The device cannot make payments. Please make sure Passbook has valid Credit Card added.
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"PassKit Payment Error"
message:NSLocalizedString(#"The device cannot make payment at this time. Please check Passbook has Valid Credit Card and Payment Request has Valid Currency & Apple MerchantID.", #"")
delegate:nil
cancelButtonTitle:NSLocalizedString(#"OK", #"")
otherButtonTitles:nil];
[alert show];
}
Thanks & Regards
Did you implement these methods to check before trying to present the viewcontroller?
// Determine whether this device can process payment requests.
// YES if the device is generally capable of making in-app payments.
// NO if the device cannot make in-app payments or if the user is restricted from authorizing payments.
+ (BOOL)canMakePayments;
// Determine whether this device can process payment requests using specific payment network brands.
// Your application should confirm that the user can make payments before attempting to authorize a payment.
// Your application may also want to alter its appearance or behavior when the user is not allowed
// to make payments.
// YES if the user can authorize payments on this device using one of the payment networks supported
// by the merchant.
// NO if the user cannot authorize payments on these networks or if the user is restricted from
// authorizing payments.
+ (BOOL)canMakePaymentsUsingNetworks:(NSArray *)supportedNetworks;

Fetching user data from Facebook on Xcode

I am trying to develop a simple app, which, retrieves data from Facebook, when the user connects to it.
After reading Facebook's example about how to retrieve User's photos and User's names, I just want to get information such as gender, city, e-mail, and date of birth, for example.
The following part, is where I got stuck:
- (void)populateUserDetails
{
if (FBSession.activeSession.isOpen) {
[[FBRequest requestForMe] startWithCompletionHandler:
^(FBRequestConnection *connection,
NSDictionary<FBGraphUser> *user,
NSError *error) {
if (!error) {
self.userNameLabel.text = user.name;
self.userProfileImage.profileID = user.id;
}
}];
}
}
My questions are:
Should I make a dictionary with all this data? (gender, city, e-mail, etc.)
-Also, I'm using the storyboard, can I use labels to all those data as Facebook's tutorial states, for the username?
I read in a couple of places that the method requestForMe isn't the appropriate one for the other type of data I am looking for. What would be the method for my requests?
First you must ask user for permissions to access his gender, email, city ...
You make a array with required permissions and add it to the openActiveSessionWithReadPermissions: method
NSArray *permissions = [[NSArray alloc] initWithObjects:#"user_birthday",#"user_hometown",#"user_location",#"email",#"basic_info", nil];
[FBSession openActiveSessionWithReadPermissions:permissions
allowLoginUI:YES
completionHandler:^(FBSession *session,
FBSessionState status,
NSError *error) {
}];
Then make a request like this to get informations you wanted
[FBRequestConnection startForMeWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
NSLog(#"%#", [result objectForKey:#"gender"]);
NSLog(#"%#", [result objectForKey:#"hometown"]);
NSLog(#"%#", [result objectForKey:#"birthday"]);
NSLog(#"%#", [result objectForKey:#"email"]);
}];
I hope i resolved your problem.

cocoa: how to create new SBElementArray?

I'm making a application which read emails in Mail.app. Firstly, the application get all senders from Mail.app using
NSArray *emailSenders = [self.mailBox.messages arrayByApplyingSelector:#selector(sender)];
I have to display target user email content, e.g. only show all mails from "abc#gmail.com", so I get the sender indexes which contain the target user email
[emailSenders enumerateObjectsUsingBlock:^(NSString *emailSender, NSUInteger idx, BOOL *stop) {
if([emailSender rangeOfString:userEmail].location != NSNotFound){
[emails addObject:[self.mailBox.messages objectAtIndex:idx]];
}
}];
emails is a SBElementArray created by
SBElementArray *emails = [[SBElementArray alloc]init];
I want to fetch all contents in emails by sending Apple Script Event only once, like
[mails arrayByApplyingSelector:#selector(content)];
so I create my own SBElementArray, but the problem is Xcode display:*** -[SBElementArray init]: should never be used.
when I run this code, how to fix it?
Just add your filtered items to an NSArray or NSMutableArray, and remember that its elements are SBObjects.

Xcode: getting badge value to add it to a label

I have an app that receives push notification.
I would like to add the badge with the right value near a button inside the application menu (do you remember the old Facebook app?).
I'm trying to get the badge value from the notification in the AppDelegate, save it in NSUserDefault to use it in other view controllers.
NSString * badgeValue = [[userInfo valueForKey:#"aps"] valueForKey:#"badge"];
NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:badgeValue forKey:#"badge"];
[defaults synchronize];
The problem is that if I try to put the value in a label the app crashes
'NSInvalidArgumentException', reason: '-[__NSCFNumber isEqualToString:]: unrecognized selector sent to instance
Xcode makes me save badgeValue in a string but when I put the string in the label it says is not a proper string
if ([badgeValue isKindOfClass:[NSString class]]) {
NSLog(#"it is string !!!!!!!!!!!!!!!");
// treat it as a string object
} else {
NSLog(#"it is not a string !!!!!!!!!!!!!!!");
// treat it as a number object
}
By debugging I see that badgeValue is not a real string but __NSCFNumber and if I try to convert it in a string the return value is a long strange number.
I searched everywhere for a way to get the badge value of the notification but the only option I can think of is a php query...Any idea?
What do you mean by "Xcode makes me save badgeValue in a string"? Do you get an error or a compiler warning if you try to type badgeValue as an NSNumber? The documentation and your own logging tell you that the value of the key "badge" is an NSNumber.
NSNumber * badgeValue = [[userInfo valueForKey:#"aps"] valueForKey:#"badge"];
[label1 setIntValue:badgeNumber.intValue];
Does something like this not work?
Yes, Just yesterday I tried with
NSString *string = [NSString stringWithFormat:#"%d", [badgeValue intValue]];
And it works! Thanks for help

Resources