如何从iTunes中设置声音本地通知?

我尝试创build闹钟应用程序,但我不知道如何将歌曲从iTunes设置为本地通知。

现在我使用这个代码来调用iTunes

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { if (indexPath.section == 0) { MPMediaPickerController *picker = [[MPMediaPickerController alloc] initWithMediaTypes: MPMediaTypeMusic]; picker.delegate = self; picker.allowsPickingMultipleItems = NO; picker.prompt = NSLocalizedString (@"Select any song from the list", @"Prompt to user to choose some songs to play"); //[self presentModalViewController: picker animated: YES]; [self.navigationController pushViewController:picker animated:YES]; NSLog(@"gsudifghukdsf"); [picker release]; } } - (void) mediaPicker: (MPMediaPickerController *) mediaPicker didPickMediaItems: (MPMediaItemCollection *) mediaItemCollection { [self.navigationController popToRootViewControllerAnimated:YES]; //[self dismissModalViewControllerAnimated: YES]; NSLog(@"%@",mediaItemCollection); UILocalNotification *local = [[UILocalNotification alloc] init]; //selectedSongCollection=mediaItemCollection; } - (void) mediaPickerDidCancel: (MPMediaPickerController *) mediaPicker { [self.navigationController popToRootViewControllerAnimated:YES]; //[self dismissModalViewControllerAnimated: YES]; } 

和关于本地通知的东西看起来像这样

  UILocalNotification *localNotif = [[UILocalNotification alloc] init]; if (localNotif == nil) { //NSLog(@"Get in if localNotif"); return; } localNotif.fireDate = DateAlarm; localNotif.timeZone = [NSTimeZone defaultTimeZone]; // Notification details localNotif.alertBody = [NSString stringWithFormat:@"%@",DateAlarm]; // Set the action button localNotif.alertAction = @"Oh Shit"; localNotif.soundName = UILocalNotificationDefaultSoundName; 

那么请指导我如何将歌曲设置为本地声音?

您只能使用属于主包的声音,也就是说,在提交到app store时,它们已经在构build应用程序。

是的,你可以在应用程序中录制声音,下载声音等,但是没有创build/保存的声音文件可以使用,因为它们不在应用程序的包中。 如果应用程序通过在包之外访问它们来使用自定义声音,那么它们正在使用私有API来执行此操作。 相信我,我已经尝试了所有我能想到的select。

正如@thephatp所述,通知(本地或远程)只能触发应用程序包中声音的回放。 我看不到这个。

@ r3dsm0k3在他的评论中询问像Rise这样的应用程序如何触发播放不在应用程序包中的声音。 如果我不得不猜测,我会说Rise将自己注册为一个需要audio背景模式的应用程序 :

声明您的应用程序支持的后台任务

支持某些types的后台执行必须由使用它们的应用程序预先声明。 应用程序使用Info.plist文件声明对服务的支持。 将UIBackgroundModes键添加到Info.plist文件中,并将其值设置为包含一个或多个以下string的数组:

audio – 应用程序在后台播放可听内容给用户。 (此内容包括使用AirPlay播放audio或video内容。)

这实际上意味着Rise可以一直保持运行。 它可以这样做,因为它代表用户播放audio。 它不会播放audio100%的时间似乎不是苹果的问题。

上升可能会或可能不会使用UILocalNotifications。 最有可能的是,他们只使用这些作为备份,因为应用程序不会被卸载,而是使用另一个定时器机制来触发唤醒警报序列。