从我的iOS应用程序打开Apple音乐

从我的iOS应用程序打开Apple音乐,第1张

概述背景:我正在开发一个与Apple Music API集成的iOS应用程序.我可以搜索歌曲,并在我的应用程序上播放.为了尊重他们的政策,我必须允许用户在Apple Music应用程序上启动和播放歌曲. Shazam可以为Apple Music,Deezer和Google Play(见下图). 我已经为Spotify使用this线程,基本上使用URL方案.在this Reddit线程我找到一个iOS 背景:我正在开发一个与Apple Music API集成的iOS应用程序.我可以搜索歌曲,并在我的应用程序上播放.为了尊重他们的政策,我必须允许用户在Apple Music应用程序上启动和播放歌曲. Shazam可以为Apple Music,Deezer和Google Play(见下图).

我已经为Spotify使用this线程,基本上使用URL方案.在this Reddit线程我找到一个iOS URL Scheme的列表,但我找不到任何关于Apple Music – this请求在同一个线程上确认它仍然不可用.

没有运气与Apple Music API.

问题:有人知道如何与Apple Music完成同样的行为吗? Btw,不需要使用URL方案.

这个目标是启动Apple Music,并将歌曲播放到Apple Music应用程序中,而不是在我的应用程序上.我已经在我的应用程序上播放了Apple Music的歌曲.

我在api文档中缺少什么?任何想法将不胜感激.

解决方法 您应该使用深层链接,以便在Apple Music应用程序中打开标签:
https://affiliate.itunes.apple.com/resources/documentation/linking-to-the-itunes-music-store/

首先,您需要通过SKCloudServiceController API请求授权,以检查您的功能(例如,如果您的设备允许播放Apple音乐曲目).

[SKCloudServiceController requestAuthorization:^(SKCloudServiceAuthorizationStatus status) {        self.cloudServiceController = [[SKCloudServiceController alloc] init];        [self.cloudServiceController requestCapabilitIEsWithCompletionHandler:^(SKCloudServiceCapability capabilitIEs,NSError * _Nullable error) {                       [self.cloudServiceController requestStorefrontIDentifIErWithCompletionHandler:^(Nsstring * _Nullable storefrontIDentifIEr,NSError * _Nullable error) {                Nsstring *IDentifIEr = [[storefrontIDentifIEr componentsSeparatedByString:@","] firstObject];                IDentifIEr = [[IDentifIEr componentsSeparatedByString:@"-"] firstObject];                Nsstring *countryCode = [self countryCodeWithIDentifIEr:IDentifIEr];                              }];        }];    }];

接下来,您可以请求商店正面标识符,您将使用它来定义您的国家/地区代码.我建议在您的项目中添加一个.pList文件,其中包含所有标识符和各自的国家/地区代码. (您可以在这里找到.pList文件https://github.com/bendodson/storefront-assistant/blob/master/StorefrontCountries.plist).您需要您的国家代码到Apple Music API请求.

- (Nsstring *)countryCodeWithIDentifIEr:(Nsstring *)IDentifIEr {     NSURL *pListURL = [[NSBundle mainBundle] URLForResource:@"CountryCodes" withExtension:@"pList"];     NSDictionary *countryCodeDictionary = [NSDictionary dictionaryWithContentsOfURL:pListURL];     return countryCodeDictionary[IDentifIEr];}

一旦你有相应的国家代码,你可以在Apple Music的API中搜索一个曲目.使用以下参数发出请求GET:https://itunes.apple.com/search

NSDictionary *parameters = @{                               @"isstreamable" : @(YES),@"term" : @"your search parameter"                               @"media" : @"music",@"limit" : @(5),@"country" : @"your country code"                               };

作为此请求的响应,您将收到一系列跟踪结果,其中包含许多参数.其中之一是“trackVIEwUrl”.只需将以下参数添加到此trackVIEwUrl,以使其深入链接到Apple Music应用程序:

Nsstring *appleMusicDeeplinking = [Nsstring stringWithFormat:@"%@&mt=1&app=music",response[0][@"trackVIEwUrl"]];
总结

以上是内存溢出为你收集整理的从我的iOS应用程序打开Apple音乐全部内容,希望文章能够帮你解决从我的iOS应用程序打开Apple音乐所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1110448.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-29
下一篇 2022-05-29

发表评论

登录后才能评论

评论列表(0条)

保存