NSURL *url = [NSURL URLWithString: address];
NSString *body = [NSString stringWithFormat: #"%#", webViewString];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc]initWithURL: url];
[request setHTTPMethod: #"POST"];
[request setHTTPBody: [body dataUsingEncoding: NSUTF8StringEncoding]];
[_paymentWebView loadRequest: request];
I load the UIWebView but I got this error in my application when I try to access the PayUMoney payment gateway via UIWebView in above code but it show this error and I am using AFNetworking in other API calls.
Kindly help me to resolve this error.
objc[4933]: Class PLBuildVersion is implemented in both /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/PrivateFrameworks/AssetsLibraryServices.framework/AssetsLibraryServices (0x12487e998) and /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/System/Library/PrivateFrameworks/PhotoLibraryServices.framework/PhotoLibraryServices (0x1246a3d38). One of the two will be used. Which one is undefined.**
Just use
NSURL *url = [NSURL URLWithString: address];
NSString *body = [NSString stringWithFormat: #"%#", webViewString];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[_paymentWebView loadRequest: request];
You don't need to use setHTTPBody or setHTTPMethod.
The code you have is not how we should load url in webview.
The sweet and simple way is as below to load URL in UIWebView.
NSURL *websiteUrl = [NSURL URLWithString:#"http://www.google.com"];
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:websiteUrl];
[myWebView loadRequest:urlRequest];
Related
I am developing HTML web page. I am creating session id in that.
I want to use the same session id for opening that web site through my iOS app as well.
NSString *urlString = #"http://www.myserver.com:8080/Test/TestPage";
NSURL *url = [NSURL URLWithString:urlString];
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url];
[webview loadRequest:urlRequest];
Is it possible to launch a web url using Session ID appended in iOS?
If I am not understanding it in the wrong way, you just want to add some parameters to your request, in this case sessionID. In this case you should do this:
NSURL *url = [NSURL URLWithString: #"http://www.myserver.com:8080/Test/TestPage"];
NSString *body = [NSString stringWithFormat: #"sessionID=%#", #"val1"];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc]initWithURL: url];
[request setHTTPMethod: #"POST"];
[request setHTTPBody: [body dataUsingEncoding: NSUTF8StringEncoding]];
[webView loadRequest: request];
On the other way around, you can use for example AFNetworking Library that will allow you to do things like this:
NSDictionary * parameters = #{#"sessionID" : #"123"};
NSMutableURLRequest * mutableRequest = [self requestWithMethod:#"POST"
path:#"http://www.myserver.com:8080/Test/TestPage"
parameters:parameters];
Anyways, #Popeye is right, you would need to manage this somehow in your server.
I have this URL I want to pass Self.Id in this url cid=self.Id .I am pass following why but getting result invalid request.
NSURL *url = [NSURL URLWithString:
#"http://sms.instatalkcommunications.com/apireq/GetCommentsForSMS?
t=1&h=admin&last=0&cid=Self.Id&items=5"];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request setRequestMethod:#"GET"];
[request setDidFailSelector:#selector(requestCompleted:)];
[request setDelegate:self];
[request startAsynchronous];
[NSURL URLWithString:[NSString stringWithFormat:#"http://sms.instatalkcommunications.com/apireq/GetCommentsForSMS?
t=1&h=admin&last=0&cid=%#&items=5",Self.Id]];
I have an UIWebView in my iOS app that loads different url's depending on a previous action. I wan't these pages to load as fast as possible. I found the class EGOCache (source) and I i got it working to store cacheData in library/Caches directory. But I'm not sure how to retrieve this cache to load it faster, I can't see the difference. Maybe use NSCache? What have I missed?
- (void)webViewDidStartLoad:(UIWebView *)webView {
if (webView_1) {
NSString *urlAddress = #"http://www.apple.com";
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *request = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval: 10.0];
[webView1 loadRequest:request];
NSData *data0 = [NSURLConnection sendSynchronousRequest:
[NSURLRequest requestWithURL:url]
returningResponse:nil
error:nil];
[[EGOCache globalCache] setData:data0 forKey:#"webCache"];
}
}
Thanks!
Okay so I made my own method and I got it working. All you have to do is to give the url address. See this code:
-(void)loadPage:(NSString *)urlAddress {
NSURL *url = [NSURL URLWithString:urlAddress];
NSString* cachePath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString* file = [cachePath stringByAppendingPathComponent:#"/xxx.APPNAME/EGOCache/EGOCache.plist"];
NSDictionary *dict =[NSDictionary dictionaryWithContentsOfFile:file];
if ([dict objectForKey:urlAddress] )
{
NSData *data = [[EGOCache globalCache] dataForKey:urlAddress];
data = [NSURLConnection sendSynchronousRequest:
[NSURLRequest requestWithURL:url]
returningResponse:nil
error:nil];
NSLog(#"loading from cache %#",urlAddress);
}else{
NSData *data = [NSURLConnection sendSynchronousRequest:
[NSURLRequest requestWithURL:url]
returningResponse:nil
error:nil];
[[EGOCache globalCache] setData:data forKey:urlAddress];
NSLog(#"saving cache %#",urlAddress);
[[EGOCache globalCache] setDefaultTimeoutInterval:60*60*24*4]; //timeout (4 days)
}
NSURLRequest *request = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval: 10.0];
[webView loadRequest:request];
}
To accomplish what you are trying to implement you would need to subclass NSURLCache and implement the required methods, with your implementation accessing EGOCache. UIWebView and NSURLConnection use NSURLCache for caching data. Once you have your custom subclass implemented, you would set an instance of it to be your application's URL cache using setSharedCache:.
I am loading a uiwebview with the following code:
NSString *fullURL = #"http://www.example.com";
NSURL *url = [NSURL URLWithString:fullURL];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[webview loadRequest:requestObj];
Is there any means to cache the website so its available offline if there is no connection?
The key is: NSURLRequestReturnCacheDataElseLoad
NSData *urlData;
NSString *baseURLString = #"mysite.com";
NSString *urlString = [baseURLString stringByAppendingPathComponent:#"myfile"];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:urlString] cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval: 10.0];
NSURLConnection *connection=[[NSURLConnection alloc] initWithRequest:request delegate:nil];
if (connection)
{
urlData = [NSURLConnection sendSynchronousRequest: request];
NSString *htmlString = [[NSString alloc] initWithData:urlData encoding:NSUTF8StringEncoding];
[webView loadHTMLString:htmlString baseURL:baseURLString];
[htmlString release];
}
[connection release];
Hope this will help.
I creating the app for my site and have a problem with signin. I have login page with login and pass fields and the "Login" button.
I tried to write post request (You can see it below) for sign in, but it doesn't work.
Please, give me some solutions.
I've been coding in Obj-C just a few weeks and I don't now many things.
NSString *login = loginField.text;
NSString *password = passField.text;
NSURL *theURL = [NSURL URLWithString:[NSString stringWithFormat:#"http://mysite",login, password]]; //Here you place your URL Link
NSURLRequest *req = [NSURLRequest requestWithURL:theURL];
NSURLConnection *connection = [NSURLConnection connectionWithRequest:req delegate:self];
if (connection) {
NSLog(#"connection successful");
}
else {
NSLog(#"Failed");
}
NSURLRequest HTTPMethod is by default "GET" and you need to set it to "POST" in your code.
My example shows a NSMutableURLRequest because I have had this code tested in an application. You should be able to do the same with NSURLRequest if you prefer that.
NSMutableURLRequest *req = [[NSMutableURLRequest alloc] init];
[req setURL:[NSURL URLWithString:theUrl]];
[req setHTTPMethod:#"POST"];
Hope this helps.