您应该使用深层链接,以便在苹果音乐应用打开图钉:,你需要申请通过SKCloudServiceController API的授权,检查你的能力( https://affiliate.itunes.apple.com/resources/documentation/linking-to-the-itunes-music-store/
,首先例如,如果你的设备允许的回放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 /搜索:
NSDictionary *parameters = @{
@"isStreamable" : @(YES),
@"term" : @"your search parameter"
@"media" : @"music",
@"limit" : @(5),
@"country" : @"your country code"
};
作为该请求的响应,会收到轨道结果的阵列,有很多的相关联的参数。其中之一是“trackViewUrl”。只需以下参数添加到该trackViewUrl以使其深度链接到苹果的音乐应用程序:
NSString *appleMusicDeepLinking = [NSString stringWithFormat:@"%@&mt=1&app=music", response[0][@"trackViewUrl"]];
什么样的政策,你指的是说,你需要允许用户打开苹果音乐的歌曲? –