Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

-[NSHTTPCookieStorage cookies] updates in Tool but not in App



As a troubleshooting/understanding experiment, I've set a timer to send -[NSHTTPCookieStorage cookies] every 3 seconds, to see if the returned array shows the cookie additions or deletions executed in Safari.

The result is that, if I do this in a Foundation Tool, the returned array of cookies changes as expected after a few seconds, but if I use the exact same code in a Cocoa Application, the returned array never changes.

Does it have something to do with the run loop?

Thanks,

Jerry Krinock

Note: I tried deleting cookies both by visiting a "logout" web page (to delete session cookies) and by deleting cookies in Safari's Preferences. Same result in either case.

*** CookieChecker class used in both projects ***

@interface CookieChecker : NSObject
@end

@implementation CookieChecker

- (void)check:(NSTimer*)timer {
	NSHTTPCookieStorage* sharedCookieStorage =
	    [NSHTTPCookieStorage sharedHTTPCookieStorage] ;
	NSArray* cookies = [sharedCookieStorage cookies] ;
				
	NSLog(@"You have %5i cookies.", [cookies count]) ;
}

@end

*** Foundation Tool ***

int main (int argc, const char * argv[]) {
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

    CookieChecker* checker = [[CookieChecker alloc] init] ;
    [NSTimer scheduledTimerWithTimeInterval:3.0
                                     target:checker
                                   selector:@selector(check:)
                                   userInfo:nil
                                    repeats:YES] ;
	
	[[NSRunLoop currentRunLoop] run] ;
	
	[pool release];
    return 0;
}

*** Cocoa Application ***

@implementation AppController

- (void)applicationDidFinishLaunching:(NSNotification *)note {

    // Same code! :
    CookieChecker* checker = [[CookieChecker alloc] init] ;
    [NSTimer scheduledTimerWithTimeInterval:3.0
                                     target:checker
                                   selector:@selector(check:)
                                   userInfo:nil
                                    repeats:YES] ;
}	

@end

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden


Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.