2012-09-10 31 views
1

我在ios中使用uilocalnotification的自定義聲音。 但它不玩。文檔文件夾中存在 文件。 通知正在與local.soundName= UILocalNotificationDefaultSoundName;如何在iphone中更改UILocalNotification中的自定義聲音?

 NSString* documentsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]; 
     NSString *path = [NSString stringWithFormat:@"%@/DingDongTone.wav",documentsPath]; 
     local.soundName=path; 

請幫助。 謝謝。

回答

3

請重新讀什麼蘋果說 -

對於此屬性,指定 聲音資源的文件名(包括擴展名)在應用程序的主束或 UILocalNotificationDefaultSoundName請求默認的系統 聲音。當系統顯示本地通知的警報或 標記應用程序圖標時,它會播放此聲音。默認值是 nil(沒有聲音)。持續時間超過30秒的聲音不支持 。如果您指定播放超過30秒的聲音的文件,則會改爲播放默認聲音。

根據本filename是文件中的main bundle資源不是在document directory

注意path:也文件不應該再那麼30 sec.

+0

感謝您的信息。當我收到localnotification時,我可以在背景中播放.caf聲音嗎?但聲音文件在文檔文件夾中。 – Mani

1

@saadnib說我完全同意他對specify the filename(含擴展名)的一個sound resource should in the application’s main bundle

因此,複製你的聲音在應用程序的主包,然後不要forget to copy你的path string這樣,它應該工作。

yourLocalNotification.soundName= [yourSoundFilePath copy]; 
相關問題