您應該使用深層鏈接,以便在蘋果音樂應用打開圖釘:,你需要申請通過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"]];
什麼樣的政策,你指的是說,你需要允許用戶打開蘋果音樂的歌曲? –