Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The connection to service named com.apple.nsurlstorage-cache was invalidated

I'm creating a custom keyboard for iOS8, and I'm having a tough time figuring out some issues with NSURLConnection.

I'm using the sendAsynchronousRequest: method like this:

[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
        NSLog(@"recieved asynchronous response");

        if (!connectionError) {
            [self connection:nil didReceiveData:data];
            [self connectionDidFinishLoading:nil];
        }
        else{
            NSLog(@"connection failed - %@", connectionError);
        }
    }];

This all seems to work correctly for a period of time (1-2 days), and I can correctly receive data. After this time I start seeing the following error message:

 ***cachedResponseForRequest:key:handler failed: 

Error Domain=NSCocoaErrorDomain Code=4099 "The operation couldn’t be completed. (Cocoa error 4099.)" (The connection to service named com.apple.nsurlstorage-cache was invalidated.) UserInfo=0x17579030 {NSDebugDescription=The connection to service named com.apple.nsurlstorage-cache was invalidated.}; { NSDebugDescription = "The connection to service named com.apple.nsurlstorage-cache was invalidated.";

The only way I then seem to be able to make things work correctly again is to reset the content and setting on the phone. If anyone could point me in the correct direction as to why this is happening I would be very grateful. Thanks in advance.

like image 258
SteveB Avatar asked Sep 11 '14 20:09

SteveB


2 Answers

This occures because the device didn't allow your keyboard to use internet.

To fix this, first check that your keyboard extention's Info.plist has the value "YES" for the key "RequestsOpenAccess".

Then, after installing your app on a device, go to Settings -> General -> Keyboard -> Keyboards -> , and turn on the "Allow Full Access" button.

like image 139
Drico Avatar answered Nov 20 '22 13:11

Drico


I also had this problem. When I write a widget for my app, the widget can use network. Then I found how to allow to use network.

Just choose your Target(keyboard) -> Capabilities -> Switch on App Sandbox -> check Network. Incoming Connections(Server) Outgoing Coonections(Client)

like image 26
DianQK Avatar answered Nov 20 '22 12:11

DianQK