Если это кому-нибудь пригодится, это код, который я использую для чего-то подобного. Я использую его , чтобы скопировать некоторые образцы документов при первом запуске или, если необходимо, (закомментированный раздел), если новая версия больше последней версии, если это гарантировано.
BOOL firstrun()
{
CFStringRef firstRunKey = CFSTR("lastVersion");
CFNumberFormatterRef formatter;
CFStringRef currentVersionString;
CFMutableStringRef currentVersionMutableString;
CFNumberRef currentVersion;
CFStringRef lastVersionRunString;
// CFMutableStringRef lastVersionRunMutableString;
// CFNumberRef lastVersionRun;
currentVersionString = CFBundleGetValueForInfoDictionaryKey(CFBundleGetMainBundle(), kCFBundleVersionKey);
currentVersionMutableString = CFStringCreateMutableCopy(NULL, 0, currentVersionString);
CFStringFindAndReplace(currentVersionMutableString, CFSTR("."), CFSTR(""), CFRangeMake(0, CFStringGetLength(currentVersionString)), 0);
formatter = CFNumberFormatterCreate(NULL, NULL, kCFNumberFormatterNoStyle);
currentVersion = CFNumberFormatterCreateNumberFromString(NULL, formatter, currentVersionMutableString, NULL, kCFNumberFormatterParseIntegersOnly);
lastVersionRunString = CFPreferencesCopyAppValue(firstRunKey, kCFPreferencesCurrentApplication);
if (lastVersionRunString == NULL)
{
// first run
NSFileManager *f = [NSFileManager defaultManager];
NSBundle *b = [NSBundle mainBundle];
NSError *e;
NSArray *xs = [NSArray arrayWithObjects: @"Welcome",
@"A Child's Garden of Verses",
@"Address to a Haggis",
@"Sonnet 18", nil];
for (id x in xs)
{
BOOL s = [f copyItemAtPath: [b pathForResource: x ofType: @"txt"]
toPath: [DocumentManager pathForDocumentWithName: x]
error: &e];
if (s == YES)
{
NSLog(@"Copied first run file %@ successfully.", x);
}
else {
NSLog(@"Failed to copy %@.", x);
}
}
} // else {
// The following is to enable support for new releases needing to show new information
/*
lastVersionRunMutableString = CFStringCreateMutableCopy(NULL, 0, lastVersionRunString);
CFStringFindAndReplace(lastVersionRunMutableString,
CFSTR("."),
CFSTR(""),
CFRangeMake(0, CFStringGetLength(lastVersionRunMutableString)),
0);
lastVersionRun = CFNumberFormatterCreateNumberFromString(NULL, formatter, lastVersionRunMutableString, NULL, kCFNumberFormatterParseIntegersOnly);
CFComparisonResult cr = CFNumberCompare(lastVersionRun, currentVersion, NULL);
*/
// }
// Update last run version
CFPreferencesSetAppValue(firstRunKey, currentVersionString, kCFPreferencesCurrentApplication);
CFPreferencesAppSynchronize(kCFPreferencesCurrentApplication);
CFRelease(currentVersionMutableString);
CFRelease(formatter);
CFRelease(currentVersion);
return (lastVersionRunString == NULL);
}