I am developing an application that integrates a payment gateway. This works by opening the page "https://sis.sermepa.es/sis/realizarPago" passing some parameters by POST, from there the customer can make the payment.
My problem is that I can not find how to open the browser giving a URL and parameters. I've seen that open the browser using Intents but does not allow parameters and I have seen that you can send POST parameters to a URL and wait for the response, but not open the URL itself.
Does anyone have the solution to my problem?
Thank you very much.
I've solved the problem, here you have the solution in case anyone else needs the answer.
NSString *code=codeTF.text;
NSString *price=priceTF.text;
NSString *email=emailTF.text;
NSString *body = [NSString stringWithFormat:Code=%#&Price=%#&E-mail=%#", code, price, email];
NSURL *url = [NSURL URLWithString:#"https://***/index.php"];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc]initWithURL:url];
[request setHTTPMethod:#"POST"];
[request setHTTPBody:[body dataUsingEncoding:NSUTF8StringEncoding]];
//initialize the webViem in the *.h
// #property (nonatomic, retain) UIWebView *webView;
[webView loadRequest:request];
Related
in the new safari on the mac they have a bar that can distinguish between google and a url.Thats what i am trying to do. I am wondering what i am doing wrong. It only wants to google not search url. Thanks in advance.
-(IBAction)SearchAll:(id)sender
{
if (googlebar) {
NSString *query = [googlebar.text stringByReplacingOccurrencesOfString:#" " withString:#"+"];
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:#"http://www.google.co./search?q=%#", query]];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webview loadRequest:request];
}
else{
NSString *query = [googlebar.text stringByReplacingOccurrencesOfString:#" " withString:#"+"];
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:#"http://www.%#", query]];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webview loadRequest:request];
}
}
Firstly, your code is way off. You will not achieve your goal this way.
Secondly, You should start off your IBAction statement by checking if the string that was input into the search bar (or urlbar whatever you want to call it) has a prefix of .com or .org...etc. If it does not then it then google searches the text in the UITextfield.
are you sure of your if statement?
you're using searchbar in the else, where searchbar if supposed not to exist.
you should also check the google.co./search url. I'd use google.com/search as it will save you a redirect
I'm still confused by your question though, as you have two toolbars: searchbar and googlebar, not one as in the latest safari for mac
I want to download audio files Asynchronously from internet through ASIHTTP request. I have written a piece of code, but it's not working properly.
+(ASIHTTPRequest *)getDownloadedLectureAndSeries:(id)target :(NSString *)downloadString FinishSelector:(SEL) finishselector FailSelector:(SEL) failselector
{
NSString *api=downloadStrin;
NSURL *url = [NSURL URLWithString:api];
[api release];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
[request startAsynchronous];
[request setDelegate:target];
[request setDidFinishSelector:finishselector];
[request setDidFailSelector:failselector];
return request;
}
Help me, if you can. Thanks in advance.
Doesn't look like you are acctually saving the file anywhere in your code. (Unless you are trying to do it in your finishselector.
Add this line to have the request automatically save the file
[request setDownloadDestinationPath:path];
Where path is a NSString to where you want the file to be stored (such as your Documents directory
I am currently building an Iphone app that is using storyboards. I know how to open new views with buttons via the ctrl+click method etc. The problem I have is that when the user clicks the button, I need to do some calculations and processing, as well as opening a web connection to pull data so I can populate the table in the next view but the view opens first before I can do any of this.
What I'm running into is the view is loading long before I am finished connecting to the web service and have calculated and stored the data for the table in the next view, so it loads blank. I need to either call the view in the button programmatically or somehow slow down the processes with some kind of "loading" screen but don't know how to do either. I guess if its possible to fill the data in the table after the view loads, that could work as well. (if its possible)
Any tips or articles that can point me in the right direction would be appreciated. I haven't found anything myself.
Thanks.
--connect method--
- (IBAction)connect:(id)sender {
//First begin by logging into the web service.
_email = self.logintxt.text;
// ---SOAP 1.1---
//large soap creation. edited for privacy etc.
NSString *soapMsg =
[NSString stringWithFormat:#"",_logintxt.text
];
//---print it to the Debugger Console for verification---
//NSLog(soapMsg);
NSURL *url = [NSURL URLWithString:
#""];
NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:url];
//---set the headers---
NSString *msgLength = [NSString stringWithFormat:#"%d", [soapMsg length]];
[req addValue:#"" forHTTPHeaderField:#"Host"];
[req addValue:#"text/xml; charset=utf-8" forHTTPHeaderField:#"Content-Type"];
[req addValue:#"" forHTTPHeaderField:#"SOAPAction"];
[req addValue:msgLength forHTTPHeaderField:#"Content-Length"];
//---set the HTTP method and body---
[req setHTTPMethod:#"POST"];
[req setHTTPBody: [soapMsg dataUsingEncoding:NSUTF8StringEncoding]];
NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:req delegate:self];
if (conn) {
XMLData = [NSMutableData data];
}
[self performSelector:#selector(getXMLList) withObject:NULL afterDelay:2.0];
[self performSegueWithIdentifier:#"LoginSegue" sender:sender];
You can have your button or whatever linked to a method in your controller, and inside the method after your processing you can call performSegueWithIdentifier: to force the transition when you're done. This will automatically still call prepareForSegue: before the view appears.
I've done something similar to check login details on a login page in my tutorial here.
what I can suggest is to write the button action yourself. to achieve this you have to put stuff in your .h like
#interface MyClass : UIViewController {
IBOutlet UIButton *my_btn;
}
#property (nonatomic, retain) IBoutlet UIButton *my_btn;
- (IBAction)MyBtnTapped:(id)sender;
in your .m remember to
#synthesize my_btn;
then just link the action to your button by using IB, and voila'
the first step is done.
in your .m you can now implement a function MybtnTapped that deals with the data retrival and then opens up the new UIView fulfilled with your new data.
I have a UIWebView in my application where I 'm loading the facebook profile of my application. I am using facebook's single sign on SDK(Graph API). And I logged in into facebook in the Safari in background using my application. But When I try loadmy game profile in my application web view still I could see "Log In" and "Sign Up" buttons.
I tried setting cookies, main document URL and relative URL too but no use.
I am adding here my code too here,
NSURL *url = [NSURL URLWithString:#"http://www.facebook.com/myapp" relativeToURL:[NSURL URLWithString:#"http://login.facebook.com"]];
NSMutableURLRequest *request = nil;
if(url)
request = [NSMutableURLRequest requestWithURL:url];
NSArray * availableCookies = [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookiesForURL:[NSURL URLWithString:#"http://login.facebook.com"]];
NSDictionary * headers = [NSHTTPCookie requestHeaderFieldsWithCookies:availableCookies];
if(request)
{
[request setHTTPShouldHandleCookies:YES];
[request setMainDocumentURL:[NSURL URLWithString:#"http://login.facebook.com"]];
[request setAllHTTPHeaderFields:headers];//login.facebook.com
[mWebView loadRequest:request];
}
You may be running into the situation I describe in the answer on this page:
Facebook iOS SDK not storing cookies for access
I am currently trying to find a solution to this task. Essentially I have an initial UIView that asks for the users username and password for a specific site, this information would then get past onto the next view which has a UIWebView inside. I would like to know if its possible to automatically fill in the username and password details on the site and send the user directly to their account page on the site.
Thanks.
assuming your website has div tags you can inject using stringByEvaluatingJavsScriptFromString.
This example injects a username into the twitter sign up page. You can test it by loading this in your viewDidLoad:
NSString *urlString = #"https://mobile.twitter.com/signup";
NSURL *url = [NSURL URLWithString:urlString];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webView loadRequest:request];
and then in webViewDidFinishLoad inject the username:
- (void)webViewDidFinishLoad:(UIWebView *)webView;
{
[webView stringByEvaluatingJavaScriptFromString:#"var field = document.getElementById('oauth_signup_client_fullname');"
"field.value='yourUserName';"];
}
sorry, just realised you already had the solution but were missing the implementation. Hope the above helps.
btw to add a dynamic variable into the injected javascript use:
- (void)webViewDidFinishLoad:(UIWebView *)webView;
{
NSString *injectedVariable = #"userNameHere";
NSString *injectedString = [NSString stringWithFormat:#"var field = document.getElementById('oauth_signup_client_fullname'); field.value='%#';", injectedVariable];
[webView stringByEvaluatingJavaScriptFromString:injectedString];
}
on solution is to "fake" the login request using the username and password and feed this into the web view.
I.e. you have a page index.php which has a username and password field.
if you fill them in, the page login.php is called with those parameters.
you could build an
NSString *urlString = #”http://www.yoursite.com/login.php?username=user&password=pass”;
NSURL *url = [NSURL URLWithString:urlString];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webView loadRequest:request];
}
that should do the trick