Reputation: 698
I have a connection issue that I am unsure how to resolve. I have combed through the documentation for the Errors and for NSURLConnection
. This is code that I am using in my iOS version of the same app. It works fine there, but when I brought it to the OS X version of the app, it doesn't work. This is the code:
NSURL* url = [NSURL URLWithString:@"url"];
NSString* data = [NSString stringWithFormat:@"command=retrieve&number=%d", number];
NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:url];
[request setHTTPMethod:@"POST"];
[request setHTTPBody:[data dataUsingEncoding:NSUTF8StringEncoding]];
NSLog(@"Starting Command");
NSOperationQueue* queue = [[NSOperationQueue alloc] init];
[NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
NSLog([NSString stringWithFormat:@"%@",connectionError]);
if ([data length] > 0 && connectionError == nil) {
dispatch_async(dispatch_get_main_queue(), ^{
[self parseResponseFromCommandRequest:data];
});
}
}];
NSLog(@"Ending Command");
The error occurs in the NSURLConnection
. The output is:
Error Domain=NSPOSIXErrorDomain Code=1 "The operation couldn’t be completed. Operation not permitted" UserInfo=0x610000279dc0 {NSErrorFailingURLStringKey=url, NSErrorFailingURLKey=url}
url is actually a functioning url, but I replaced it here. Like I said, it works fine on iOS, but not on OS X. Is there a Library that I could be missing that is causing this? Any other ideas?
Upvotes: 3
Views: 1546
Reputation: 47284
It could be just a matter of setting up the entitlements to allow access. It looks from the error that it fails because it's not permitted, which would indicate the app sandbox is doing it's job. For NSURL
you would normally use bookmarks.app-scope
or bookmarks.document-scope
.
See: Enabling Security-Scoped Bookmark and URL Access
Depending on how your app is using the NSURL, network entitlements may be worth looking into:
com.apple.security.network.server = Allow Incoming Connections
com.apple.security.network.client = Allow Outgoing Connections
Upvotes: 9