2016-11-09 3 views
13

컨텍스트 : 현재 Apple Music API와 통합되는 iOS 앱을 개발 중입니다. 노래를 검색하고 내 앱에서 재생할 수 있습니다. 자신의 정책을 존중하기 위해 사용자가 Apple Music 앱에서 노래를 실행하고 재생할 수 있도록해야합니다. Shazam은 Apple Music, Deezer 및 Google Play에서이를 수행합니다 (아래 이미지 참조).iOS 앱에서 Apple 음악 열기

enter image description here

나는 스포티 파이는 기본적으로 URL 방식을 사용, this 스레드를 사용하는 동안 그 일을했습니다. On this Reddit thread iOS URL Scheme의 목록을 찾았지만 애플 뮤직에 관해서 아무 것도 찾을 수 없습니다. 같은 스레드에서 this 요청은 여전히 ​​사용할 수 없다고 확인합니다.

Apple Music API에서도 운이 좋지 않습니다.

질문 : 누군가 Apple 음악과 동일한 동작을 수행하는 방법을 알고 있습니까? Btw, URL 스키마가 필요하지 않습니다.

목표는 Apple Music을 실행하고 내 음악이 아닌 Apple Music 앱으로 노래를 재생하는 것입니다. 이미 내 앱에서 Apple Music의 노래를 재생하고 있습니다.

API 문서에 뭔가 빠졌습니까? 어떤 생각을 부탁드립니다.

+0

Apple 뮤직에서 사용자가 노래를 열도록 허용해야한다고 말하는 어떤 정책이 있습니까? –

답변

7
당신은 애플의 뮤직 앱에 침을 열기 위해 딥 링크를 사용한다

: 당신이 당신의 능력을 (확인 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"입니다. Apple 음악 앱에 깊은 링크를 만들기 위해이 trackViewUrl에 다음 매개 변수를 추가하기 만하면됩니다.

NSString *appleMusicDeepLinking = [NSString stringWithFormat:@"%@&mt=1&app=music", response[0][@"trackViewUrl"]]; 
+0

오른쪽으로 보시면 여기에서 시도해보실 수 있습니다. 고맙습니다! – antonioduarte

+0

나를 위해 일해 줬습니다 - 고마워요! –

0

이 게시물에 유용 할 수있는 몇 가지 예제 코드가 있습니다. play apple music songs by third party applications. 나는 플레이어를 활성화하고 함께 노래를 연주 할 수 있었다 : 또한

#import <MediaPlayer/MediaPlayer.h> 

[[MPMusicPlayerController systemMusicPlayer] setQueueWithStoreIDs:tracks]; 
[[MPMusicPlayerController systemMusicPlayer] play]; 

, 애플 뮤직 API 문서는 여기 소개 :

Apple Music Best Practices for App Developers

Apple Music API FAQ

나는 희망이 도움이 .

+0

이것은 앱에서 이미 수행되고 있지만, 내가 찾고있는 것이 아닙니다. 내 앱에서 Apple Music을 시작하고 거기에서 노래를 재생할 수 있기를 원합니다. – antonioduarte