+ (NSString*) startPage {
return @"http://192.168.7.185:8088/Html5/index.html";
}
NSString* startPage = [[self class] startPage];
NSURL *appURL = [NSURL URLWithString:startPage];
NSString* loadErr = nil;
if(![appURL scheme]) {
NSLog(@"appURL scheme nil");
NSString* startFilePath = [[self class] pathForResource:startPage];
if (startFilePath == nil) {
loadErr = [NSString stringWithFormat:@"ERROR: Start Page at '%@/%@' was not found.", [[self class] wwwFolderName], startPage];
NSLog(@"%@", loadErr);
appURL = nil;
} else {
appURL = [NSURL fileURLWithPath:startFilePath];
}
}
if (!loadErr) {
int height = (int)[[UIScreen mainScreen] bounds].size.height;
int width = (int)[[UIScreen mainScreen] bounds].size.width;
NSString *strHeight = [NSString stringWithFormat:@"%d", height];
NSString *strWidth = [NSString stringWithFormat:@"%d", width];
NSString *unidstring = [[UIDevice currentDevice] uniqueIdentifier];
NSString *deviceType = [[UIDevice currentDevice] model];
NSString *version = [[UIDevice currentDevice] systemVersion];
NSDictionary *properties = [NSDictionary dictionaryWithObjectsAndKeys: strHeight, NSHTTPCookieValue, @"me_client-height",
NSHTTPCookieName, @"/" , NSHTTPCookiePath, @"192.168.7.185" , NSHTTPCookieDomain, nil];
NSHTTPCookie *cookie_PD1 = [NSHTTPCookie cookieWithProperties:properties];
NSDictionary *propertiesWidth = [NSDictionary dictionaryWithObjectsAndKeys: strWidth, NSHTTPCookieValue, @"me_client-Width",
NSHTTPCookieName, @"/" , NSHTTPCookiePath, @"192.168.7.185" , NSHTTPCookieDomain, nil];
NSHTTPCookie *cookie_PD2 = [NSHTTPCookie cookieWithProperties:propertiesWidth];
NSDictionary *propertiesUni = [NSDictionary dictionaryWithObjectsAndKeys: unidstring, NSHTTPCookieValue, @"me_imei",
NSHTTPCookieName, @"/" , NSHTTPCookiePath, @"192.168.7.185" , NSHTTPCookieDomain ,nil];
NSHTTPCookie *cookie_PD3 = [NSHTTPCookie cookieWithProperties:propertiesUni];
NSDictionary *propertiesDev = [NSDictionary dictionaryWithObjectsAndKeys: deviceType, NSHTTPCookieValue, @"me_userggent",
NSHTTPCookieName, @"/" , NSHTTPCookiePath, @"192.168.7.185" , NSHTTPCookieDomain, nil];
NSHTTPCookie *cookie_PD4 = [NSHTTPCookie cookieWithProperties:propertiesDev];
NSDictionary *propertiesVer = [NSDictionary dictionaryWithObjectsAndKeys: version, NSHTTPCookieValue, @"me_version",
NSHTTPCookieName, @"/" , NSHTTPCookiePath, @"192.168.7.185" , NSHTTPCookieDomain, nil];
NSHTTPCookie *cookie_PD5 = [NSHTTPCookie cookieWithProperties:propertiesVer];
[[NSHTTPCookieStorage sharedHTTPCookieStorage] setCookie:cookie_PD1];
[[NSHTTPCookieStorage sharedHTTPCookieStorage] setCookie:cookie_PD2];
[[NSHTTPCookieStorage sharedHTTPCookieStorage] setCookie:cookie_PD3];
[[NSHTTPCookieStorage sharedHTTPCookieStorage] setCookie:cookie_PD4];
[[NSHTTPCookieStorage sharedHTTPCookieStorage] setCookie:cookie_PD5];
NSMutableURLRequest *appReq = [NSMutableURLRequest requestWithURL:appURL cachePolicy:
NSURLRequestUseProtocolCachePolicy timeoutInterval:20.0];
[self.webView loadRequest:appReq];
} else {
NSString* html = [NSString stringWithFormat:@"<html><body> %@ </body></html>", loadErr];
[self.webView loadHTMLString:html baseURL:nil];
self.loadFromString = YES;
}
在设置特定的cookis时,需要注意以下:
1:在NSDictionary设置字典的时候必须包含以下几项:NSHTTPCookieValue, NSHTTPCookieName, NSHTTPCookiePath, NSHTTPCookieDomain。
2:在甚至键值对NSHTTPCookiePath时,value必须是url的Domain。