嗨,我需要修改Cookie,但是我正在iOS中进行开发,有人知道如何更改它。也许在UIWebViewDelegate中使用webView:shouldStartLoadWithRequest:navigationType:??
因为WebKit.framework无法用于IOS,所以最好的方法是将事件用于UIWebView shouldStartLoadWithRequest和webViewDidFinishLoad,因此我将NSHTTPCookieStorage类用于cookie并进行如下修改
NSHTTPCookieStorage *sharedHTTPCookieStorage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
NSArray *cookies = [sharedHTTPCookieStorage cookiesForURL:[NSURL URLWithString:self.webView.request.URL.absoluteString]];
NSEnumerator *enumerator = [cookies objectEnumerator];
NSHTTPCookie *cookie;
while (cookie = [enumerator nextObject])
{
if ([[cookie name] isEqualToString:key])
{
NSString *actcookie = [cookie value];
NSMutableString *newcookiestring = [NSMutableString stringWithFormat:@"%@changes",actcookie];
NSMutableDictionary *propscook = [[NSMutableDictionary alloc] initWithDictionary: [cookie properties]];
[propscook setObject:newcookiestring forKey:NSHTTPCookieValue];
NSHTTPCookie *newcookie = [NSHTTPCookie cookieWithProperties:propscook];
[sharedHTTPCookieStorage setCookie:newcookie];
return [cookie value];
}
}
return nil;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2656 次 |
| 最近记录: |