klippa-app/nativescript-http

[IOS] - Clear Cookies

mapo80 opened this issue · 6 comments

Hi,

I've a problem with method "clearCookies" on iOS if executed from the second time.
I've this error:
Error: *** __boundsFail: index 3 beyond bounds [0 .. 1]

I had to use a try/catch to intercept the error.

Do you know how to fix?

Thanks

Hi! Are you possibly executing clearCookies 2 times at the same time? It might be some race condition, I will test this today!

No, I've seen that deleteCookie remove from array so count is different on every delete.

This should be ok:

export function clearCookies() {
    if (sessionConfig.HTTPCookieStorage && sessionConfig.HTTPCookieStorage.cookies) {
        const cookieSize = sessionConfig.HTTPCookieStorage.cookies.count;
        if (cookieSize <= 0) {
            return; 
        }

        for (let i = cookieSize - 1; i >= 0; i--) {
            const cookie = sessionConfig.HTTPCookieStorage.cookies.objectAtIndex(i);
            sessionConfig.HTTPCookieStorage.deleteCookie(cookie);
        }

    }
}

Ah yeah, that makes sense! I will create a new release soon, thanks!

I hope you'll create a new version soon.

Thanks very much for everything!

If you want I can make a pull request. Let me know.

@mapo80 I just pushed 1.3.1 to npm!