iOS使用应用中的给定关键字打开iTunes音乐搜索 [英] iOS open iTunes music search with given keywords from app

查看:81
本文介绍了iOS使用应用中的给定关键字打开iTunes音乐搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经构建了一个显示带有背景音乐的视频的应用程序,用户可以将要显示的歌曲的元数据(Artis,标题,专辑,流派)添加到视频旁边.

现在,我想使观众能够在iTunes中购买这首歌.

我查询iTunes搜索( https://itunes.apple.com/search )以获取一个打开特定歌曲的链接,该链接在95%的时间内效果很好.我通过比较返回的歌手和歌名来验证结果,以确保我不会将用户指向误报"歌曲.

万一我找不到完美的匹配,我想打开iTunes并在歌曲字段中预填标题和艺术家.而且我很难让它开始工作.

到目前为止,我最大的努力是打开itms://search.itunes.apple.com/WebObjects/MZSearch.woa/wa/search并添加?term = My + keywords& media = music& entity = song随即打开带有搜索视图的iTunes并已经填写了我的关键字",但不幸的是,搜索词被弄乱了并显示为(我的关键字"),包括引号和括号.

这是我正在使用的代码:

NSString* baseURLString2 = @"itms://search.itunes.apple.com/WebObjects/MZSearch.woa/wa/search";
NSString* searchUrlString2 = [NSString stringWithFormat:@"%@?term=%@&media=music&entity=song", baseURLString2, searchTerm];

searchUrlString2 = [searchUrlString2 stringByReplacingOccurrencesOfString:@" " withString:@"+"];
searchUrlString2 = [searchUrlString2 stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

NSURL* searchUrl2 = [NSURL URLWithString:searchUrlString2];

dispatch_async(dispatch_get_main_queue(), ^{
    [[UIApplication sharedApplication] openURL:searchUrl2];
});

这是searchUrlString2的示例:

itms://search.itunes.apple.com/WebObjects/MZSearch.woa/wa/search?term=J+Cole+Trouble&media=music&entity=song

当我使用https而不是itms时,它可以在MacBook上的浏览器中正常工作,但在iOS 8上的iTunes中仍然可以正常工作.

关于如何解决此问题的任何想法? 还是可以为此指出一个好的文档?

先谢谢了 SVen

解决方案

使用itms://itunes.apple.com/WebObjects/MZStore.woa/wa/search来找到它,因为baseURL对我有用. >

因此,完整的URL是:

itms://itunes.apple.com/WebObjects/MZStore.woa/wa/search?term=MySearch&media=music&entity=song

I have build an app that displays videos with background music and users can add the meta-data (artis, title, album, genre) of the song to be displayed next to the video.

Now I want to enable the viewers to buy this song in iTunes.

I query the iTunes search (https://itunes.apple.com/search) to get a link to open the specific song, which works nice 95% of the time. I validate the result by comparing the returned artist and songtitle to make sure I don't point the user to a "false positive" song.

In case I cant find a perfect match I would like to open iTunes and pre-fill the title and artist in the song field. And I am having a hard time to get it working.

My best effort so far was to open itms://search.itunes.apple.com/WebObjects/MZSearch.woa/wa/search and add ?term=My+keywords&media=music&entity=song which opens iTunes with the search view presented and has already filled in "My keywords", but unfortunately the search term is messed up and displayed as ( "My keywords" ) including the quotation marks and brackets.

This is the code I am using:

NSString* baseURLString2 = @"itms://search.itunes.apple.com/WebObjects/MZSearch.woa/wa/search";
NSString* searchUrlString2 = [NSString stringWithFormat:@"%@?term=%@&media=music&entity=song", baseURLString2, searchTerm];

searchUrlString2 = [searchUrlString2 stringByReplacingOccurrencesOfString:@" " withString:@"+"];
searchUrlString2 = [searchUrlString2 stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

NSURL* searchUrl2 = [NSURL URLWithString:searchUrlString2];

dispatch_async(dispatch_get_main_queue(), ^{
    [[UIApplication sharedApplication] openURL:searchUrl2];
});

This is an example for a searchUrlString2:

itms://search.itunes.apple.com/WebObjects/MZSearch.woa/wa/search?term=J+Cole+Trouble&media=music&entity=song

When I use https instead of itms it works fine in a browser on my MacBook, but still the same in iTunes on iOS 8.

Any ideas on how to fix this? Or can you point me to a good documentation for this?

Thanks in advance SVen

解决方案

Found it, using itms://itunes.apple.com/WebObjects/MZStore.woa/wa/search as baseURL did the trick for me.

So the complete URL is:

itms://itunes.apple.com/WebObjects/MZStore.woa/wa/search?term=MySearch&media=music&entity=song

这篇关于iOS使用应用中的给定关键字打开iTunes音乐搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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