加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

objective-c – 如何在iTunes中设置来自歌曲的声音本地通知?

发布时间:2020-12-16 04:57:26 所属栏目:百科 来源:网络整理
导读:我尝试创建闹钟应用程序,但我不知道如何将iTunes中的歌曲设置为本地通知的声音. 现在我使用此代码来调用iTunes - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ if (indexPath.section == 0) { MPMediaPicke
我尝试创建闹钟应用程序,但我不知道如何将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;

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

解决方法

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

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读