Hen*_*Two 3 macos xcode core-foundation ios
现在不建议使用Apple的Load Preset Demo示例代码中包括的许多其他功能,不再支持CFURLCreateDataAndPropertiesFromResource的调用。但是我找不到它的替代品-单击选项或查看引用都不能告诉我,这已不再是一件容易的事。
CFDataRef propertyResourceData = 0;
Boolean status;
SInt32 errorCode = 0;
OSStatus result = noErr;
// Read from the URL and convert into a CFData chunk
status = CFURLCreateDataAndPropertiesFromResource (
kCFAllocatorDefault,
(__bridge CFURLRef) presetURL,
&propertyResourceData,
NULL,
NULL,
&errorCode
);
NSAssert (status == YES && propertyResourceData != 0, @"Unable to create data and properties from a preset. Error code: %d '%.4s'", (int) errorCode, (const char *)&errorCode);
// Convert the data object into a property list
CFPropertyListRef presetPropertyList = 0;
CFPropertyListFormat dataFormat = 0;
CFErrorRef errorRef = 0;
presetPropertyList = CFPropertyListCreateWithData (
kCFAllocatorDefault,
propertyResourceData,
kCFPropertyListImmutable,
&dataFormat,
&errorRef
);
// Set the class info property for the Sampler unit using the property list as the value.
if (presetPropertyList != 0) {
result = AudioUnitSetProperty(
self.samplerUnit,
kAudioUnitProperty_ClassInfo,
kAudioUnitScope_Global,
0,
&presetPropertyList,
sizeof(CFPropertyListRef)
);
CFRelease(presetPropertyList);
}
if (errorRef) CFRelease(errorRef);
CFRelease (propertyResourceData);
return result;
Run Code Online (Sandbox Code Playgroud)
对于属性: CFURLCopyResourcePropertiesForKeys示例属性:kCFURLFileSizeKey和kCFURLContentModificationDateKey,或具有的基础样式[NSURL resourceValuesForKeys:error:]。
对于数据: +[NSData dataWithContentsOfURL:options:error:]。
他们没有被记录为替代品,AFAIK。这些更新的API大多已经存在了几年。
编辑
在此示例中,您发布在编辑中,该程序不要求属性,因此只需要URL上的数据presetURL。
您可以通过以下方法实现此目的:
NSURL * presetURL = ...;
// do review these options for your needs. you can make great
// optimizations if you use memory mapping or avoid unnecessary caching.
const NSDataReadingOptions DataReadingOptions = 0;
NSError * outError = nil;
NSData * data = [NSData dataWithContentsOfURL:presetURL
options:DataReadingOptions
error:&outError];
const bool status = nil != data; // << your `status` variable
if (!status) {
// oops - an error was encountered getting the data see `outError`
}
else {
// use the data
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2230 次 |
| 最近记录: |