-
-
Save cnsoft/5911269 to your computer and use it in GitHub Desktop.
| // | |
| http://ioscreator.com/loading-a-website-with-uiwebview/ | |
| Now modify the ViewDidLoad method in ViewController.m | |
| - (void)viewDidLoad | |
| { | |
| [super viewDidLoad]; | |
| //1 | |
| NSString *urlString = @"http://ioscreator.com"; | |
| //2 | |
| NSURL *url = [NSURL URLWithString:urlString]; | |
| //3 | |
| NSURLRequest *request = [NSURLRequest requestWithURL:url]; | |
| //4 | |
| NSOperationQueue *queue = [[NSOperationQueue alloc] init]; | |
| //5 | |
| [NSURLConnection sendAsynchronousRequest:request queue:queue | |
| completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) { | |
| if ([data length] > 0 && error == nil) [myWebView loadRequest:request]; | |
| else if (error != nil) NSLog(@"Error: %@", error); | |
| }]; | |
| } | |
| http://blog.csdn.net/totogo2010/article/details/7686164 | |
| Delphi FMX Webrowser 如何使用 NSURLConnection | |
| - (void)viewDidLoad | |
| { | |
| [super viewDidLoad]; | |
| webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)]; | |
| NSURLRequest *request =[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.baidu.com"]]; | |
| [self.view addSubview: webView]; | |
| [webView loadRequest:request]; | |
| } |
http://blog.csdn.net/wangyx810328/article/details/8752295
在UIWebView中设置cookie
分类: IOS 2013-04-02 16:58 54人阅读 评论(0) 收藏 举报
项目中,需要在打开3g网页时,通过cookie传递一些信息。
实现代码如下:
在
[plain] view plaincopy
NSURL *url = [NSURL URLWithString:_urlstr];
//NSURLRequest *request = [NSURLRequest requestWithURL:url];
NSURLRequest *request = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval:60];
[self.myWeb loadRequest:request];
之前,设置或者删除cookie。
[plain] view plaincopy
//////////////////////////////////////////////////////
//设置cookie
-
(void)setCookie{
NSMutableDictionary *cookiePropertiesUser = [NSMutableDictionary dictionary];
[cookiePropertiesUser setObject:@"cookie_user" forKey:NSHTTPCookieName];
[cookiePropertiesUser setObject:uid forKey:NSHTTPCookieValue];
[cookiePropertiesUser setObject:@"xxx.xxx.com" forKey:NSHTTPCookieDomain];
[cookiePropertiesUser setObject:@"/" forKey:NSHTTPCookiePath];
[cookiePropertiesUser setObject:@"0" forKey:NSHTTPCookieVersion];// set expiration to one month from now or any NSDate of your choosing
// this makes the cookie sessionless and it will persist across web sessions and app launches
/// if you want the cookie to be destroyed when your app exits, don't set this
[cookiePropertiesUser setObject:[[NSDate date] dateByAddingTimeInterval:2629743] forKey:NSHTTPCookieExpires];NSHTTPCookie *cookieuser = [NSHTTPCookie cookieWithProperties:cookiePropertiesUser];
[[NSHTTPCookieStorage sharedHTTPCookieStorage] setCookie:cookieuser];
}
//清除cookie
-
(void)deleteCookie{
NSHTTPCookie *cookie;NSHTTPCookieStorage *cookieJar = [NSHTTPCookieStorage sharedHTTPCookieStorage];
NSArray *cookieAry = [cookieJar cookiesForURL: [NSURL URLWithString: _urlstr]];
for (cookie in cookieAry) {
[cookieJar deleteCookie: cookie];}
}
http://stackoverflow.com/questions/6031034/uiwebview-webviewdidfinishload-not-getting-called-ios