除了蘋果的Load Preset Demo示例代碼中包含的其他一些東西外,現在不鼓勵對CFURLCreateDataAndPropertiesFromResource的調用。但是我無法找到替代品 - 既沒有選擇權,也沒有看到參考文獻告訴我,它不再是完成的事情。不建議使用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;
我試圖轉換有問題的代碼(請參閱編輯的文章),但我在這裏陌生的地方,我不確定如何使用dataWithContentsOfURL:options:錯誤代替返回布爾值的代碼。 – HenryRootTwo
@stugrimshaw看到更新的答案 – justin
我開始獲得照片,這對我有很大的幫助。所以我猜,CFPropertyListCreateWithData現在必須替換爲使用NSData對象的東西?由於propertyResourceData仍然爲0,此時NSAssert失敗。 – HenryRootTwo