2012-03-22 86 views
0

我花了一些時間搜索,並且可能有一種使用ARC設置和播放系統聲音的簡單方法,但是我發現的所有內容都不兼容ARC。如果有人有一個片段,我會非常感激。使用ARC在IOS5中設置和播放系統聲音

現在想通了。

+0

也許你應該張貼你已經嘗試了代碼。 – Darren 2012-03-22 21:10:38

+1

發佈您的解決方案作爲答案,並接受它,如果它解決了您的問題。 – danielbeard 2012-03-23 00:33:10

回答

1

這對我有用,希望有人會發現它也有用。

.h文件中:

@property (readwrite) CFURLRef sysSoundTestPath; 

.m文件:

#import <AudioToolbox/AudioToolbox.h> 

@synthesize sysSoundTestPath; 
SystemSoundID soundID; 


NSURL *path = [[NSBundle mainBundle] URLForResource: @"testSound" withExtension: @"wav"]; 
sysSoundTestPath = (__bridge CFURLRef)path; 

AudioServicesCreateSystemSoundID(sysSoundTestPath, &soundID); 
AudioServicesPlaySystemSound(soundID); 
+0

您還需要添加'#import ' – 2012-10-22 14:27:40

+0

謝謝,劉易斯,我將它添加到解決方案中 – 2014-07-16 08:04:20