如何在iTunes中设置来自歌曲的声音本地通知? [英] How to set sound local notification from song in iTunes?

查看:93
本文介绍了如何在iTunes中设置来自歌曲的声音本地通知?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试创建闹钟应用但我不知道如何将iTunes中的歌曲设置为本地通知声音。

I try to create alarm app but I don't know how to set song from iTunes to sound of local notification.

现在我用这段代码来调用iTunes

Now I use this code to call 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]; 
}

关于本地通知的内容如下所示

and something about local notification look like this

 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;

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

So please guide me how can I set song to local sound ??

推荐答案

您只能使用属于主要捆绑包的声音,这意味着,当提交到应用商店时,它们会在应用内置。

You can only use sounds that are a part of the main bundle, meaning, they have be in the build of the app when submitted to the app store.

是的,您可以在应用程序中录制声音,下载声音等,但这些声音创建/保存的文件都不能使用,因为它们不在应用程序的包中。如果应用程序通过在捆绑包外部访问它们来使用自定义声音,那么他们正在使用私有API来执行此操作。相信我,我已经尝试了我能想到的每一个选择。

Yes, you can record sound, download sound, etc in app, but none of those sounds files created/saved can be used, because they are not in the app's bundle. If an app is using custom sounds by accessing them outside of the bundle, then they are using private APIs to do so. Trust me, I've tried every option I can think of.

这篇关于如何在iTunes中设置来自歌曲的声音本地通知?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆