Jawaban:
Aplikasi Anda memiliki "toples kue" sendiri di dalam [NSHTTPCookieStorage sharedHTTPCookieStorage]
wadah.
Berikut adalah cara Anda dapat melihat sekilas cookie di toples cookie aplikasi Anda:
NSHTTPCookie *cookie;
NSHTTPCookieStorage *cookieJar = [NSHTTPCookieStorage sharedHTTPCookieStorage];
for (cookie in [cookieJar cookies]) {
NSLog(@"%@", cookie);
}
Beberapa metode tersedia untuk pemfilteran dan manipulasi. Lihatlah di NSHTTPCookieStorage dokumentasi untuk mengakses cookie, dan NSHTTPCookie dokumentasi untuk mengakses properti kue individu.
cookiesForURL
metode sebagai pengganticookies
Terima kasih atas penunjuk Alex! Untuk menambahkan ini, saya akan memasukkan "cookie dumper" yang saya buat menggunakan contoh Alex. Mungkin ini akan membantu orang lain.
- (void) dumpCookies:(NSString *)msgOrNil {
NSMutableString *cookieDescs = [[[NSMutableString alloc] init] autorelease];
NSHTTPCookie *cookie;
NSHTTPCookieStorage *cookieJar = [NSHTTPCookieStorage sharedHTTPCookieStorage];
for (cookie in [cookieJar cookies]) {
[cookieDescs appendString:[self cookieDescription:cookie]];
}
NSLog(@"------ [Cookie Dump: %@] ---------\n%@", msgOrNil, cookieDescs);
NSLog(@"----------------------------------");
}
- (NSString *) cookieDescription:(NSHTTPCookie *)cookie {
NSMutableString *cDesc = [[[NSMutableString alloc] init] autorelease];
[cDesc appendString:@"[NSHTTPCookie]\n"];
[cDesc appendFormat:@" name = %@\n", [[cookie name] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
[cDesc appendFormat:@" value = %@\n", [[cookie value] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
[cDesc appendFormat:@" domain = %@\n", [cookie domain]];
[cDesc appendFormat:@" path = %@\n", [cookie path]];
[cDesc appendFormat:@" expiresDate = %@\n", [cookie expiresDate]];
[cDesc appendFormat:@" sessionOnly = %d\n", [cookie isSessionOnly]];
[cDesc appendFormat:@" secure = %d\n", [cookie isSecure]];
[cDesc appendFormat:@" comment = %@\n", [cookie comment]];
[cDesc appendFormat:@" commentURL = %@\n", [cookie commentURL]];
[cDesc appendFormat:@" version = %d\n", [cookie version]];
// [cDesc appendFormat:@" portList = %@\n", [cookie portList]];
// [cDesc appendFormat:@" properties = %@\n", [cookie properties]];
return cDesc;
}
NSHTTPCookieStorage
: macdevelopertips.com/objective-c/objective-c-categories.html
Alex punya ide bagus untuk memasukkan ini ke dalam kategori. Inilah yang akhirnya saya gunakan:
NSHTTPCookieStorage + Info.h
#import <Foundation/Foundation.h>
@interface NSHTTPCookieStorage (Info)
+ (NSDictionary*) describeCookies;
+ (NSDictionary *) describeCookie:(NSHTTPCookie *)cookie;
@end
NSHTTPCookieStorage.m
@implementation NSHTTPCookieStorage (Info)
+ (NSDictionary*) describeCookies {
NSMutableDictionary *descriptions = [NSMutableDictionary new];
[[[NSHTTPCookieStorage sharedHTTPCookieStorage] cookies] enumerateObjectsUsingBlock:^(NSHTTPCookie* obj, NSUInteger idx, BOOL *stop) {
[descriptions setObject:[[self class] describeCookie:obj] forKey:[[obj name] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
}];
NSLog(@"Cookies:\n\n%@", descriptions);
return descriptions;
}
+ (NSDictionary *) describeCookie:(NSHTTPCookie *)cookie {
return @{@"value" : [[cookie value] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding],
@"domain" : [cookie domain] ? [cookie domain] : @"n/a",
@"path" : [cookie path] ? [cookie path] : @"n/a",
@"expiresDate" : [cookie expiresDate] ? [cookie expiresDate] : @"n/a",
@"sessionOnly" : [cookie isSessionOnly] ? @1 : @0,
@"secure" : [cookie isSecure] ? @1 : @0,
@"comment" : [cookie comment] ? [cookie comment] : @"n/a",
@"commentURL" : [cookie commentURL] ? [cookie commentURL] : @"n/a",
@"version" : @([cookie version]) };
}
@end
Membuat keluaran sedikit lebih "JSON-y" ...
di sandbox:Library->Cookies->Cookies.binarycookies
tetapi Anda tidak dapat membuka .binarycookie
s secara langsung, Anda dapat menjalankan skrip:
Unduh dan instal Python
Unduh BinaryCookieReader.py
Jalankan "Python BinaryCookieReader.py" di terminal
seperti yang Anda lihat, log keluaran berisi deskripsi detail cookie