2014-11-03 69 views

回答

-2

這是非常簡單的玩法:

我已經編輯我的代碼:

只需添加路徑NSURL,然後將該網址添加到AVAudioPlayer。呼叫play方法

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/ma.mp3", [[NSBundle mainBundle] resourcePath]]]; 

    NSError *error; 
audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error]; 
    audioPlayer.numberOfLoops = -1; 

[audioPlayer play]; 


} 

添加默認聲音uilocalnotification

- (void)scheduleNotification { 

    [reminderText resignFirstResponder]; 
    [[UIApplication sharedApplication] cancelAllLocalNotifications]; 

    Class cls = NSClassFromString(@"UILocalNotification"); 
    if (cls != nil) { 

    UILocalNotification *notif = [[cls alloc] init]; 
    notif.fireDate = [datePicker date]; 
    notif.timeZone = [NSTimeZone defaultTimeZone]; 

    notif.alertBody = @"Did you forget something?"; 
    notif.alertAction = @"Show me"; 

    notif.soundName = UILocalNotificationDefaultSoundName; 
    notif.applicationIconBadgeNumber = 1; 

    NSDictionary *userDict = [NSDictionary dictionaryWithObject:reminderText.text 
           forKey:kRemindMeNotificationDataKey]; 
    notif.userInfo = userDict; 

    [[UIApplication sharedApplication] scheduleLocalNotification:notif]; 
    [notif release]; 
    } 
} 
+0

感謝您的回覆,我的問題是在本地通知而非默認的聲音我們如何發揮系統的聲音。 notif.soundName = UILocalNotificationDefaultSoundName;在這裏,我需要給系統聲音path.so當我的應用程序在後臺,系統聲音應播放而不是默認的一個 – appsign 2014-11-04 15:17:24

+0

請理解我的問題,我知道如何播放聲音文件。在本地通知如何添加系統聲音文件在後臺播放的路徑不在前臺 – appsign 2014-11-05 15:39:11