Hi All,
I’m trying to load/save some very basic settings in an iOS app. Traditionally on MSW/OSX I’ve done this by reading/writing to a json file. On iOS I’m able to read the initial settings, but it’s throwing errors when I’m trying to write to the same file. I’m looking into doing this natively using Objective-C using a plist instead, but figured it was worth finding out why this is happening.
The EXC_BAD_ACCESS error is being thrown in the JsonTree::write() method because of a nullptr resulting from trying to get the target’s stream.
void JsonTree::write( DataTargetRef target, JsonTree::WriteOptions writeOptions )
{
// Declare output string
string jsonString = "";
try {
// Create JsonCpp data to send to parser
Json::Value value = createNativeDoc( writeOptions );
// This routine serializes JsonCpp data and formats it
if( writeOptions.getIndented() ) {
jsonString = value.toStyledString();
boost::replace_all( jsonString, "\n", "\r\n" );
} else {
Json::FastWriter writer;
jsonString = writer.write( value );
}
jsonString += "\0";
}
catch ( ... ) {
throw ExcJsonParserError( "Unable to serialize JsonTree." );
}
// Save data to file
OStreamRef os = target->getStream();
os->writeData( jsonString.c_str(), jsonString.length() ); // <= os is a nullptr
}
I can see the location of settings.json in the Sandboxed App dir on the device by logging to the console:
std::cout << "attempting to save to: " << ci::app::getAssetPath("settings.json") << std::endl;
mSettingsJson.write(ci::app::getAssetPath("settings.json"));
outputs the following:
attempting to save to: "/var/containers/Bundle/Application/72CB45DE-D9EA-4A07-9469-27AEE4C019A6/TestIos.app/assets/settings.json"
the ( FILE *) of mStream object of the target ptr is null, as per the image below:
Any insights would be appreciated!
(using Xcode 9, iOS 11.2, OSX 10.13.2)
Craig