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

匿名 (未验证) 提交于 2019-12-03 02:30:02

问题:

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.

回答1:

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.



回答2:

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)



回答3:

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)

Sorry ^_^, now I can't upload image(because I sign up just now).



回答4:

I've found the way to avoid the issue.

To solve the issue, add an environment variable before launching tests as follows:

XPC_SIMULATOR_LAUNCHD_NAME="com.apple.CoreSimulator.SimDevice.04042E78-E743-4376-94E9-31842D4770B6.launchd_sim"

However, the 04042E78-E743-4376-94E9-31842D4770B6 is depends on each environment. So it can not be hard-coded. I'm looking for a way to read the value from project settings.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!