I am writing an app that needs to store a cookie.
my plan is to do the following.
// create a ref to shared storage area NSHTTPCookieStorage *cookieJar = [NSHTTPCookieStorage sharedHTTPCookieStorage]; // query the current acceptpolicy (ie want to store it for later...) [cookieJar cookieAcceptPolicy]; /******** This line crashes app ********/ [cookieJar setcookieAcceptPolicy:NSHTTPCookieAcceptPolicyAlways]; NSArray *mycookies = [cookieJar cookies]; ..... do more stuff ..... change it back....
Problem is I can’t figure out how to store the result of cookieAcceptPolicy for later use. the docs shows – (NSHTTPCookieAcceptPolicy)cookieAcceptPolicy, makes no sense to me.
Help appreciated.
The documentation actually shows
- (NSHTTPCookieAcceptPolicy)cookieAcceptPolicywhich means it returns the value of an enum typedef’d as NSHTTPCookieAcceptPolicy. So something like:should work. The reason your app is “crashing” is because of the lowercase ‘c’ in the setCookieAcceptPolicy method of the line below the one you think is crashing your app. You definitely receive a warning about this at compile time… in the future I’d advise you to strive for not just error-free, but warning-free objective-C code, since type-checking isn’t plausible for dynamically-typed languages.