I'm making an iPhone tweak using THEOS which hooks to Google Chrome App. Part of the tweak functions, is to handle downloading and saving files using ASIHTTPRequest/ASINetworkQueue. The user can choose and set the download destination freely. This works fine as long as I set the download path to "/tmp" or Google Chrome Documents Folder. When I try to choose a folder other then these, like for instance "/var/mobile/Documents/" I get no permission error:
Domain=NSCocoaErrorDomain Code=513 "The operation couldn’t be completed. (Cocoa error 513.)" UserInfo=0x1f53e230 {NSFilePath=/var/mobile/Documents, NSUnderlyingError=0x1f53b3d0 "The operation couldn’t be completed. Operation not permitted
I've looked up this error and tried every other answer suggested here on StackExchange but to no avail.
I'm developing for IOS 6 and I'm including the answers I've read here as links in case you guys think I missed out something:
1 - How to make a directory iOS?
2 - iphone create folder outside sandbox
3 - Cydia App Documents Folder Not Created
4 - Gaining root permissions on iOS for NSFileManager (Jailbreak)
The last link refers to running the app as root to access non mobile directories but not sure if this is appropriate since I'm only making a tweak for Chrome.
I hope someone could help me with this issue or point me in the right direction. I'm tearing my hair out.
Here's a common code snippet for creating a directory which just doesn't work for me:
NSString* SaveDir = @"/var/mobile/Documents/Test";
NSFileManager* fileManager = [NSFileManager defaultManager];
NSMutableDictionary* attributes = [[NSMutableDictionary alloc] init];
NSNumber* permission = [NSNumber numberWithLong: 0755];
[attributes setObject:permission forKey: NSFilePosixPermissions];
NSError* error = nil;
if (![fileManager createDirectoryAtPath: SaveDir
withIntermediateDirectories: YES
attributes: attributes
error: &error])
{
NSLog(@"Unable to create data directory: %@", error);
}
[attributes release];
Thank you guys in advance
My note about Cocoanuts Sandcastle from bigboss was right. I've linked to Sandcastle dylib and using its methods I was able to create files/directories outside the sandbox.
Another library is H2Co3 Unbox, which allows to do the same thing only difference is within unbox commands are executed by daemon.