문제

In a previous answer I found on stackoverflow (can't find now) someone suggested using NSRange rangeOfString to see if a particular variable had data in it from a cookie:

NSRange range = [[[NSHTTPCookie requestHeaderFieldsWithCookies:[[NSHTTPCookieStorage sharedHTTPCookieStorage] cookiesForURL:[NSURL URLWithString:cookie]]] objectForKey:@"Cookie"] rangeOfString:@"variable"];
if (range.length != NSNotFound) {
    //it has data
} else {
    //it doesn't
}

From what resources I can find this should work, but it doesn't, even when the cookie is null.

What am I doing wrong?

도움이 되었습니까?

해결책

This is a bit odd. Even though range.length is apparently null if you log the output you can't check if its null and NSNotFound doesn't work as expected. You have to check if the value > 0.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top