[ 
https://issues.apache.org/jira/browse/CB-12074?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16180050#comment-16180050
 ] 

Grant Patterson commented on CB-12074:
--------------------------------------

Well I've developed a workaround for AJAX/XHR requests. It's disgusting. :-(
I wrote a native-code XHR function that my javascript code can call. It makes 
that call, then needs to wait at least 2 seconds before attempting further XHRs 
within javascript. If I don't wait long enough, those XHRs all fail because no 
cookies are remembered. But if it waits long enough, subsequent XHRs from 
javascript will have the cookies that were received from the native-code XHR.

I filed a bug for this issue, which I think is separate from cookies working at 
all: https://bugs.webkit.org/show_bug.cgi?id=177478

Native-code XHR implementation:

{code}
- (void)executeXHR:(CDVInvokedUrlCommand *)command {
    NSString *urlStr = command.arguments[0];
    NSURL *url = [NSURL URLWithString:urlStr];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
    [request setHTTPMethod:@"GET"];
    [request setValue:@"application/json" forHTTPHeaderField:@"Accept"];

    [[[NSURLSession sharedSession] dataTaskWithRequest:request 
completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable 
response, NSError * _Nullable error) {
        CDVPluginResult *result;
        NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
        NSHTTPURLResponse *httpResponse = nil;
        if (response && [response isKindOfClass:[NSHTTPURLResponse class]]) {
            httpResponse = (NSHTTPURLResponse*)response;
            dict[@"statusCode"] = [NSNumber 
numberWithInteger:httpResponse.statusCode];
        }
        if (data) {
            dict[@"data"] = [[NSString alloc] initWithData:data 
encoding:NSUTF8StringEncoding];
        }
        if (error) {
            NSLog(@"executeXHR error: %@", error);
            dict[@"error"] = [error localizedDescription];
            if (httpResponse) {
                NSLog(@"executeXHR error code: %d", 
(int)httpResponse.statusCode);
            }
            result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR 
messageAsDictionary:dict];
        } else {
            result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK 
messageAsDictionary:dict];
        }
        [self.commandDelegate sendPluginResult:result 
callbackId:command.callbackId];
    }] resume];
}
{code}


> Cookies are ignored on first application execution
> --------------------------------------------------
>
>                 Key: CB-12074
>                 URL: https://issues.apache.org/jira/browse/CB-12074
>             Project: Apache Cordova
>          Issue Type: Bug
>          Components: cordova-plugin-wkwebview-engine
>         Environment: Cordova 5.4.0, iOS 9.3.5
>            Reporter: Maxim
>            Assignee: Shazron Abdullah
>              Labels: wkwebview-known-issues
>
> Our application authenticates to the server. The server sets a 'JSESSIONID' 
> cookie. The cookie is used by the server for session management. 
> The issue is WKWebView does not send this cookie back to the server on 
> subsequent requests. However, this only happens on first execution of the 
> application, after its installation. Once the application closed and 
> re-opened, the cookies are properly sent and authentication completes 
> successfully. 
> The problematic behavior is consistent, and was observed on several devices. 
> On the other hand, there are no such issues with UIWebView. 



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@cordova.apache.org
For additional commands, e-mail: issues-h...@cordova.apache.org

Reply via email to