Hello for the life of me I cannot figure out why I am getting the following error during my signup process. Attached is the picture of what I'm getting this error when I enter a uppercase letter inside the username textfield.
Call Signup Fuction:
- (void)signUpCode {
NSString *str = #"09";
str = [_firstNameField.text isEqualToString:#""]?#"Please provide firstname":[_lastNameField.text isEqualToString:#""]?#"Please provide lastname":[_usernameField.text isEqualToString:#""]?#"Please provide username":[_emailField.text isEqualToString:#""]?#"Please provide email":[_passwordField.text isEqualToString:#""]?#"Please provide password":#"";
if ([_passwordField.text isEqualToString:_repeatPasswordField.text]) {
}
else
{
UIAlertView *alt = [[UIAlertView alloc]initWithTitle:#"work" message:#"Password doesn't match." delegate:nil cancelButtonTitle:#"Cancel" otherButtonTitles:#"Ok", nil];
[alt show];
}
if ([str isEqualToString:#""])
{
NSDictionary *dict =[[NSDictionary alloc] initWithObjectsAndKeys:_firstNameField.text,#"firstname",_lastNameField.text,#"lastname",_usernameField.text,#"username",_emailField.text,#"email",_passwordField.text,#"password", nil];
[blkRkMngr signup:dict completionBlock:^(BOOL success){
if (success) {
// Go to main menu
[self performSegueWithIdentifier:#"showMenu" sender:self];
}
else{
}
}];
}
else{
UIAlertView *alt = [[UIAlertView alloc]initWithTitle:#"LoginApp" message:str delegate:nil cancelButtonTitle:#"Cancel" otherButtonTitles:#"Ok", nil];
[alt show];
}
}
Details for Signup
-(void)signup:(NSDictionary *)dictParam completionBlock:(BlackRockManagerCompletionBlock)pCompletionBlock{
NSString *strRequestUrl = KSignup;
[Helper showGlobalProgressHUDWithTitle:#"Loading"];
AFHTTPRequestOperationManager *operationManager = [AFHTTPRequestOperationManager manager];
operationManager.responseSerializer = [AFJSONResponseSerializer serializer];
operationManager.requestSerializer = [AFJSONRequestSerializer serializer];
operationManager.responseSerializer.acceptableContentTypes = [operationManager.responseSerializer.acceptableContentTypes setByAddingObject:#"Text/html"];
AFHTTPRequestOperation *operation = [operationManager POST:strRequestUrl parameters:dictParam success:^(AFHTTPRequestOperation *operation, id responseObject) {
[Helper dismissGlobalHUD];
NSDictionary* dictResponse = [NSJSONSerialization
JSONObjectWithData:operation.responseData //1
options:kNilOptions
error:nil];
NSLog(#"%#",dictResponse);
if ([[dictResponse valueForKey:#"status"] intValue] == 1) {
UIAlertView *alt = [[UIAlertView alloc]initWithTitle:#"Trend" message:[dictResponse valueForKey:#"message"] delegate:nil cancelButtonTitle:#"Cancel" otherButtonTitles:#"Ok", nil];
[alt show];
pCompletionBlock(YES);
}
else if([[dictResponse valueForKey:#"status"] intValue] == 2){
UIAlertView *alt = [[UIAlertView alloc]initWithTitle:#"Trend" message:[dictResponse valueForKey:#"message"] delegate:nil cancelButtonTitle:#"Cancel" otherButtonTitles:#"Ok", nil];
[alt show];
pCompletionBlock(NO);
}else{
UIAlertView *alt = [[UIAlertView alloc]initWithTitle:#"Trend" message:[dictResponse valueForKey:#"message"] delegate:nil cancelButtonTitle:#"Cancel" otherButtonTitles:#"Ok", nil];
[alt show];
}
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
[Helper dismissGlobalHUD];
NSLog(#"Failed %#",operation.responseString);
}];
[operation start];
}
It's weird since I also searched everywhere in the entire code and I cannot find where the error box statement of "Username must contains only small letters and numbers".
You can not find out "Username must contains only small letters and numbers" error message because it comes from HTTP request and showed with UIAlertView.
Just checkout the codes where you request and find out why that error occurs.
Related
Below is my code and I want to perform segue based on response string, but couldn't, can someone watch out my code and tell me what's wrong.
and when I am entering value in contact no. textfield,app is terminating with the error :
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Can't do regex matching on object <UITextField: 0x7faae2079980; frame = (20 353; 280 45); text = '9876543210'; clipsToBounds = YES; opaque = NO; autoresize = W+TM+BM; gestureRecognizers = <NSArray: 0x7faae2097250>; layer = <CALayer: 0x7faae2083bd0>>.'
Code I have try:
- (IBAction)Register:(id)sender {
if ((uname.text.length==0)&&(uemail.text.length==0)&&(ucontact.text.length==0)&&(upwd.text.length==0)&&(confirmpwd.text.length==0)){
UIAlertView *alert=[[UIAlertView alloc] initWithTitle:#"Can not Register"
message:#"All the Fields are Mandatory"
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:#"Cancel", nil];
[alert show];
}
else{
NSString *emailString = uemail.text;// storing the entered email in a string.
//Regular expression to checl the email format.
NSString *emailReg = #"[A-Z0-9a-z._%+-]+#[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";
NSPredicate *emailTest=[NSPredicate predicateWithFormat:#"SELF MATCHES %#", emailReg];
if(([emailTest evaluateWithObject:emailString]!=YES)||[emailString isEqualToString:#""])
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Warning" message:#"Enter your email in abc#example.com format." delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
uemail.text = #"";
return;
}
}
NSString *mobile=ucontact.text;
NSString *numberRegEx = #"([0-9]{10})";
NSPredicate *numberTest = [NSPredicate predicateWithFormat:#"SELF MATCHES %#", numberRegEx];
if ([numberTest evaluateWithObject:ucontact] != YES||[mobile isEqualToString:#""])
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Warning" message:#"Enter a Valid Number." delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
uemail.text = #"";
return;
}
if ((upwd.text)!=(confirmpwd.text)) {
UIAlertView *alert=[[UIAlertView alloc] initWithTitle:#"Password Do Not Match"
message:nil
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:#"Cancel", nil];
[alert show];}
NSURL *url = [NSURL URLWithString:#"http://108.179.246.128/connectme/service/registration.php"];
NSMutableURLRequest *rq = [NSMutableURLRequest requestWithURL:url];
[rq setHTTPMethod:#"POST"];
NSString *params=[NSString stringWithFormat:#"name=%#&email=%#&mobile=%#&passwrd=%#",self->uname.text,self->uemail.text,self->ucontact.text,self->upwd.text];
NSData *postData = [params dataUsingEncoding:NSASCIIStringEncoding];
[rq setHTTPBody:postData];
NSURLResponse *response;
NSError *error;
NSData *urlData = [NSURLConnection sendSynchronousRequest:rq returningResponse:&response error:&error];
NSString *str=[[NSString alloc]initWithData:urlData encoding:NSUTF8StringEncoding]; NSLog(#"Login response:%#",str); //getting response
// [self performSegueWithIdentifier:#"activity" sender:self];
if([str isEqual: #"Successfully Registered"])
{
[self performSegueWithIdentifier:#"login" sender:self];
}
else if([str isEqual:#"Sorry Email address already taken"])
{
UIAlertView *alertit=[[UIAlertView alloc] initWithTitle:#"Can not Register"
message:#"Email Address already Taken"
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:#"Cancel", nil];
[alertit show];
}
}
For your second question that is crashing, it is because you need to pass the textField.text not the UITextField object. So it should be mobile variable that contain text of textField instead of ucontact textField object.
[numberTest evaluateWithObject:mobile]
I want to pass a JSON dictionary as a parameter by using uploadUrl, but it gives me an Unsupported Url error with code-1002.
When I hit this URL on Postman, it works perfectly. How do I implement this using a JSON model?
NSString *uploadUrl =#"<Your host URL>";
[JSONHTTPClient postJSONFromURLWithString:uploadUrl params:nil
completion:^(NSDictionary *json, JSONModelError *err)
{
if(err == nil)
{
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:#"success" message:#"uploaded" delegate:self cancelButtonTitle:nil otherButtonTitles:#"OK", nil];
[alert show];
completionHanldler(json);
}
else
{
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:#"Failed" message:#"uploaded" delegate:self cancelButtonTitle:nil otherButtonTitles:#"OK", nil];
[alert show];
NSMutableDictionary *errorDict=[[NSMutableDictionary alloc]init];
if(err.code==-1009)
[errorDict setObject:#"The Internet connection appears to be offline."forKey:#"error"];
else
[errorDict setObject:#"Error occurred. Please try again!"forKey:#"error"];
completionHanldler(errorDict);
}
}];
stringByAddingPercentEscapesUsingEncoding
This method solved this issue. Previously I was assigning the unsupported URL.
NSError * err;
NSData * jsonData = [NSJSONSerialization dataWithJSONObject:parameters options:0 error:&err];
NSString *myString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
// This line is the answer.
myString = [myString stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding];
NSString *uploadUrl = [NSString stringWithFormat:#"<MY host URL>"?data=%#",myString];
[JSONHTTPClient postJSONFromURLWithString:uploadUrl params:nil
completion:^(NSDictionary *json, JSONModelError *err)
{
if(err == nil)
{
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:#"success" message:#"uploaded" delegate:self cancelButtonTitle:nil otherButtonTitles:#"OK", nil];
[alert show];
completionHanldler(json);
}
else
{
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:#"Failed" message:#"uploaded" delegate:self cancelButtonTitle:nil otherButtonTitles:#"OK", nil];
[alert show];
NSMutableDictionary *errorDict=[[NSMutableDictionary alloc]init];
if(err.code==-1009)
[errorDict setObject:#"The Internet connection appears to be offline."forKey:#"error"];
else
[errorDict setObject:#"Error occurred. Please try again!"forKey:#"error"];
completionHanldler(errorDict);
}
}];
Reviewing your question and API. you want to send some information to backend, you need to POST information using POST method and your data as json format.
you can test request using any online API Proxies (eg. POSTMAN or hurlit).
I hope its clear to you, you can't send more than 256 bytes using GET request, and as your API is POST request. In your existing method make following changes and you are done.
NSString *uploadUrl =#"<Your host URL>";
NSDictionary *dictParams = #{#"key" : #"value"};
[JSONHTTPClient postJSONFromURLWithString:uploadUrl params:dictParams
completion:^(NSDictionary *json, JSONModelError *err)
{
}];
Try this:
NSString *uploadUrl =#"<Your host URL>";
NSDictionary *val = #{<Add your params as key : value here>};
NSArray *innerParameter = #[val];
NSDictionary *parameter =#{#"Passports":innerParameter};
[JSONHTTPClient postJSONFromURLWithString:uploadUrl params:parameter
completion:^(NSDictionary *json, JSONModelError *err)
{
if(err == nil)
{
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:#"success" message:#"uploaded" delegate:self cancelButtonTitle:nil otherButtonTitles:#"OK", nil];
[alert show];
NSError *error;
NSDictionary *resultDict = [NSJSONSerialization JSONObjectWithData:objectData options:NSJSONReadingMutableContainers error:&jsonError]; // this is a dictionary NOT the JSON
completionHanldler(resultDict);
}
else
{
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:#"Failed" message:#"uploaded" delegate:self cancelButtonTitle:nil otherButtonTitles:#"OK", nil];
[alert show];
NSMutableDictionary *errorDict=[[NSMutableDictionary alloc]init];
if(err.code==-1009)
[errorDict setObject:#"The Internet connection appears to be offline."forKey:#"error"];
else
[errorDict setObject:#"Error occurred. Please try again!"forKey:#"error"];
completionHanldler(errorDict);
}
}];
EDIT:
Same network call using AFNetworking
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
NSDictionary *val = #{<Params as key : value>};
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
[manager POST:#"<your host URL>" parameters:val success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(#"JSON: %#", responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(#"Error: %#", error);
}];
EDIT 2:
First of all, I figured the backend is done in POST but it is going through URL encoding. After much trial and error, this CANNOT be done, even after trying it in GET. As far as I can understand, the backend is not recognizing the POST method in JSON format, so you have to send it in URL encoding fashion only.
It may be an easy question, but I am tired of it
Is there any setting for Facebook app (Which we set while creating an App in Facebook developer's site) for making "invite friend" functionality to be worked.
I am using WebDialog method as follows,
FBWebDialogs presentRequestsDialogModallyWithSession:nil
message:FacebookInviteMessage
title:#"Invite Friends"
parameters:parameters
handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error)
With the same method I am able to invite friend, when I am using the Facebook APP ID of another sample code in my project. But when I am using my own project's Facebook APP ID, invite is not working when I am getting Success in result url.
So I think there would be some setting in developer's site of Facebook.
Can anyone help for this
The complete code is
NSDictionary *parameters = self.fbidSelection ? #{#"to":self.fbidSelection} : nil;
MIDLog(#"self.fbidSelection %#",self.fbidSelection);
[FBWebDialogs presentRequestsDialogModallyWithSession:nil
message:FacebookInviteMessage
title:#"Invite Friends"
parameters:parameters
handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {
NSString *strResultUrl = [resultURL absoluteString];
if (result == FBWebDialogResultDialogCompleted && ![strResultUrl isEqualToString:#"fbconnect://success"])
{
MIDLog(#"Web dialog complete: %#", resultURL);
if (![resultURL query])
{
return;
}
NSDictionary *params = [self parseURLParams:[resultURL query]];
NSMutableArray *recipientIDs = [[NSMutableArray alloc] init];
for (NSString *paramKey in params)
{
if ([paramKey hasPrefix:#"to["])
{
[recipientIDs addObject:[params objectForKey:paramKey]];
}
}
if ([params objectForKey:#"request"])
{
NSLog(#"Request ID: %#", [params objectForKey:#"request"]);
}
if ([recipientIDs count] > 0)
{
//[self showMessage:#"Sent request successfully."];
//NSLog(#"Recipient ID(s): %#", recipientIDs);
UIAlertView *alrt = [[UIAlertView alloc] initWithTitle:#"Success!" message:#"Invitation(s) sent successfuly!" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles: nil];
[alrt show];
alrt = nil;
}
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Success" message:FacebookInviteSuccess delegate:self cancelButtonTitle:#"Proceed" otherButtonTitles:nil];
alert.tag = 14114;
[alert show];
alert = nil;
// [self navigateToSearch];
}
else if (result == FBWebDialogResultDialogCompleted && [strResultUrl isEqualToString:#"fbconnect://success"])
{
MIDLog(#"Cancel Clicked");
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Cancelled" message:nil delegate:self cancelButtonTitle:#"Proceed" otherButtonTitles:nil];
alert.tag = 14114;
[alert show];
alert = nil;
}
else {
MIDLog(#"Web dialog not complete, error: %#", error.description);
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Error" message:InternetFailError delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
alert.tag = 15115;
[alert show];
alert = nil;
}
}
friendCache:self.friendCache];
}
Thank you
It may be an easy question but can anybody tell me.
Is there any setting we need to do in the app (in Facebook developer site) for invite friends?
I have done all in code to invite friends.
When I substitute the Facebook APP ID of a sample code in which invite friend is working, then my code is also working fine.
But when I substitute my APP ID then the process is going fine, showing me successfully invitation message, but invitation is not sent.
I am using the following code:
[FBWebDialogs presentRequestsDialogModallyWithSession:nil
message:FacebookInviteMessage
title:#"Invite Friends"
parameters:parameters
handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {
NSString *strResultUrl = [resultURL absoluteString];
if (result == FBWebDialogResultDialogCompleted && ![strResultUrl isEqualToString:#"fbconnect://success"])
{
MIDLog(#"Web dialog complete: %#", resultURL);
if (![resultURL query])
{
return;
}
NSDictionary *params = [self parseURLParams:[resultURL query]];
NSMutableArray *recipientIDs = [[NSMutableArray alloc] init];
for (NSString *paramKey in params)
{
if ([paramKey hasPrefix:#"to["])
{
[recipientIDs addObject:[params objectForKey:paramKey]];
}
}
if ([params objectForKey:#"request"])
{
NSLog(#"Request ID: %#", [params objectForKey:#"request"]);
}
if ([recipientIDs count] > 0)
{
//[self showMessage:#"Sent request successfully."];
//NSLog(#"Recipient ID(s): %#", recipientIDs);
UIAlertView *alrt = [[UIAlertView alloc] initWithTitle:#"Success!" message:#"Invitation(s) sent successfuly!" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles: nil];
[alrt show];
alrt = nil;
}
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Success" message:FacebookInviteSuccess delegate:self cancelButtonTitle:#"Proceed" otherButtonTitles:nil];
alert.tag = 14114;
[alert show];
alert = nil;
}
else if (result == FBWebDialogResultDialogCompleted && [strResultUrl isEqualToString:#"fbconnect://success"])
{
MIDLog(#"Cancel Clicked");
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Cancelled" message:nil delegate:self cancelButtonTitle:#"Proceed" otherButtonTitles:nil];
alert.tag = 14114;
[alert show];
alert = nil;
}
else {
MIDLog(#"Web dialog not complete, error: %#", error.description);
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Error" message:InternetFailError delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
alert.tag = 15115;
[alert show];
alert = nil;
}
}
friendCache:self.friendCache]
I provided the canvas URL in the application settings under Facebook developer site and It works for me
Code that posts one image:
-(IBAction)postImageToFacebook:(id)sender {
DLog(#"");
NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
[params setObject:self.textField.text forKey:#"message"];
DLog(#"%#",[params objectForKey:#"message"]);
if(self.imageView.image){
DLog(#"not null");
UIImage *_img = self.imageView.image;
[params setObject:UIImagePNGRepresentation(_img) forKey:#"picture"];
}
[self performPublishAction:^{
[FBRequestConnection startWithGraphPath:#"me/photos"
parameters:params
HTTPMethod:#"POST"
completionHandler:^(FBRequestConnection *connection,
id result,
NSError *error)
{
if (error)
{
//showing an alert for failure
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Error"
message:#"unable to post"
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert show];
}
else
{
//showing an alert for success
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Posted!"
message:#""
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert show];
}
}];
}];
}
Can I add another object for a duplicate key into the NSMutableDictionary?