如何使用声音发出本地通知警报

时间:2015-06-10 13:43:37

标签: ios objective-c ios8.1

当我的应用程序在foregroundmode中时,我想在本地通知中设置声音。我尝试了很多东西。请帮我。

      UInt32 flag = 0;
   SystemSoundID soundID;
        int err = AudioServicesSetProperty(kAudioServicesPropertyIsUISound,
                                       sizeof(UInt32),
                                       &UILocalNotificationDefaultSoundName,
                                       sizeof(UInt32),
                                       &flag);

        NSLog(@"%d",(unsigned int)err);

        AudioServicesPlaySystemSound(soundID);

1 个答案:

答案 0 :(得分:0)

如果您尝试使用声音启动本地通知,则可以使用soundName属性:

UILocalNotification *localNotif = [[UILocalNotification alloc] init];
localNotif.fireDate = [NSDate dateWithTimeIntervalSinceNow:30];
localNotif.alertBody = @"Hey!";
localNotif.alerttitle = @"Notification!";

localNotif.soundName = UILocalNotificationDefaultSoundName;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotif];

使用UILocalNotificationDefaultSoundName通知将使用默认声音,而使用文件名代替自定义声音。

documentation中有关此属性的更多信息。

相关问题