1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【Swift】URLからAppleMusicを開く方法

Last updated at Posted at 2021-10-06

SwiftでAppleMusicのURLを取得した後、AppleMusicアプリを開く方法に躓いたのでメモとして残しておきます。

//AppleMusicを開くための関数、urlを引数としている
func openAppMusic(url: String) {
    DispatchQueue.main.async {
        
        guard let url: URL = URL(string: url) else { return }

        // URLを開く
        UIApplication.shared.open(url, options: [:]) { success in
            if success {

            }
        }
    }
}

//ボタンをタップしたらAppleMusicのURLを開く関数(例)
@objc func onPressButton(_ sender : Any){
    self.openAppMusic(url: "AppleMusicのURL")
}


メインスレッドで開くのを忘れがちなので注意が必要。

Swiftのお役立ち情報

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?