Search code examples
objective-cnsurlconnectionnsurlrequestosx-yosemite

NSURLRequest not working on Yosemite Today Extension


I am trying to create a Yosemite Notification Center widget for my own personal use. It is supposed to grab a number from a server using NSURLRequest and NSURLConnection and display that number in a label. I have it working in a normal Objective-C Cocoa application so I don't think there is a problem with my code, but I can't get the exact same code to work on the Today Extension. This is the error I get:

2014-11-04 13:07:00.178 B-Web mobile downloads[854:39027] ***storageTaskManagerExistsWithIdentifier:withIdentifier failed: Error Domain=NSCocoaErrorDomain Code=4099 "Couldn’t communicate with a helper application." (The connection to service named com.apple.nsurlstorage-cache was invalidated.) UserInfo=0x60000026e6c0 {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 .m for the Today Extension is here. The URL I'm getting the number from is in my actual code but I withheld it there. Just so you know, the response string and label are declared in the .h. Why is this not working in the Today Extension? Am I doing something wrong?


Solution

  • I had the same problem and could solve it. The extension is started in a sandbox. You can permit outgoing connections in the sandbox by navigate to your project and select your extension target. Then go on the capabilities section and enable outgoing connections.