Mailing Lists: Apple Mailing Lists

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

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



I've also now tried to run the CookieChecker in a separate thread of my App, but still the same results: It does not update when cookies are changed in Safari.

To resolve the issue, I've now worked around it by using a kludge from other information instead. If no one posts an explanation, I'll submit a bug report.

Jerry Krinock

*** Cocoa Application, Threaded Version ***

@implementation AppController

- (void)checkThreaded:(id)nilly {
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init] ;
	
    // Same code:
    CookieChecker* checker = [[CookieChecker alloc] init] ;
    [NSTimer scheduledTimerWithTimeInterval:3.0
                                     target:checker
                                   selector:@selector(check:)
                                   userInfo:nil
                                    repeats:YES] ;
    [[NSRunLoop currentRunLoop] run] ;
	
    [pool release] ;
}	

- (void)applicationDidFinishLaunching:(NSNotification *)note {
	[NSThread detachNewThreadSelector:@selector(checkThreaded:)
                                 toTarget:self
                               withObject:nil] ;
}	

@end

On 2007 Mar, 27, at 18:40, Jerry Krinock wrote:

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

_______________________________________________

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
References: 
 >-[NSHTTPCookieStorage cookies] updates in Tool but not in App (From: Jerry Krinock <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.